Submission #1112639

# Submission time Handle Problem Language Result Execution time Memory
1112639 2024-11-14T13:22:36 Z noyancanturk Chessboard (IZhO18_chessboard) C++17
8 / 100
51 ms 2384 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
using pii=pair<int,int>;
signed main(){
  int n,k;
  cin>>n>>k;
  int a[k],b[k],c[k],d[k];
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i]>>d[i];
  }
  int ans=n*n;
  for(int len=1;len<n;len++){
    if(n%len)continue;
    auto cntfind=[&](int x,int y)->pii {
      if(!x||!y)return pii{0,0};
      int st1,nd1;
      if((x/len)%2==1){
        st1=(x/len/2+1)*len;
        nd1=x-st1;
      }else{
        nd1=(x/len/2)*len;
        st1=x-nd1;
      }
      int st2,nd2;
      if((y/len)%2==1){
        st2=(y/len/2+1)*len;
        nd2=y-st2;
      }else{
        nd2=(y/len/2)*len;
        st2=y-nd2;
      }
      return pii{st1*st2+nd1*nd2,x*y-(st1*st2+nd1*nd2)};
    };
    int part=n/len;
    auto[need1,need2]=cntfind(n,n);
    for(int i=0;i<k;i++){
      int xx=a[i],yx=b[i],xy=c[i],yy=d[i];
      pii res;
      res=cntfind(xy,yy);
      need1-=res.first-res.second;
      need2-=res.second-res.first;
      res=cntfind(xx-1,yx-1);
      need1-=res.first-res.second;
      need2-=res.second-res.first;
      res=cntfind(xx-1,yy);
      need1-=res.second-res.first;
      need2-=res.first-res.second;
      res=cntfind(xy,yx-1);
      need1-=res.second-res.first;
      need2-=res.first-res.second;
    }
    ans=min({ans,need1,need2});
  }
  cout<<ans;
}


Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:35:9: warning: unused variable 'part' [-Wunused-variable]
   35 |     int part=n/len;
      |         ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 560 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 2384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 2384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 560 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Incorrect 51 ms 2384 KB Output isn't correct
10 Halted 0 ms 0 KB -