Submission #850553

# Submission time Handle Problem Language Result Execution time Memory
850553 2023-09-16T21:52:51 Z oscar1f Monochrome Points (JOI20_monochrome) C++17
35 / 100
2000 ms 15124 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];

int compt(vector<int> listeBla,vector<int> listeNoir) {
    int nbInter=0,temp,mini,maxi;
    for (int i=0;i<nbVal;i++) {
        mini=min(listeBla[i],listeNoir[i]);
        maxi=max(listeBla[i],listeNoir[i]);
        temp=min(maxi-mini-1,2*nbVal-maxi-1+mini);
        //cout<<listeBla[i]<<" "<<listeNoir[i]<<" "<<temp<<" ";
        nbInter+=temp;
    }
    return nbInter/2;
}

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 autre,deb,fin,mid,premSup;
    for (int i=0;i<nbVal;i++) {
        //cout<<i<<endl;
        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;
                }
            }
            for (int j=0;j<deb;j++) {
                cumu[(j-i+nbVal)%nbVal]+=2*nbVal-listeBla[i];
                //cout<<"D"<<j<<" ";
            }
            for (int j=deb;j<premSup;j++) {
                cumu[(j-i+nbVal)%nbVal]+=listeBla[i];
                //cout<<"C"<<j<<" ";
            }
            //cout<<deb<<" ";
        }
        //cout<<premSup<<" ";
        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;
                }
            }
            //cout<<deb<<" ";
            for (int j=premSup;j<deb;j++) {
                cumu[(j-i+nbVal)%nbVal]-=listeBla[i];
                //cout<<"A"<<j<<" ";
            }
            for (int j=deb;j<nbVal;j++) {
                cumu[(j-i+nbVal)%nbVal]+=listeBla[i];
                //cout<<"B"<<j<<" ";
            }
        }
        /*cout<<endl;
        for (int j=0;j<nbVal;j++) {
            autre=listeNoir[j];
            if (listeBla[i]<autre) {
                if (autre-listeBla[i]<nbVal) {
                    //cumu[(j-i+nbVal)%nbVal]-=listeBla[i];
                    cout<<"A"<<j<<" ";
                }
                else {
                    //cumu[(j-i+nbVal)%nbVal]+=listeBla[i];
                    cout<<"B"<<j<<" ";
                }
            }
            else {
                if (listeBla[i]-autre<nbVal) {
                    //cumu[(j-i+nbVal)%nbVal]+=listeBla[i];
                    cout<<"C"<<j<<" ";
                }
                else {
                    //cumu[(j-i+nbVal)%nbVal]+=2*nbVal-listeBla[i];
                    cout<<"D"<<j<<" ";
                }
            }
        }
        cout<<endl;
        cout<<endl;*/
    }
    for (int i=0;i<nbVal;i++) {
        //cout<<i<<endl;
        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;
                }
            }
            for (int j=0;j<deb;j++) {
                cumu[(i-j+nbVal)%nbVal]+=2*nbVal-listeNoir[i];
                //cout<<"D"<<j<<" ";
            }
            for (int j=deb;j<premSup;j++) {
                cumu[(i-j+nbVal)%nbVal]+=listeNoir[i];
                //cout<<"C"<<j<<" ";
            }
            //cout<<deb<<" ";
        }
        //cout<<premSup<<" ";
        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;
                }
            }
            //cout<<deb<<" ";
            for (int j=premSup;j<deb;j++) {
                cumu[(i-j+nbVal)%nbVal]-=listeNoir[i];
                //cout<<"A"<<j<<" ";
            }
            for (int j=deb;j<nbVal;j++) {
                cumu[(i-j+nbVal)%nbVal]+=listeNoir[i];
                //cout<<"B"<<j<<" ";
            }
        }
        /*cout<<endl;
        for (int j=0;j<nbVal;j++) {
            autre=listeNoir[j];
            if (listeBla[i]<autre) {
                if (autre-listeBla[i]<nbVal) {
                    //cumu[(j-i+nbVal)%nbVal]-=listeBla[i];
                    cout<<"A"<<j<<" ";
                }
                else {
                    //cumu[(j-i+nbVal)%nbVal]+=listeBla[i];
                    cout<<"B"<<j<<" ";
                }
            }
            else {
                if (listeBla[i]-autre<nbVal) {
                    //cumu[(j-i+nbVal)%nbVal]+=listeBla[i];
                    cout<<"C"<<j<<" ";
                }
                else {
                    //cumu[(j-i+nbVal)%nbVal]+=2*nbVal-listeBla[i];
                    cout<<"D"<<j<<" ";
                }
            }
        }
        cout<<endl;
        cout<<endl;*/
    }
    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;
}

Compilation message

monochrome.cpp: In function 'long long int calc(std::vector<long long int>)':
monochrome.cpp:38:9: warning: unused variable 'autre' [-Wunused-variable]
   38 |     int autre,deb,fin,mid,premSup;
      |         ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 508 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 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 508 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 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 508 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 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 35 ms 352 KB Output is correct
35 Correct 35 ms 352 KB Output is correct
36 Correct 34 ms 604 KB Output is correct
37 Correct 32 ms 352 KB Output is correct
38 Correct 29 ms 348 KB Output is correct
39 Correct 33 ms 596 KB Output is correct
40 Correct 28 ms 348 KB Output is correct
41 Correct 26 ms 596 KB Output is correct
42 Correct 34 ms 344 KB Output is correct
43 Correct 34 ms 348 KB Output is correct
44 Correct 30 ms 572 KB Output is correct
45 Correct 31 ms 348 KB Output is correct
46 Correct 34 ms 600 KB Output is correct
47 Correct 34 ms 580 KB Output is correct
48 Correct 35 ms 348 KB Output is correct
49 Correct 29 ms 348 KB Output is correct
50 Correct 35 ms 848 KB Output is correct
51 Correct 35 ms 348 KB Output is correct
52 Correct 35 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 508 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 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 35 ms 352 KB Output is correct
35 Correct 35 ms 352 KB Output is correct
36 Correct 34 ms 604 KB Output is correct
37 Correct 32 ms 352 KB Output is correct
38 Correct 29 ms 348 KB Output is correct
39 Correct 33 ms 596 KB Output is correct
40 Correct 28 ms 348 KB Output is correct
41 Correct 26 ms 596 KB Output is correct
42 Correct 34 ms 344 KB Output is correct
43 Correct 34 ms 348 KB Output is correct
44 Correct 30 ms 572 KB Output is correct
45 Correct 31 ms 348 KB Output is correct
46 Correct 34 ms 600 KB Output is correct
47 Correct 34 ms 580 KB Output is correct
48 Correct 35 ms 348 KB Output is correct
49 Correct 29 ms 348 KB Output is correct
50 Correct 35 ms 848 KB Output is correct
51 Correct 35 ms 348 KB Output is correct
52 Correct 35 ms 348 KB Output is correct
53 Execution timed out 2008 ms 15124 KB Time limit exceeded
54 Halted 0 ms 0 KB -