제출 #1132989

#제출 시각아이디문제언어결과실행 시간메모리
1132989AgageldiChessboard (IZhO18_chessboard)C++17
39 / 100
192 ms23880 KiB
/* TASK: siuu */ #include <bits/stdc++.h> using namespace std; #define ll long long #define N 400005 #define ff first #define ss second #define pb push_back #define sz(s) (int)s.size() #define rep(c, a, b) for(c = a; c <= b; c++) ll n, t, a[6000][6000], b[6000][6000], answer, k, jogap; void solve1(int x,int bal) { bool tr = 0, tp = 0; if(!bal) tr = 1; ll ans = 0; for(int i = 1; i <= n; i++) { tp = tr; for(int j = 1; j <= n; j++) { if(tp == 0) b[i][j] = 0; else b[i][j] = 1; if(j % x == 0) tp = 1 - tp; if(a[i][j]!=b[i][j]) ans++; } if(i % x == 0) tr = 1 - tr; } answer = min(ans,answer); } int main () { ios::sync_with_stdio(0);cin.tie(0); cin >> n >> k; for(int i = 1; i <= k; i++) { int x1, x2,y1,y2; cin >> x1 >> y1 >> x2 >> y2; if(x1 % 2 == y1 % 2) answer++; else jogap++; if(n >= 4e3) continue; for(int j = x1; j <= x2; j++) { for(int l = y1; l <= y2; l++) { a[j][l] = 1; } } } if(n >= 4e3) { cout << min(n/2 * n/2 - jogap + answer,(n + 1)/2 * (n + 1)/2 - answer + jogap) << '\n'; return 0; } answer = INT_MAX; for(int i = 1; i * i <= n; i++) { if(n % i == 0) { solve1(i, 1); solve1(i, 0); if(i != 1){ solve1(n/i,1); solve1(n/i,0); } } } cout << answer << '\n'; }
#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...