Submission #885102

# Submission time Handle Problem Language Result Execution time Memory
885102 2023-12-09T02:23:40 Z txk_2k6 Difference (POI11_roz) C++17
40 / 100
1000 ms 65536 KB
#include <bits/stdc++.h>
#define NAME "ssdiff"
#define pb push_back
#define fi first
#define se second
#define mp make_pair

using namespace std;
using ll = long long;
using pii = pair<int, int>;

void file(){

    freopen(NAME".inp","r",stdin);
    freopen(NAME".out","w",stdout);

}

int n;
string s;
const int mx=1e6+5;
int dp[30][mx];

int check(int u, int v){

    int mx=0, mn=v-u+1;
    for (int i=1; i<='z'-'a'+1; i++){

        int d=dp[i][v]-dp[i][u];
        mx=max(mx,d);
        if (d!=0) mn=min(mn,d);

    }

    //cout << u<<' '<<v<<' '<<mx<<' '<<mn<<' '<<mx-mn<<'\n';
    if (mn>mx) return mx;
    else return mx-mn;

}

int main(){

    //file();

    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    cin >> n >> s;
    s=" "+s;

    for (int i=1; i<='z'-'a'+1; i++) dp[0][i]=0;

    for (int i=1; i<=n; i++){

        for (int j=1; j<='z'-'a'+1; j++){
            dp[j][i]=dp[j][i-1];
        }
        dp[s[i]-'a'+1][i]++;

    }
    int res=0;
    for (int i=0; i<n; i++){
        for (int j=i+1; j<=n; j++){
            res=max(res,check(i,j));
        }
    }

    cout << res<<'\n';

    return 0;

}

Compilation message

roz.cpp: In function 'void file()':
roz.cpp:14:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     freopen(NAME".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
roz.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     freopen(NAME".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 900 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1024 ms 3676 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1063 ms 20312 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 25 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 27 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 28 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 26 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -