답안 #872660

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
872660 2023-11-13T13:51:10 Z epicci23 Chessboard (IZhO18_chessboard) C++17
39 / 100
2000 ms 22424 KB
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

/*
 implement and debug smart
 DONT GET STUCK ON ONE APPROACH
 write smth on paper
 edge cases (n=1?)
 rewrite the problem
 simplify
 transform the problem into other problem
*/


void solve(){

  int n,k;
  cin >> n >> k;
 
  vector<array<int,4>> v;

  int ans = n * n;

  for(int i=1;i<=k;i++){
     int a,b,c,d;
     cin >> a >> b >> c >> d;
     a--;
     b--;
     c--;
     d--;
     v.pb({a,b,c,d});
  }  
  
  auto f = [](array<int,4> a,array<int,4> b)->array<int,4>{
     int xl,xr,yl,yr;
     xl=max(a[0],b[0]);
     xr=min(a[2],b[2]);
     yl=max(a[1],b[1]);
     yr=min(a[3],b[3]);
     if(xl<=xr && yl<=yr) return {xl,yl,xr,yr};
     else return {-1,-1,-1,-1};
  };

  for(int i=1;i<n;i++){

  	if(n%i) continue;
    
    // 1 siyah
    // 0 beyaz

    int cur = 0;
    
    map<array<int,4>,vector<array<int,4>>> mp;

    int kac_siyah = (n / i) * ( (n / i) / 2);
    if((n/i)&1) kac_siyah +=  (n / i) / 2;

    for(auto x : v){
      int aa = x[0]-(x[0]%i);
      int bb = x[1]-(x[1]%i);

      for(int a=aa;a<=n;a+=i){
	       for(int b=bb;b<=n;b+=i){
		      if(f(x,{a,b,a+i-1,b+i-1})[0]!=-1)
		       mp[{a,b,a+i-1,b+i-1}].pb(f(x,{a,b,a+i-1,b+i-1}));
		      else break;
	       }
      }
    }

    for(auto x:mp){
      int col = (x.first[0] / i + x.first[1] / i) & 1;
      int hm = 0;
      for(auto y:x.second) hm+=(y[2]-y[0]+1)*(y[3]-y[1]+1);
      if(col) cur+=i*i-hm;
      else cur+=hm;
      if(col) kac_siyah--;
    }
    
    //cout << i << ": " << kac_siyah << endl;
    cur += kac_siyah * i * i;
    ans=min(ans,cur);
    
    cur=0;
    kac_siyah = (n / i) * ( (n/i) / 2);
    if((n/i)&1) kac_siyah +=  (n / i + 1) / 2;

    for(auto x:mp){
      int col = (x.first[0] / i + x.first[1] / i) & 1;
      col^=1;
      int hm = 0;
      for(auto y:x.second) hm+=(y[2]-y[0]+1)*(y[3]-y[1]+1);
      if(col) cur+=i*i-hm;
      else cur+=hm;
      if(col) kac_siyah--;
    }

    cur += kac_siyah * i * i;
    //cout << i << ": " << kac_siyah << endl;
    ans=min(ans,cur);
  }

  cout << ans << endl;
}

int32_t main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  
  int t=1;//cin >> t;
  while(t--) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 420 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2073 ms 6592 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 464 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 644 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 464 KB Output is correct
8 Correct 2 ms 604 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 604 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 2 ms 644 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 97 ms 5596 KB Output is correct
17 Correct 273 ms 16080 KB Output is correct
18 Correct 387 ms 19292 KB Output is correct
19 Correct 1090 ms 21344 KB Output is correct
20 Correct 1190 ms 22424 KB Output is correct
21 Correct 211 ms 16848 KB Output is correct
22 Correct 3 ms 348 KB Output is correct
23 Correct 217 ms 10612 KB Output is correct
24 Correct 325 ms 17344 KB Output is correct
25 Correct 34 ms 2296 KB Output is correct
26 Correct 181 ms 11292 KB Output is correct
27 Correct 330 ms 18368 KB Output is correct
28 Correct 385 ms 21440 KB Output is correct
29 Correct 74 ms 6644 KB Output is correct
30 Correct 11 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2073 ms 6592 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 420 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Execution timed out 2073 ms 6592 KB Time limit exceeded
10 Halted 0 ms 0 KB -