Submission #1103942

# Submission time Handle Problem Language Result Execution time Memory
1103942 2024-10-22T10:00:23 Z thangdz2k7 Difference (POI11_roz) C++17
100 / 100
115 ms 3308 KB
// author : thembululquaUwU
// 3.9.2024

#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define endl '\n'

using namespace std;
using ll = long long;
using ii = pair <int, int>;
using vi = vector <int>;

const int N = 1e6 + 1;
const int mod = 1e9 + 7;
const int nc = 26;

void maxl(auto &a, auto b) {a = max(a, b);}
void minl(auto &a, auto b) {a = min(a, b);}

int n, cur[nc], Min[nc], ntm[nc];
string s;

void solve(){
    cin >> n;
    cin >> s; s = ' ' + s;
    int ans = 0;
    for (int u = 0; u < nc; ++ u){
        for (int v = 0; v < nc; ++ v) {
            cur[v] = 0;
            Min[v] = 1e9;
            ntm[v] = 0;
        }
        for (int i = 1; i <= n; ++ i){
            int v = s[i] - 'a';
            if (u == v) {
                for (int k = 0; k < nc; ++ k) {
                    cur[k] ++;
                    if (k != u){
                        minl(ntm[k], cur[k]);
                        maxl(ans, cur[k] - Min[k]);
                    }
                }
            }
            else {
                cur[v] --;
                minl(Min[v], ntm[v]);
                ntm[v] = cur[v];
                maxl(ans, cur[v] - Min[v]);
            }
        }

    }
    cout << ans;
}

int main(){
    if (fopen("chenhlech.inp", "r")){
        freopen("chenhlech.inp", "r", stdin);
        freopen("chenhlech.out", "w", stdout);
    }
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int t = 1; // cin >> t;
    while (t --) solve();
    return 0;
}

Compilation message

roz.cpp:19:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void maxl(auto &a, auto b) {a = max(a, b);}
      |           ^~~~
roz.cpp:19:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   19 | void maxl(auto &a, auto b) {a = max(a, b);}
      |                    ^~~~
roz.cpp:20:11: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   20 | void minl(auto &a, auto b) {a = min(a, b);}
      |           ^~~~
roz.cpp:20:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   20 | void minl(auto &a, auto b) {a = min(a, b);}
      |                    ^~~~
roz.cpp: In function 'int main()':
roz.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |         freopen("chenhlech.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
roz.cpp:61:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |         freopen("chenhlech.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
# 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
# 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 592 KB Output is correct
2 Correct 0 ms 336 KB Output is correct
3 Correct 2 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 92 ms 2284 KB Output is correct
2 Correct 1 ms 500 KB Output is correct
3 Correct 77 ms 2028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 2284 KB Output is correct
2 Correct 74 ms 2028 KB Output is correct
3 Correct 59 ms 2028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 2540 KB Output is correct
2 Correct 108 ms 2540 KB Output is correct
3 Correct 69 ms 3080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 2540 KB Output is correct
2 Correct 115 ms 2708 KB Output is correct
3 Correct 74 ms 3308 KB Output is correct