Submission #897373
Source Code Expand
#define DEB #include<bits/stdc++.h> #define REP(i,m) for(int i=0;i<(m);++i) #define REPN(i,m,in) for(int i=(in);i<(m);++i) #define ALL(t) (t).begin(),(t).end() #define CLR(a) memset((a),0,sizeof(a)) #define pb push_back #define mp make_pair #define fr first #define sc second using namespace std; #ifdef DEB #define dump(x) cerr << #x << " = " << (x) << endl #define prl cerr<<"called:"<< __LINE__<<endl template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;} #else #define dump(x) ; #define prl ; template<class T> void debug(T a,T b){ ;} #endif template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; } template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; } typedef long long int lint; typedef pair<int,int> pi; namespace std{ template<class S,class T> ostream &operator <<(ostream& out,const pair<S,T>& a){ out<<'('<<a.fr<<','<<a.sc<<')'; return out; } } //const int INF=5e8; int n,m; int q; int ar[100005]; vector<int> pos[100005]; int finish[100005];// N bool done[100005];// M void fail(){ puts("No"); exit(0); } void doit(set<int> rest){ int lastpos=q; bool ng=false; REP(i,m) if(rest.count(i)){ if(pos[i].empty()) lastpos=-1; else if(pos[i][0]>lastpos) ng=true; else lastpos=pos[i][0]; } if(!ng){ puts("Yes"); }else{ puts("No"); } exit(0); } int main(){ cin>>n>>m>>q; REP(i,q){ scanf("%d",&ar[i]);--ar[i]; pos[ar[i]].pb(i); } REP(i,m) reverse(ALL(pos[i])); { int lastpos=q; bool ng=false; REP(i,m){ if(pos[i].empty()) lastpos=-1; else if(pos[i][0]>lastpos) ng=true; else lastpos=pos[i][0]; } if(!ng){ puts("Yes"); return 0; } } REP(i,n) finish[i]=q; int seek=q-1; bool last=false; set<int> rest; REP(i,m) rest.insert(i); while(seek>=0){ int val=ar[seek]; if(done[val]){ --seek; continue; } done[val]=1; int j=0; REP(i,n){ while(j<pos[val].size() && finish[i]<=pos[val][j]){ ++j; } if(j==pos[val].size()){ doit(rest); }else{ finish[i]=pos[val][j]; ++j; } } rest.erase(val); } puts("Yes"); return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - LRU Puzzle |
User | hogloid |
Language | C++14 (GCC 5.4.1) |
Score | 1200 |
Code Size | 2353 Byte |
Status | AC |
Exec Time | 69 ms |
Memory | 15872 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:75:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&ar[i]);--ar[i]; ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1200 / 1200 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt |
All | 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt, 1_14.txt, 1_15.txt, 1_16.txt, 1_17.txt, 1_18.txt, 1_19.txt, 1_20.txt, 1_21.txt, 1_22.txt, 1_23.txt, 1_24.txt, 1_25.txt, 1_26.txt, 1_27.txt, 1_28.txt, 1_29.txt, 1_30.txt, 1_31.txt, 1_32.txt, 1_33.txt, 1_34.txt, 1_35.txt, 1_36.txt, 1_37.txt, 1_38.txt, 1_39.txt, 1_40.txt, 1_41.txt, 1_42.txt, 1_43.txt, 1_44.txt, 1_45.txt, 1_46.txt, 1_47.txt, 1_48.txt, 1_49.txt, 1_50.txt, 1_51.txt, 1_52.txt, 1_53.txt, 1_54.txt, 1_55.txt, 1_56.txt, 1_57.txt, 1_58.txt, 1_59.txt, 1_60.txt, 1_61.txt, 1_62.txt, 1_63.txt, 1_64.txt, 1_65.txt, 1_66.txt, 1_67.txt, 1_68.txt, 1_69.txt, 1_70.txt, 1_71.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_00.txt | AC | 5 ms | 2560 KB |
0_01.txt | AC | 5 ms | 2560 KB |
0_02.txt | AC | 5 ms | 2560 KB |
0_03.txt | AC | 5 ms | 2560 KB |
1_00.txt | AC | 5 ms | 2560 KB |
1_01.txt | AC | 5 ms | 2560 KB |
1_02.txt | AC | 14 ms | 3452 KB |
1_03.txt | AC | 41 ms | 8440 KB |
1_04.txt | AC | 14 ms | 3452 KB |
1_05.txt | AC | 53 ms | 13176 KB |
1_06.txt | AC | 23 ms | 6144 KB |
1_07.txt | AC | 62 ms | 15872 KB |
1_08.txt | AC | 23 ms | 6144 KB |
1_09.txt | AC | 23 ms | 6144 KB |
1_10.txt | AC | 35 ms | 6912 KB |
1_11.txt | AC | 34 ms | 6912 KB |
1_12.txt | AC | 34 ms | 6912 KB |
1_13.txt | AC | 37 ms | 9216 KB |
1_14.txt | AC | 34 ms | 6912 KB |
1_15.txt | AC | 34 ms | 6912 KB |
1_16.txt | AC | 34 ms | 6912 KB |
1_17.txt | AC | 37 ms | 9216 KB |
1_18.txt | AC | 59 ms | 12672 KB |
1_19.txt | AC | 50 ms | 7296 KB |
1_20.txt | AC | 57 ms | 11904 KB |
1_21.txt | AC | 63 ms | 14976 KB |
1_22.txt | AC | 64 ms | 13184 KB |
1_23.txt | AC | 62 ms | 8192 KB |
1_24.txt | AC | 60 ms | 13696 KB |
1_25.txt | AC | 56 ms | 8064 KB |
1_26.txt | AC | 16 ms | 3840 KB |
1_27.txt | AC | 15 ms | 3712 KB |
1_28.txt | AC | 18 ms | 3840 KB |
1_29.txt | AC | 18 ms | 3840 KB |
1_30.txt | AC | 40 ms | 10240 KB |
1_31.txt | AC | 42 ms | 10496 KB |
1_32.txt | AC | 33 ms | 8704 KB |
1_33.txt | AC | 45 ms | 10752 KB |
1_34.txt | AC | 31 ms | 6528 KB |
1_35.txt | AC | 39 ms | 7680 KB |
1_36.txt | AC | 28 ms | 6144 KB |
1_37.txt | AC | 36 ms | 8064 KB |
1_38.txt | AC | 56 ms | 9088 KB |
1_39.txt | AC | 56 ms | 11008 KB |
1_40.txt | AC | 58 ms | 13696 KB |
1_41.txt | AC | 69 ms | 13184 KB |
1_42.txt | AC | 15 ms | 3712 KB |
1_43.txt | AC | 16 ms | 3712 KB |
1_44.txt | AC | 16 ms | 3712 KB |
1_45.txt | AC | 15 ms | 3712 KB |
1_46.txt | AC | 22 ms | 5120 KB |
1_47.txt | AC | 27 ms | 6784 KB |
1_48.txt | AC | 27 ms | 6528 KB |
1_49.txt | AC | 49 ms | 11520 KB |
1_50.txt | AC | 18 ms | 3968 KB |
1_51.txt | AC | 16 ms | 3712 KB |
1_52.txt | AC | 20 ms | 4608 KB |
1_53.txt | AC | 18 ms | 3840 KB |
1_54.txt | AC | 17 ms | 3712 KB |
1_55.txt | AC | 26 ms | 6912 KB |
1_56.txt | AC | 57 ms | 12928 KB |
1_57.txt | AC | 51 ms | 11904 KB |
1_58.txt | AC | 14 ms | 3456 KB |
1_59.txt | AC | 15 ms | 3584 KB |
1_60.txt | AC | 14 ms | 3584 KB |
1_61.txt | AC | 14 ms | 3584 KB |
1_62.txt | AC | 24 ms | 6528 KB |
1_63.txt | AC | 52 ms | 12540 KB |
1_64.txt | AC | 14 ms | 3584 KB |
1_65.txt | AC | 44 ms | 10752 KB |
1_66.txt | AC | 14 ms | 3712 KB |
1_67.txt | AC | 15 ms | 4096 KB |
1_68.txt | AC | 14 ms | 3712 KB |
1_69.txt | AC | 15 ms | 4096 KB |
1_70.txt | AC | 14 ms | 3712 KB |
1_71.txt | AC | 43 ms | 10752 KB |