Submission #1111271

#TimeUsernameProblemLanguageResultExecution timeMemory
1111271SoMotThanhXuan Martian DNA (BOI18_dna)C++17
100 / 100
26 ms3216 KiB
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //::::::::::::::::::::::::::::::::::::-+*--+*=:::::::::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::::::==-------+-:::::::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::=+========+*=--=-:::::::::::::::::::::::::::::::::: //:::::::::::::::::::::::::-*=--------------=#+::::::::::::::::::::::::::::::::::: //::::::::::::::::::-----=*---++--+-----------+=:::::::::::::::::::::::::::::::::: //::::::::::::::::-+---++------=+%-.=+-----=++=++====-::::::::::::::-+===-:::::::: //::::::::::::::::==--+=------*--==::=#==+=-----------*-::::::::::+=-::::-++:::::: //::::::::::::::::==-+=-------*..++--------------------+::::::::-=-:::::::::+::::: //::::::::::::::::=+=*------=+%=--------===+%@@@+#---+=:::::::::=-::::::::::==:::: //::::::::::::::::::=+----++------=*#%+.-*+-..-+:.*+-:::::::::::+:::::::::::==:::: //:::::::::::::::::::*-=+=-----+=-:+%+...-:..:+*%=*+-:::::::::::+:::::::::::*::::: //:::::::::::::::::::=*+----*@@++:...:+..=..%@%+@@*..:=+::::::::=-::::::::-+-::::: //:::::::::::::::::::*----*%-:=-.:#@@@@%:..-@@-.:@#....:=-::::::-+-:::::-=+::::::: //::::::::::::::::::*----=@%-.=.:#@+ .%@%...+%@@%+..::::-=:::::::-*#==++:::::::::: //::::::::::::::::::*----#@%-...:#@@*#@@+...........:::::+::::::-*=*:::::::::::::: //:::::::::::::::::::=*++::=+....:-+*=-.................-=::::::-=:::::::::::::::: //:::::::::::::::::::::=:.....::::.............==-=+....=-::::::-=:::::::::::::::: //::::::::::::::::::::--......::::.............=---+-.:=-:::::::=-:::::::::::::::: //:::::::::::::::::::::=:...=****#+++*+========+****+%*-::::::::+::::::::::::::::: //::::::::::::::::::::::---:+*+++#=-+***+*#*+##++++*=#**:::::::-+::::::::::::::::: //:::::::::::::::::::::::::-**+++**-****#=---**++++*+#+*=::::::*:::::::::::::::::: //::::::::::::::::::::::::=***++++#=#+*+------+*++++*%**=:::::-=:::::::::::::::::: //:::::::::::::::::::::::+==**++++*%++*-------=*+++++*=-=:::::+::::::::::::::::::: //::::::::::::::::::::::+=--+#::-***++**------+*++++++#:=:::-+:::::::::::::::::::: //::::::::::::::::::::::+----*..:+++++++##+#@#++++++++*-=::*=::::::::::::::::::::: //::::::::::::::::::::::-*----*.+#****++**=-:.....:+==*:++:::::::::::::::::::::::: //::::::::::::::::::::::::+===#.-*+*:..............:+%+:=::::::::::::::::::::::::: //::::::::::::::::::::::::::::+==+*+........+........:=+:::::::::::::::::::::::::: //:::::::::::::::::::::::::::::=:..........*.....-*#+::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::=+=--==+*#*=-+=-=..:=:::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::+=-==:::::::::+#%#=:::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::+--+-:::::::::=+++-:::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::***=::::::::::-%#:=*::::::::::::::::::::::::::::: //::::::::::::::::::::::::::::-+=..:=::::::::::=*+=-::+-:::::::::::::::::::::::::: //::::::::::::::::::::::::::::=====-:::::::::::::::::::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::==-==--:: //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: #include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for(int i = a; i <= b; ++i) #define REP(i, a, b) for(int i = a; i >= b; --i) #define left _________left #define right _________right #define NAME "" const int mod = 1e9 + 7; inline bool maximize(int &u, int v){ if(v > u){ u = v; return true; } return false; } inline bool minimize(int &u, int v){ if(v < u){ u = v; return true; } return false; } inline bool maximizell(long long &u, long long v){ if(v > u){ u = v; return true; } return false; } inline bool minimizell(long long &u, long long v){ if(v < u){ u = v; return true; } return false; } inline int fastPow(int a, int n){ if(n == 0) return 1; int t = fastPow(a, n >> 1); t = 1ll * t * t % mod; if(n & 1) t = 1ll * t * a % mod; return t; } inline void add(int &u, int v){ u += v; if(u >= mod) u -= mod; } inline void sub(int &u, int v){ u -= v; if(u < 0) u += mod; } const int maxN = 2e5 + 5; int r, n, k, cnt[maxN], d[maxN], cur[maxN]; inline void process(){ cin >> n >> k >> r; FOR(i, 1, n){ cin >> d[i]; } FOR(i, 1, r){ int u, v; cin >> u >> v; cnt[u] = v; } int rem = 0, answer = n + 1; int i = 1, j = 1; while(j <= n){ if(cnt[d[j]] > 0){ ++cur[d[j]]; if(cur[d[j]] == cnt[d[j]])++rem; } while(rem == r){ minimize(answer, j - i + 1); if(cnt[d[i]] > 0){ cur[d[i]]--; if(cur[d[i]] == cnt[d[i]] - 1)--rem; } ++i; } ++j; } if(answer == n + 1)cout << "impossible"; else cout << answer; } int main(){ if(fopen(NAME".inp", "r")){ freopen(NAME".inp", "r", stdin); freopen(NAME".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while(t--) process(); cerr << '\n' << "Time elapsed: " << (1.0 * clock() / CLOCKS_PER_SEC) << " s\n" ; return 0; }

Compilation message (stderr)

dna.cpp: In function 'int main()':
dna.cpp:144:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  144 |         freopen(NAME".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
dna.cpp:145:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  145 |         freopen(NAME".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...