답안 #880792

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880792 2023-11-30T05:03:08 Z dimashhh Chessboard (IZhO18_chessboard) C++17
39 / 100
427 ms 135052 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 12;

unordered_map<int,int> odd[N],even[N];
ll col_eq(int k,int x,int y,int x1,int y1){
    ll ret = (odd[x1][k] - odd[x - 1][k]) * (odd[y1][k] - odd[y - 1][k]);
    ret += (even[x1][k] - even[x - 1][k]) *1ll* (even[y1][k] - even[y - 1][k]);
    return ret;
}

ll col_non_eq(int k,int x,int y,int x1,int y1){
    return (x1 - x + 1) *1ll* (y1 - y + 1) - col_eq(k,x,y,x1,y1);
}
vector<pair<pair<int,int>,pair<int,int>>> a;
ll n,k;
int get(ll del){
    ll res1 = 0,res2 = 0;
    for(auto [x,y]:a){
        res1 += col_eq(del,x.first,x.second,y.first,y.second);
        res2 += col_non_eq(del,x.first,x.second,y.first,y.second);
    }
    ll x = res1;
    res1 = ((n * n / del / del) + 1) / 2 * (del * del) - res1 + res2;
    res2 = ((n * n / del / del)) / 2 * (del * del) + x - res2;
    // cout << ((n * n / del / del) + 1) / 2 * del * del - res2 << '\n';
    return min(res1,res2);
}
void test(){
    cin >> n >> k;
    for(int i = 1;i <= k;i++){
        int x,y,x1,y1;
        cin >> x >> y >> x1 >> y1;
        a.push_back({{x,y},{x1,y1}});
    }
    ll res = 1e10;
    for(int i = 1;i < n;i++){
        if(n % i == 0){
            for(int j = 1;j <= n;j++){
                int x = (j + i - 1) / i;
                odd[j][i] = odd[j - 1][i];
                even[j][i] = even[j - 1][i];
                if(x & 1){
                    odd[j][i]++;
                }else{
                    even[j][i]++;
                }
            }
        }
    }
    for(int i = 1;i < n;i++){
        if(n % i == 0){
            res = min(res,1ll*get(i));
        }
    }
    cout << res;
}
main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    test();
}

Compilation message

chessboard.cpp:59:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   59 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 109916 KB Output is correct
2 Correct 27 ms 109988 KB Output is correct
3 Correct 27 ms 109916 KB Output is correct
4 Correct 26 ms 109912 KB Output is correct
5 Correct 27 ms 109916 KB Output is correct
6 Correct 27 ms 109916 KB Output is correct
7 Correct 26 ms 109912 KB Output is correct
8 Correct 26 ms 109912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 129824 KB Output is correct
2 Correct 40 ms 114368 KB Output is correct
3 Incorrect 96 ms 135052 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 109916 KB Output is correct
2 Correct 26 ms 109916 KB Output is correct
3 Correct 28 ms 110100 KB Output is correct
4 Correct 28 ms 109916 KB Output is correct
5 Correct 26 ms 110112 KB Output is correct
6 Correct 30 ms 109984 KB Output is correct
7 Correct 27 ms 109916 KB Output is correct
8 Correct 27 ms 109916 KB Output is correct
9 Correct 26 ms 109912 KB Output is correct
10 Correct 26 ms 109916 KB Output is correct
11 Correct 27 ms 109916 KB Output is correct
12 Correct 28 ms 109916 KB Output is correct
13 Correct 27 ms 109928 KB Output is correct
14 Correct 28 ms 109912 KB Output is correct
15 Correct 27 ms 109916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 109916 KB Output is correct
2 Correct 26 ms 109916 KB Output is correct
3 Correct 28 ms 110100 KB Output is correct
4 Correct 28 ms 109916 KB Output is correct
5 Correct 26 ms 110112 KB Output is correct
6 Correct 30 ms 109984 KB Output is correct
7 Correct 27 ms 109916 KB Output is correct
8 Correct 27 ms 109916 KB Output is correct
9 Correct 26 ms 109912 KB Output is correct
10 Correct 26 ms 109916 KB Output is correct
11 Correct 27 ms 109916 KB Output is correct
12 Correct 28 ms 109916 KB Output is correct
13 Correct 27 ms 109928 KB Output is correct
14 Correct 28 ms 109912 KB Output is correct
15 Correct 27 ms 109916 KB Output is correct
16 Correct 40 ms 111324 KB Output is correct
17 Correct 59 ms 113360 KB Output is correct
18 Correct 76 ms 113712 KB Output is correct
19 Correct 333 ms 114856 KB Output is correct
20 Correct 427 ms 115056 KB Output is correct
21 Correct 58 ms 113368 KB Output is correct
22 Correct 30 ms 111452 KB Output is correct
23 Correct 64 ms 111828 KB Output is correct
24 Correct 69 ms 113404 KB Output is correct
25 Correct 35 ms 111060 KB Output is correct
26 Correct 54 ms 112088 KB Output is correct
27 Correct 97 ms 113208 KB Output is correct
28 Correct 72 ms 113368 KB Output is correct
29 Correct 37 ms 111580 KB Output is correct
30 Correct 28 ms 110428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 129824 KB Output is correct
2 Correct 40 ms 114368 KB Output is correct
3 Incorrect 96 ms 135052 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 109916 KB Output is correct
2 Correct 27 ms 109988 KB Output is correct
3 Correct 27 ms 109916 KB Output is correct
4 Correct 26 ms 109912 KB Output is correct
5 Correct 27 ms 109916 KB Output is correct
6 Correct 27 ms 109916 KB Output is correct
7 Correct 26 ms 109912 KB Output is correct
8 Correct 26 ms 109912 KB Output is correct
9 Correct 91 ms 129824 KB Output is correct
10 Correct 40 ms 114368 KB Output is correct
11 Incorrect 96 ms 135052 KB Output isn't correct
12 Halted 0 ms 0 KB -