Submission #1111271

# Submission time Handle Problem Language Result Execution time Memory
1111271 2024-11-12T01:02:07 Z SoMotThanhXuan Martian DNA (BOI18_dna) C++17
100 / 100
26 ms 3216 KB
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::-+*--+*=::::::::::::::::::::::::::::::::::::
//:::::::::::::::::::::::::::::::::::==-------+-::::::::::::::::::::::::::::::::::
//:::::::::::::::::::::::::::::=+========+*=--=-::::::::::::::::::::::::::::::::::
//:::::::::::::::::::::::::-*=--------------=#+:::::::::::::::::::::::::::::::::::
//::::::::::::::::::-----=*---++--+-----------+=::::::::::::::::::::::::::::::::::
//::::::::::::::::-+---++------=+%-.=+-----=++=++====-::::::::::::::-+===-::::::::
//::::::::::::::::==--+=------*--==::=#==+=-----------*-::::::::::+=-::::-++::::::
//::::::::::::::::==-+=-------*..++--------------------+::::::::-=-:::::::::+:::::
//::::::::::::::::=+=*------=+%=--------===+%@@@+#---+=:::::::::=-::::::::::==::::
//::::::::::::::::::=+----++------=*#%+.-*+-..-+:.*+-:::::::::::+:::::::::::==::::
//:::::::::::::::::::*-=+=-----+=-:+%+...-:..:+*%=*+-:::::::::::+:::::::::::*:::::
//:::::::::::::::::::=*+----*@@++:...:+..=..%@%+@@*..:=+::::::::=-::::::::-+-:::::
//:::::::::::::::::::*----*%-:=-.:#@@@@%:..-@@-.:@#....:=-::::::-+-:::::-=+:::::::
//::::::::::::::::::*----=@%-.=.:#@+ .%@%...+%@@%+..::::-=:::::::-*#==++::::::::::
//::::::::::::::::::*----#@%-...:#@@*#@@+...........:::::+::::::-*=*::::::::::::::
//:::::::::::::::::::=*++::=+....:-+*=-.................-=::::::-=::::::::::::::::
//:::::::::::::::::::::=:.....::::.............==-=+....=-::::::-=::::::::::::::::
//::::::::::::::::::::--......::::.............=---+-.:=-:::::::=-::::::::::::::::
//:::::::::::::::::::::=:...=****#+++*+========+****+%*-::::::::+:::::::::::::::::
//::::::::::::::::::::::---:+*+++#=-+***+*#*+##++++*=#**:::::::-+:::::::::::::::::
//:::::::::::::::::::::::::-**+++**-****#=---**++++*+#+*=::::::*::::::::::::::::::
//::::::::::::::::::::::::=***++++#=#+*+------+*++++*%**=:::::-=::::::::::::::::::
//:::::::::::::::::::::::+==**++++*%++*-------=*+++++*=-=:::::+:::::::::::::::::::
//::::::::::::::::::::::+=--+#::-***++**------+*++++++#:=:::-+::::::::::::::::::::
//::::::::::::::::::::::+----*..:+++++++##+#@#++++++++*-=::*=:::::::::::::::::::::
//::::::::::::::::::::::-*----*.+#****++**=-:.....:+==*:++::::::::::::::::::::::::
//::::::::::::::::::::::::+===#.-*+*:..............:+%+:=:::::::::::::::::::::::::
//::::::::::::::::::::::::::::+==+*+........+........:=+::::::::::::::::::::::::::
//:::::::::::::::::::::::::::::=:..........*.....-*#+:::::::::::::::::::::::::::::
//:::::::::::::::::::::::::::::=+=--==+*#*=-+=-=..:=::::::::::::::::::::::::::::::
//:::::::::::::::::::::::::::::::+=-==:::::::::+#%#=::::::::::::::::::::::::::::::
//:::::::::::::::::::::::::::::::+--+-:::::::::=+++-::::::::::::::::::::::::::::::
//:::::::::::::::::::::::::::::::***=::::::::::-%#:=*:::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::-+=..:=::::::::::=*+=-::+-::::::::::::::::::::::::::
//::::::::::::::::::::::::::::=====-::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
//:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::==-==--::
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#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

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 time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 504 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1116 KB Output is correct
2 Correct 12 ms 1616 KB Output is correct
3 Correct 10 ms 1116 KB Output is correct
4 Correct 11 ms 1616 KB Output is correct
5 Correct 17 ms 1104 KB Output is correct
6 Correct 10 ms 1616 KB Output is correct
7 Correct 11 ms 1616 KB Output is correct
8 Correct 14 ms 1104 KB Output is correct
9 Correct 12 ms 1884 KB Output is correct
10 Correct 9 ms 1104 KB Output is correct
11 Correct 2 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 556 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1828 KB Output is correct
2 Correct 18 ms 1612 KB Output is correct
3 Correct 16 ms 1628 KB Output is correct
4 Correct 14 ms 1872 KB Output is correct
5 Correct 25 ms 3216 KB Output is correct
6 Correct 26 ms 2640 KB Output is correct
7 Correct 14 ms 1872 KB Output is correct
8 Correct 17 ms 2140 KB Output is correct
9 Correct 10 ms 1616 KB Output is correct
10 Correct 10 ms 1616 KB Output is correct
11 Correct 10 ms 1616 KB Output is correct
12 Correct 11 ms 1616 KB Output is correct
13 Correct 14 ms 2056 KB Output is correct
14 Correct 9 ms 1104 KB Output is correct
15 Correct 10 ms 1104 KB Output is correct
16 Correct 13 ms 1104 KB Output is correct
17 Correct 11 ms 1116 KB Output is correct
18 Correct 13 ms 1616 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 492 KB Output is correct
21 Correct 1 ms 504 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 2 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 504 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 508 KB Output is correct
33 Correct 1 ms 336 KB Output is correct