Submission #91264

# Submission time Handle Problem Language Result Execution time Memory
91264 2018-12-26T19:04:35 Z Vardanyan Chessboard (IZhO18_chessboard) C++14
8 / 100
32 ms 4588 KB
#include<bits/stdc++.h>

using namespace std;
const int N = 1000*100+5;
long long tox_type[N];
long long pref_type1[N];
long long pref_type2[N];
int X1[N],X2[N],Y1[N],Y2[N];
long long syun_pref_type[N];
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    for(int i = 1;i<=k;i++) scanf("%d%d%d%d",&X1[i],&Y1[i],&X2[i],&Y2[i]);
    long long ans = 100000000000000005;
    for(int w = 1;w<=n/2;w++){
        if(n%w) continue;
        memset(tox_type,0,sizeof tox_type);
        memset(pref_type1,0,sizeof pref_type1);
        memset(pref_type2,0,sizeof pref_type2);
        memset(syun_pref_type,0,sizeof syun_pref_type);
        for(int j = 1;j<=n;j++){
            int x = (j-1)/w;
            if(x%2 == 0){
                    // sev
                tox_type[j] = 1;
                syun_pref_type[j] = syun_pref_type[j-1]+1;
            }
            else{
                // spitak
                tox_type[j] = 2;
                syun_pref_type[j] = syun_pref_type[j-1];
            }
        }
        for(int j = 1;j<=n;j++){
            int x = (j-1)/w;
            if(x%2 == 0){
                pref_type1[j] = pref_type1[j-1]+1;
                pref_type2[j] = pref_type2[j-1];
            }
            else{
                pref_type1[j] = pref_type1[j-1];
                pref_type2[j] = pref_type2[j-1]+1;
            }
        }
        long long need = 0;
        for(int i = 1;i<=n;i++){
            if(tox_type[i] == 1) need+=pref_type1[n];
            else need+=pref_type2[n];
        }
        for(int i = 1;i<=k;i++){
            long long x1 = X1[i],y1 = Y1[i];
            long long x2 = X2[i],y2 = Y2[i];
            long long qan_tp1 = syun_pref_type[x2]-syun_pref_type[x1-1];
            long long qan_tp2 = (x2-x1+1)-qan_tp1;
            need-=(qan_tp1*(pref_type1[y2]-pref_type1[y1-1])+qan_tp2*(pref_type2[y2]-pref_type2[y1-1]));
            need+=(qan_tp1*((y2-y1+1)-(pref_type1[y2]-pref_type1[y1-1]))+qan_tp2*((y2-y1+1)-(pref_type2[y2]-pref_type2[y1-1])));
        }
        ans = min(ans,need);
        memset(tox_type,0,sizeof tox_type);
        memset(pref_type1,0,sizeof pref_type1);
        memset(pref_type2,0,sizeof pref_type2);
        memset(syun_pref_type,0,sizeof syun_pref_type);
        for(int j = 1;j<=n;j++){
            int x = (j-1)/w;
            if(x%2 == 1){
                    // sev
                tox_type[j] = 1;
                syun_pref_type[j] = syun_pref_type[j-1]+1;
            }
            else{
                // spitak
                tox_type[j] = 2;
                syun_pref_type[j] = syun_pref_type[j-1];
            }
        }
        for(int j = 1;j<=n;j++){
            int x = (j-1)/w;
            if(x%2 == 1){
                pref_type1[j] = pref_type1[j-1]+1;
                pref_type2[j] = pref_type2[j-1];
            }
            else{
                pref_type1[j] = pref_type1[j-1];
                pref_type2[j] = pref_type2[j-1]+1;
            }
        }
        need = 0;
        for(int i = 1;i<=n;i++){
            if(tox_type[i] == 2) need+=pref_type1[n];
            else need+=pref_type2[n];
        }
        for(int i = 1;i<=k;i++){
            long long x1 = X1[i],y1 = Y1[i];
            long long x2 = X2[i],y2 = Y2[i];
            long long qan_tp1 = syun_pref_type[x2]-syun_pref_type[x1-1];
            long long qan_tp2 = (x2-x1+1)-qan_tp1;
            need-=(qan_tp1*(pref_type1[y2]-pref_type1[y1-1])+qan_tp2*(pref_type2[y2]-pref_type2[y1-1]));
            need+=(qan_tp1*((y2-y1+1)-(pref_type1[y2]-pref_type1[y1-1]))+qan_tp2*((y2-y1+1)-(pref_type2[y2]-pref_type2[y1-1])));
        }
        ans = min(ans,need);
    }
    cout<<ans<<endl;
    return 0;
}

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&k);
     ~~~~~^~~~~~~~~~~~~~
chessboard.cpp:14:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1;i<=k;i++) scanf("%d%d%d%d",&X1[i],&Y1[i],&X2[i],&Y2[i]);
                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3448 KB Output is correct
2 Correct 6 ms 3448 KB Output is correct
3 Correct 5 ms 3592 KB Output is correct
4 Correct 5 ms 3592 KB Output is correct
5 Correct 4 ms 3592 KB Output is correct
6 Correct 7 ms 3592 KB Output is correct
7 Correct 4 ms 3592 KB Output is correct
8 Correct 5 ms 3632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 4588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 4588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 4588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 4588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3448 KB Output is correct
2 Correct 6 ms 3448 KB Output is correct
3 Correct 5 ms 3592 KB Output is correct
4 Correct 5 ms 3592 KB Output is correct
5 Correct 4 ms 3592 KB Output is correct
6 Correct 7 ms 3592 KB Output is correct
7 Correct 4 ms 3592 KB Output is correct
8 Correct 5 ms 3632 KB Output is correct
9 Incorrect 32 ms 4588 KB Output isn't correct
10 Halted 0 ms 0 KB -