제출 #168621

#제출 시각아이디문제언어결과실행 시간메모리
168621MrPlanyChessboard (IZhO18_chessboard)C++17
39 / 100
293 ms3576 KiB
// In the name of God #include <bits/stdc++.h> //#include <conio.h> #define ff first #define ss second #define pb push_back #define pp pop_back #define mp make_pair #define db double #define INF 1000000009 #define ll long long #define all(a) a.begin(), a.end() #define iOS ios_base::sync_with_stdio(false) using namespace std; const int N = 2e5 + 9, mod = 1e9+7; int n,k; struct gr{ int x1,y1,x2,y2; }; gr d[N]; int f(int v, int p){ if(v%p==0) return v; return (v/p+1)*p; } int ters(int col){ return (col==1?0:1); } ll solve(int p, int col){ ll as_ak = 0 , as_gara = 0; if( (n/p)%2 == 0 ){ as_gara = (n*n)/2; } else{ ll t= (n/p); as_gara = (t/2)*t + (t-1)/2 + 1; as_gara *= (p*p); if(col == 0) as_gara = (n*n) - as_gara; } ll gara = 0 , ak = 0 ; for(int i=1;i<=k;i++){ gr a = d[i] , b; b = a; while(true){ gr c; c.x2 = f(a.x1,p); c.x1 = c.x2 - p + 1; c.y2 = f(a.y1,p); c.y1 = c.y2 - p + 1; gr e = c; e.x1 = max( c.x1 , a.x1 ); e.y1 = max( c.y1 , a.y1 ); e.x2 = min( c.x2 , a.x2 ); e.y2 = min( c.y2 , a.y2 ); ll S = 1LL*abs( e.x2 - e.x1 + 1 ) * abs(e.y2 - e.y1 + 1); int o1 = f(c.x1,p); int o2 = f(c.y1,p); if( (o1/p)%2 == (o2/p)%2 ){ if(col == 1) gara+=S; else ak+=S; } else{ if(ters(col) == 1) gara+=S; else ak+=S; } if( e.x2 == a.x2 && e.y2 == a.y2 ) break; a.y1 = f(a.y1,p) + 1; if(a.y1 > a.y2) a.x1 = f(a.x1,p) + 1 , a.y1 = b.y1; } /* int o1 = f(a[i].x1,p); int o2 = f(a[i].y1,p); if( (o1/p)%2 == (o2/p)%2 ){ if(col == 1) gara++; else ak++; } else{ if( ters(col) == 1 ) gara++; else ak++; } */ } //cout << as_gara << " " << " " << ((as_gara - gara) + ak) << " " << p << " " << col << endl; // as_garada problema bar. return ((as_gara - gara) + ak); } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>n>>k; for(int i=1;i<=k;i++){ cin>>d[i].x1>>d[i].y1>>d[i].x2>>d[i].y2; } ll mn = INF; for(int i=1;i<n;i++){ if(n%i == 0){ mn = min( mn, solve(i,0) ); mn = min( mn, solve(i,1) ); } } cout <<mn; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

chessboard.cpp: In function 'long long int solve(int, int)':
chessboard.cpp:36:5: warning: unused variable 'as_ak' [-Wunused-variable]
  ll as_ak = 0 , as_gara = 0;
     ^~~~~
#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...