Submission #850569

# Submission time Handle Problem Language Result Execution time Memory
850569 2023-09-16T23:18:29 Z oscar1f Monochrome Points (JOI20_monochrome) C++17
35 / 100
2000 ms 15580 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long

const int MAX_VAL=200*1000+5;
int nbVal;
vector<int> initType;
string valDeb;
int cumu[MAX_VAL];

void addInter(int deb,int fin,int val) {
    //cout<<deb<<" "<<fin<<" "<<val<<endl; 
    if (deb>fin) {
        addInter(deb,nbVal,val);
        addInter(0,fin,val);
    }
    for (int i=deb;i<fin;i++) {
        cumu[i]+=val;
    }
}

void add(int deb,int fin,int val) {
    if (fin-deb>=nbVal) {
        addInter(0,nbVal,val);
    }
    else {
        addInter((deb+nbVal)%nbVal,(fin+nbVal)%nbVal,val);
    }
}

int calc(vector<int> typeSom) {
    int rep=0;
    vector<int> listeBla,listeNoir;
    for (int i=0;i<2*nbVal;i++) {
        if (typeSom[i]==0) {
            listeBla.push_back(i);
        }
        else {
            listeNoir.push_back(i);
        }
    }
    for (int j=0;j<nbVal;j++) {
        cumu[j]=-nbVal;
    }
    int deb,fin,mid,premSup;
    for (int i=0;i<nbVal;i++) {
        deb=0;
        fin=nbVal;
        while (deb!=fin) {
            mid=(deb+fin)/2;
            if (listeNoir[mid]<listeBla[i]) {
                deb=mid+1;
            } 
            else {
                fin=mid;
            }
        }
        premSup=deb;
        if (premSup>0) {
            deb=0;
            fin=premSup;
            while (deb!=fin) {
                mid=(deb+fin)/2;
                if (listeBla[i]-listeNoir[mid]<nbVal) {
                    fin=mid;
                }
                else {
                    deb=mid+1;
                }
            }
            add(0-i,deb-i,2*nbVal-listeBla[i]);
            add(deb-i,premSup-i,listeBla[i]);
        }
        if (premSup<nbVal) {
            deb=premSup;
            fin=nbVal;
            while (deb!=fin) {
                mid=(deb+fin)/2;
                if (listeNoir[mid]-listeBla[i]>=nbVal) {
                    fin=mid;
                }
                else {
                    deb=mid+1;
                }
            }
            add(premSup-i,deb-i,-listeBla[i]);
            add(deb-i,nbVal-i,listeBla[i]);
        }
    }
    for (int i=0;i<nbVal;i++) {
        deb=0;
        fin=nbVal;
        while (deb!=fin) {
            mid=(deb+fin)/2;
            if (listeBla[mid]<listeNoir[i]) {
                deb=mid+1;
            } 
            else {
                fin=mid;
            }
        }
        premSup=deb;
        if (premSup>0) {
            deb=0;
            fin=premSup;
            while (deb!=fin) {
                mid=(deb+fin)/2;
                if (listeNoir[i]-listeBla[mid]<nbVal) {
                    fin=mid;
                }
                else {
                    deb=mid+1;
                }
            }
            add(i-deb+1,i-0+1,2*nbVal-listeNoir[i]);
            add(i-premSup+1,i-deb+1,listeNoir[i]);
        }
        if (premSup<nbVal) {
            deb=premSup;
            fin=nbVal;
            while (deb!=fin) {
                mid=(deb+fin)/2;
                if (listeBla[mid]-listeNoir[i]>=nbVal) {
                    fin=mid;
                }
                else {
                    deb=mid+1;
                }
            }
            add(i-deb+1,i-premSup+1,-listeNoir[i]);
            add(i-nbVal+1,i-deb+1,listeNoir[i]);
        }
    }
    for (int j=0;j<nbVal;j++) {
        rep=max(rep,cumu[j]/2);
    }
    return rep;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>nbVal;
    cin>>valDeb;
    for (int i=0;i<2*nbVal;i++) {
        if (valDeb[i]=='W') {
            initType.push_back(0);
        }
        else {
            initType.push_back(1);
        }
    }
    cout<<calc(initType)<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 600 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 1 ms 344 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 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 600 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 1 ms 344 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
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 548 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 600 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 1 ms 344 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
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 548 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 4 ms 344 KB Output is correct
35 Correct 5 ms 600 KB Output is correct
36 Correct 5 ms 344 KB Output is correct
37 Correct 4 ms 344 KB Output is correct
38 Correct 4 ms 344 KB Output is correct
39 Correct 4 ms 344 KB Output is correct
40 Correct 4 ms 344 KB Output is correct
41 Correct 3 ms 348 KB Output is correct
42 Correct 4 ms 344 KB Output is correct
43 Correct 4 ms 604 KB Output is correct
44 Correct 4 ms 344 KB Output is correct
45 Correct 4 ms 344 KB Output is correct
46 Correct 4 ms 600 KB Output is correct
47 Correct 4 ms 344 KB Output is correct
48 Correct 4 ms 348 KB Output is correct
49 Correct 4 ms 344 KB Output is correct
50 Correct 4 ms 344 KB Output is correct
51 Correct 4 ms 344 KB Output is correct
52 Correct 4 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 600 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 1 ms 344 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
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 0 ms 344 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 548 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 4 ms 344 KB Output is correct
35 Correct 5 ms 600 KB Output is correct
36 Correct 5 ms 344 KB Output is correct
37 Correct 4 ms 344 KB Output is correct
38 Correct 4 ms 344 KB Output is correct
39 Correct 4 ms 344 KB Output is correct
40 Correct 4 ms 344 KB Output is correct
41 Correct 3 ms 348 KB Output is correct
42 Correct 4 ms 344 KB Output is correct
43 Correct 4 ms 604 KB Output is correct
44 Correct 4 ms 344 KB Output is correct
45 Correct 4 ms 344 KB Output is correct
46 Correct 4 ms 600 KB Output is correct
47 Correct 4 ms 344 KB Output is correct
48 Correct 4 ms 348 KB Output is correct
49 Correct 4 ms 344 KB Output is correct
50 Correct 4 ms 344 KB Output is correct
51 Correct 4 ms 344 KB Output is correct
52 Correct 4 ms 344 KB Output is correct
53 Execution timed out 2039 ms 15580 KB Time limit exceeded
54 Halted 0 ms 0 KB -