Submission #895603
Source Code Expand
#include <iostream> #include <vector> #include <cstdio> #include <sstream> #include <map> #include <string> #include <algorithm> #include <queue> #include <cmath> #include <functional> #include <set> #include <ctime> #include <random> #include <chrono> #include <cassert> using namespace std; namespace { using Integer = long long; //__int128; template<class T> istream& operator >> (istream& is, vector<T>& vec){for(T& val: vec) is >> val; return is;} template<class T> istream& operator , (istream& is, T& val){ return is >> val;} template<class T> ostream& operator << (ostream& os, const vector<T>& vec){for(int i=0; i<vec.size(); i++) os << vec[i] << (i==vec.size()-1?"":" "); return os;} template<class T> ostream& operator , (ostream& os, const T& val){ return os << " " << val;} template<class H> void print(const H& head){ cout << head; } template<class H, class ... T> void print(const H& head, const T& ... tail){ cout << head << " "; print(tail...); } template<class ... T> void println(const T& ... values){ print(values...); cout << endl; } template<class H> void eprint(const H& head){ cerr << head; } template<class H, class ... T> void eprint(const H& head, const T& ... tail){ cerr << head << " "; eprint(tail...); } template<class ... T> void eprintln(const T& ... values){ eprint(values...); cerr << endl; } class range{ long long start_, end_, step_; public: struct range_iterator{ long long val, step_; range_iterator(long long v, long long step) : val(v), step_(step) {} long long operator * (){return val;} void operator ++ (){val += step_;} bool operator != (range_iterator& x){return step_ > 0 ? val < x.val : val > x.val;} }; range(long long len) : start_(0), end_(len), step_(1) {} range(long long start, long long end) : start_(start), end_(end), step_(1) {} range(long long start, long long end, long long step) : start_(start), end_(end), step_(step) {} range_iterator begin(){ return range_iterator(start_, step_); } range_iterator end(){ return range_iterator( end_, step_); } }; string operator "" _s (const char* str, size_t size){ return move(string(str)); } constexpr Integer my_pow(Integer x, Integer k, Integer z=1){return k==0 ? z : k==1 ? z*x : (k&1) ? my_pow(x*x,k>>1,z*x) : my_pow(x*x,k>>1,z);} constexpr Integer my_pow_mod(Integer x, Integer k, Integer M, Integer z=1){return k==0 ? z%M : k==1 ? z*x%M : (k&1) ? my_pow_mod(x*x%M,k>>1,M,z*x%M) : my_pow_mod(x*x%M,k>>1,M,z);} constexpr unsigned long long operator "" _ten (unsigned long long value){ return my_pow(10,value); } inline int k_bit(Integer x, int k){return (x>>k)&1;} //0-indexed mt19937 mt(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()); template<class T> string join(const vector<T>& v, const string& sep){ stringstream ss; for(int i=0; i<v.size(); i++){ if(i>0) ss << sep; ss << v[i]; } return ss.str(); } string operator * (string s, int k){ string ret; while(k){ if(k&1) ret += s; s += s; k >>= 1; } return ret; } } constexpr long long mod = 9_ten + 7; int main(){ int n,m; cin >> n,m; int q; cin >> q; vector<int> a(q); cin >> a; for(auto i : range(q) ){ a[i]--; } reverse(a.begin(), a.end()); vector<int> res; vector<int> ord(m, -1); vector<int> cnt(m+1, 0); cnt[0] = n; for(int i=0; i<q; i++){ if(ord[a[i]] == -1){ ord[a[i]] = res.size(); if(cnt[ord[a[i]]] == 0){ cout << "No" << endl; return 0; } cnt[ord[a[i]]]--; cnt[ord[a[i]]+1]++; res.push_back(a[i]); }else{ if(cnt[ord[a[i]]] > 0){ cnt[ord[a[i]]]--; cnt[ord[a[i]]+1]++; } } } set<int> unused; for(int i=0; i<m; i++){ unused.insert(i); } for(int i=0; i<=m; i++){ if(cnt[i] != 0){ for(int j=0; j<i; j++){ unused.erase(res[j]); } for(int j=i; j<res.size(); j++){ if(res[j] != *unused.begin()){ cout << "No" << endl; return 0; } unused.erase(unused.begin()); } break; } } cout << "Yes" << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - LRU Puzzle |
User | koyumeishi |
Language | C++14 (GCC 5.4.1) |
Score | 1200 |
Code Size | 4328 Byte |
Status | AC |
Exec Time | 64 ms |
Memory | 6520 KB |
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 | 2 ms | 256 KB |
0_01.txt | AC | 2 ms | 256 KB |
0_02.txt | AC | 2 ms | 256 KB |
0_03.txt | AC | 2 ms | 256 KB |
1_00.txt | AC | 2 ms | 256 KB |
1_01.txt | AC | 2 ms | 256 KB |
1_02.txt | AC | 45 ms | 6144 KB |
1_03.txt | AC | 44 ms | 6144 KB |
1_04.txt | AC | 44 ms | 6144 KB |
1_05.txt | AC | 43 ms | 6144 KB |
1_06.txt | AC | 58 ms | 6520 KB |
1_07.txt | AC | 58 ms | 6520 KB |
1_08.txt | AC | 58 ms | 6520 KB |
1_09.txt | AC | 59 ms | 6520 KB |
1_10.txt | AC | 44 ms | 3580 KB |
1_11.txt | AC | 43 ms | 3580 KB |
1_12.txt | AC | 43 ms | 3580 KB |
1_13.txt | AC | 40 ms | 3580 KB |
1_14.txt | AC | 43 ms | 3580 KB |
1_15.txt | AC | 43 ms | 3580 KB |
1_16.txt | AC | 43 ms | 3580 KB |
1_17.txt | AC | 40 ms | 3580 KB |
1_18.txt | AC | 60 ms | 5752 KB |
1_19.txt | AC | 54 ms | 3836 KB |
1_20.txt | AC | 58 ms | 5496 KB |
1_21.txt | AC | 57 ms | 6264 KB |
1_22.txt | AC | 63 ms | 6264 KB |
1_23.txt | AC | 64 ms | 5116 KB |
1_24.txt | AC | 59 ms | 6264 KB |
1_25.txt | AC | 59 ms | 4604 KB |
1_26.txt | AC | 23 ms | 640 KB |
1_27.txt | AC | 20 ms | 640 KB |
1_28.txt | AC | 26 ms | 768 KB |
1_29.txt | AC | 26 ms | 768 KB |
1_30.txt | AC | 41 ms | 4480 KB |
1_31.txt | AC | 42 ms | 4736 KB |
1_32.txt | AC | 36 ms | 3712 KB |
1_33.txt | AC | 47 ms | 4864 KB |
1_34.txt | AC | 36 ms | 2304 KB |
1_35.txt | AC | 42 ms | 3324 KB |
1_36.txt | AC | 33 ms | 1920 KB |
1_37.txt | AC | 39 ms | 3068 KB |
1_38.txt | AC | 58 ms | 4860 KB |
1_39.txt | AC | 56 ms | 5240 KB |
1_40.txt | AC | 57 ms | 6140 KB |
1_41.txt | AC | 63 ms | 6392 KB |
1_42.txt | AC | 22 ms | 640 KB |
1_43.txt | AC | 23 ms | 640 KB |
1_44.txt | AC | 23 ms | 640 KB |
1_45.txt | AC | 22 ms | 640 KB |
1_46.txt | AC | 30 ms | 1536 KB |
1_47.txt | AC | 33 ms | 2560 KB |
1_48.txt | AC | 32 ms | 2432 KB |
1_49.txt | AC | 51 ms | 5248 KB |
1_50.txt | AC | 25 ms | 896 KB |
1_51.txt | AC | 23 ms | 640 KB |
1_52.txt | AC | 27 ms | 1152 KB |
1_53.txt | AC | 27 ms | 768 KB |
1_54.txt | AC | 42 ms | 5120 KB |
1_55.txt | AC | 30 ms | 2688 KB |
1_56.txt | AC | 52 ms | 6016 KB |
1_57.txt | AC | 50 ms | 5376 KB |
1_58.txt | AC | 20 ms | 640 KB |
1_59.txt | AC | 21 ms | 640 KB |
1_60.txt | AC | 20 ms | 768 KB |
1_61.txt | AC | 21 ms | 640 KB |
1_62.txt | AC | 27 ms | 2432 KB |
1_63.txt | AC | 43 ms | 6016 KB |
1_64.txt | AC | 26 ms | 2176 KB |
1_65.txt | AC | 48 ms | 4864 KB |
1_66.txt | AC | 18 ms | 640 KB |
1_67.txt | AC | 18 ms | 640 KB |
1_68.txt | AC | 18 ms | 640 KB |
1_69.txt | AC | 20 ms | 640 KB |
1_70.txt | AC | 42 ms | 5760 KB |
1_71.txt | AC | 48 ms | 4736 KB |