Submission #854261

# Submission time Handle Problem Language Result Execution time Memory
854261 2023-09-26T13:50:17 Z fanwen JOIOJI (JOI14_joioji) C++17
100 / 100
31 ms 6448 KB
#include <bits/stdc++.h>

using namespace std;

#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }

template <class A, class B> bool minimize(A &a, B b)  { if (a > b) { a = b; return true; } return false; }
template <class A, class B> bool maximize(A &a, B b)  { if (a < b) { a = b; return true; } return false; }

const int MAXN = 2e5 + 5;

int N, a[MAXN];

void you_make_it(void) {
    string s; cin >> N >> s; s = " " + s;
    map <pair <int, int>, int> dd;
    int Max = 0;
    dd[{0, 0}] = 0;
    FOR(i, 1, N) {
    	static int J = 0, O = 0, I = 0;
    	if(s[i] == 'J') J++;
    	else if(s[i] == 'I') I++;
    	else O++;
    	pair <int, int> tmp = make_pair(J - I, J - O);
    	if(dd.find(tmp) != dd.end()) maximize(Max, i - dd[tmp]);
    	else dd[tmp] = i;
    }
    cout << Max;

}

signed main() {

#ifdef LOCAL
    freopen("TASK.inp", "r", stdin);
    freopen("TASK.out", "w", stdout);
#endif
    auto start_time = chrono::steady_clock::now();

    cin.tie(0), cout.tie(0) -> sync_with_stdio(0);

    you_make_it();

    auto end_time = chrono::steady_clock::now();

    cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl;

    return (0 ^ 0);
}

// Dream it. Wish it. Do it.
# Verdict Execution time Memory Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 600 KB Output is correct
2 Correct 5 ms 1112 KB Output is correct
3 Correct 8 ms 1368 KB Output is correct
4 Correct 15 ms 2388 KB Output is correct
5 Correct 23 ms 3544 KB Output is correct
6 Correct 29 ms 3604 KB Output is correct
7 Correct 31 ms 4128 KB Output is correct
8 Correct 29 ms 3608 KB Output is correct
9 Correct 29 ms 3864 KB Output is correct
10 Correct 28 ms 3616 KB Output is correct
11 Correct 21 ms 5192 KB Output is correct
12 Correct 12 ms 2344 KB Output is correct
13 Correct 15 ms 1580 KB Output is correct
14 Correct 29 ms 6448 KB Output is correct
15 Correct 11 ms 1312 KB Output is correct