Submission #1003045

# Submission time Handle Problem Language Result Execution time Memory
1003045 2024-06-20T03:57:20 Z wibulord Difference (POI11_roz) C++17
100 / 100
684 ms 18264 KB
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
#define fi first
#define se second
#define pb emplace_back
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
#define sz(s) (int)((s).size())
#define all(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define F0R(i, b) for (int i = 0, _b = (b); i < _b; ++i)
#define FORd(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define F0Rd(i, b) for (int i = (b)-1; i >= 0; i--)
using namespace std;

template<typename T1,typename T2> bool ckmax(T1 &x,const T2 &y){if(x<y){x=y; return 1;} return 0;}
template<typename T1,typename T2> bool ckmin(T1 &x,const T2 &y){if(y<x){x=y; return 1;} return 0;}

const int MOD = (int)1e9 + 7;
const int mod = 998244353;
const int N = 1e6 + 10, M = 18;
const int INF = (int)2e9 + 11;
/*
     /\_/\
    (= ._.)
    / >?  \>$
*/

int n;
char c[N];
int pref[N];
vector<int> ds[101];
vector<int> A;

int calc(int a, int b){
    if(sz(ds[a]) == 0 || sz(ds[b]) == 0) return 0;
    vector<int>().swap(A);
    A.push_back(0);
    int j = 0;
    F0R(i, sz(ds[a])){
        for(; j < sz(ds[b]) && ds[b][j] < ds[a][i]; j++) A.push_back(-1);
        A.push_back(1);
    }
    for(; j < sz(ds[b]); j++) A.push_back(-1);
    int m = sz(A) - 1;
    FOR(i, 1, m) pref[i] = pref[i-1] + A[i];
    int lst = -1, ptr = 0, ans = 0, mn = INF;
    FOR(i, 1, m){
        if(A[i] < 0) lst = i;
        for(; ptr < lst; ptr++) mn = min(mn, pref[ptr]);
        if(lst != -1) ans = max(ans, pref[i] - mn);
    }
    return ans;
}

void sol(void){
    cin >> n;
    FOR(i, 1, n){
        cin >> c[i];
        ds[c[i]-'a'].push_back(i);
    }
    int ans = 0;
    F0R(i, 26) F0R(j, 26) if(i != j) ans = max(ans, calc(i,j));
    cout << ans << '\n';
}

signed main(void){
    #define TASK "nhap"
    if(fopen(TASK".inp", "r")){
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t = 1;
//    cin >> t;
    while(t--) sol();
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
}

Compilation message

roz.cpp: In function 'int main()':
roz.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
roz.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 1116 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 4 ms 636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 653 ms 7980 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 354 ms 6788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 627 ms 8176 KB Output is correct
2 Correct 481 ms 6328 KB Output is correct
3 Correct 189 ms 8004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 629 ms 8052 KB Output is correct
2 Correct 91 ms 15680 KB Output is correct
3 Correct 133 ms 9192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 684 ms 7984 KB Output is correct
2 Correct 46 ms 18264 KB Output is correct
3 Correct 225 ms 8644 KB Output is correct