Submission #91265

#TimeUsernameProblemLanguageResultExecution timeMemory
91265VardanyanChessboard (IZhO18_chessboard)C++14
100 / 100
353 ms48872 KiB
#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;
        long long need2 = 0;
        for(int i = 1;i<=n;i++){
            if(tox_type[i] == 1) need+=pref_type1[n];
            else need+=pref_type2[n];
        }
        need2 = n;
        need2*=n;
        need2-=need;
        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;
            long long sev = (qan_tp1*(pref_type1[y2]-pref_type1[y1-1])+qan_tp2*(pref_type2[y2]-pref_type2[y1-1]));
            need-=sev;
            need+=((x2-x1+1)*(y2-y1+1)-sev);
            need2-=((x2-x1+1)*(y2-y1+1)-sev);
            need2+=sev;
        }
        ans = min(ans,min(need,need2));

    }
    cout<<ans<<endl;
    return 0;
}

Compilation message (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...