Submission #775466

# Submission time Handle Problem Language Result Execution time Memory
775466 2023-07-06T12:06:09 Z hgmhc None (JOI16_ho_t2) C++17
100 / 100
4 ms 3644 KB
#include <bits/stdc++.h>
#define rep(i,a,b) for (auto i = (a); i <= (b); ++i)
#define per(i,a,b) for (auto i = (b); i >= (a); --i)
#define all(x) begin(x),end(x)
#define siz(x) int((x).size())
#define Mup(x,y) x = max(x,y)
#define mup(x,y) x = min(x,y)
#define dbg(...) fprintf(stdout,__VA_ARGS__)
#define fi first
#define se second
using namespace std; using ll = long long; using ii = pair<int,int>;

const int N = 1e5+3;
int n;
char s[N];
ll ans, diff;
ll cJ[N], cI[N];
ll cJO[N], cOI[N];

int main() {
    cin.tie(0)->sync_with_stdio(0);
    // 지문이 너무 난해하다..
    // 조합.. 든든하군
    cin >> n >> &s[1];
    rep(i,1,n) cJ[i] = cJ[i-1]+(s[i]=='J');
    per(i,1,n) cI[i] = cI[i+1]+(s[i]=='I');
    rep(i,1,n) if (s[i]=='O') ans += cJ[i-1]*cI[i+1];
    
    rep(i,1,n) {
        cJO[i] = cJO[i-1];
        if (s[i]=='O') cJO[i] += cJ[i-1];
    }
    
    per(i,1,n) {
        cOI[i] = cOI[i+1];
        if (s[i]=='O') cOI[i] += cI[i+1];
    }
    
    rep(i,0,n) {
        // between i and i+1
        // select 'J'
        Mup(diff, cOI[i+1]);
        // select 'O'
        Mup(diff, cJ[i]*cI[i+1]);
        // select 'I'
        Mup(diff, cJO[i]);
    }
    
    cout << ans+diff;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 0 ms 328 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 0 ms 328 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 0 ms 328 KB Output is correct
8 Correct 0 ms 328 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Correct 0 ms 340 KB Output is correct
30 Correct 0 ms 340 KB Output is correct
31 Correct 3 ms 3540 KB Output is correct
32 Correct 3 ms 3540 KB Output is correct
33 Correct 3 ms 3540 KB Output is correct
34 Correct 3 ms 3540 KB Output is correct
35 Correct 3 ms 3640 KB Output is correct
36 Correct 3 ms 3644 KB Output is correct
37 Correct 3 ms 3540 KB Output is correct
38 Correct 4 ms 3540 KB Output is correct
39 Correct 4 ms 3540 KB Output is correct
40 Correct 3 ms 3540 KB Output is correct
41 Correct 3 ms 3540 KB Output is correct
42 Correct 3 ms 3540 KB Output is correct
43 Correct 3 ms 3540 KB Output is correct
44 Correct 3 ms 3540 KB Output is correct
45 Correct 3 ms 3644 KB Output is correct