Submission #837241

# Submission time Handle Problem Language Result Execution time Memory
837241 2023-08-25T08:34:27 Z Kubogi Difference (POI11_roz) C++17
0 / 100
18 ms 16988 KB
#include <bits/stdc++.h>
using namespace std;

#define fileio(name) if (fopen(name".inp", "r")) freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout)

const int maxn = 1e6+5, inf = 1e9;
int n;
vector<int> idx[26];
string s;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    fileio("diff");
    // freopen("debug.txt", "w", stderr);

    cin >> n >> s;
    s = "%" + s;
    for (int i = 1; i <= n; i++) {
        idx[s[i] - 'a'].push_back(i);
    }

    int res = 0;
    for (int x = 0; x < 26; x++) {
        for (int y = 0; y < 26; y++) {
            if (idx[x].empty() || idx[y].empty()) continue;
            if (x == y) continue;

            vector<int> a {0};
            int j = 0;
            for (int i: idx[x]) {
                while (j < idx[y].size() && idx[y][j] < i) {
                    a.push_back(-1);
                    j++;
                }
                a.push_back(1);
            }
            while (j < idx[y].size()) {
                a.push_back(-1);
                j++;
            }

            // kjjfdlkfjdf
            int ans = 0, mini = inf, last = 0;
            vector<int> pfs {0};
            for (int i = 1; i < a.size(); i++) {
                pfs[i] = pfs[i-1] + a[i];
                if (i > 1 && a[i] != a[i-1]) {
                    for (int j = last; j < i-1; j++) {
                        mini = min(mini, pfs[j]);
                    }
                    last = i-1;
                }
                ans = max(ans, pfs[i] - mini);
            }
            res = max(res, ans);
        }
    }
    cout << res;


    return 0 ^ 0;
}

Compilation message

roz.cpp: In function 'int32_t main()':
roz.cpp:32:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |                 while (j < idx[y].size() && idx[y][j] < i) {
      |                        ~~^~~~~~~~~~~~~~~
roz.cpp:38:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |             while (j < idx[y].size()) {
      |                    ~~^~~~~~~~~~~~~~~
roz.cpp:46:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |             for (int i = 1; i < a.size(); i++) {
      |                             ~~^~~~~~~~~~
roz.cpp:4:57: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    4 | #define fileio(name) if (fopen(name".inp", "r")) freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout)
      |                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
roz.cpp:14:5: note: in expansion of macro 'fileio'
   14 |     fileio("diff");
      |     ^~~~~~
roz.cpp:4:90: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    4 | #define fileio(name) if (fopen(name".inp", "r")) freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout)
      |                                                                                   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
roz.cpp:14:5: note: in expansion of macro 'fileio'
   14 |     fileio("diff");
      |     ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 444 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Runtime error 1 ms 448 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 596 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1872 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 18 ms 16988 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 14 ms 16428 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 16 ms 16508 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 15 ms 16252 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -