답안 #241526

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
241526 2020-06-24T11:26:14 Z mhy908 Chessboard (IZhO18_chessboard) C++14
16 / 100
46 ms 1656 KB
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define svec(x) sort(x.begin(), x.end())
#define press(x) x.erase(unique(x.begin(), x.end()), x.end())
#define lb(x, v) lower_bound(x.begin(), x.end(), v)
#define ub(x, v) upper_bound(x.begin(), x.end(), v)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
const LL llinf=2000000000000000000;
const LL mod1=1000000007;
const LL mod2=998244353;
const int inf=2000000000;
int n, k;
pair<pii, pii> rect[100010];
LL ans=llinf;
LL query2(int x, int y, int s){
    LL ret=0;
    int tx=x/s, ty=y/s;
    ret+=(LL)tx*ty/2*s*s;
    int rx=x%s, ry=y%s;
    if(tx%2)ret+=(LL)rx*(ty+1)/2*s;
    else ret+=(LL)rx*ty/2*s;
    if(ty%2)ret+=(LL)ry*(tx+1)/2*s;
    else ret+=(LL)ry*tx/2*s;
    if((tx+ty)%2)ret+=(LL)rx*ry;
    return ret;
}
pll query(int stx, int sty, int finx, int finy, int s){
    //LL b=query2(finx, finy, s)-query2(stx-1, finy, s)-query2(finx, sty-1, s)+query2(stx-1, sty-1, s);
    //LL w=(LL)(finx-stx+1)*(finy-sty+1)-b;
    if((stx+sty)%2)return mp(1, 0);
    return mp(0, 1);
}
int main(){
    scanf("%d %d", &n, &k);
    for(int i=1; i<=k; i++){
        scanf("%d %d %d %d", &rect[i].F.F, &rect[i].F.S, &rect[i].S.F, &rect[i].S.S);
    }
    for(int i=1; i<n; i++){
        if(n%i)continue;
        LL w=0, b=0;
        for(int j=1; j<=k; j++){
            pll tmp=query(rect[j].F.F, rect[j].F.S, rect[j].S.F, rect[j].S.S, i);
            b+=tmp.F;
            w+=tmp.S;
        }
        LL temp1=w+(LL)(n/i)*(n/i)/2*i*i-b;
        LL temp2=b+((LL)(n/i)*(n/i)+1)/2*i*i-w;
        ans=min(ans, min(temp1, temp2));
    }
    printf("%lld", ans);
}
/*
6 8
3 3 3 3
1 2 1 2
3 4 3 4
5 5 5 5
4 3 4 3
4 4 4 4
2 1 2 1
3 6 3 6
*/

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &k);
     ~~~~~^~~~~~~~~~~~~~~~~
chessboard.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d %d", &rect[i].F.F, &rect[i].F.S, &rect[i].S.F, &rect[i].S.S);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 308 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 1408 KB Output is correct
2 Correct 12 ms 512 KB Output is correct
3 Correct 23 ms 896 KB Output is correct
4 Correct 28 ms 1024 KB Output is correct
5 Correct 31 ms 1280 KB Output is correct
6 Correct 20 ms 896 KB Output is correct
7 Correct 8 ms 512 KB Output is correct
8 Correct 20 ms 896 KB Output is correct
9 Correct 46 ms 1656 KB Output is correct
10 Correct 28 ms 1152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 1408 KB Output is correct
2 Correct 12 ms 512 KB Output is correct
3 Correct 23 ms 896 KB Output is correct
4 Correct 28 ms 1024 KB Output is correct
5 Correct 31 ms 1280 KB Output is correct
6 Correct 20 ms 896 KB Output is correct
7 Correct 8 ms 512 KB Output is correct
8 Correct 20 ms 896 KB Output is correct
9 Correct 46 ms 1656 KB Output is correct
10 Correct 28 ms 1152 KB Output is correct
11 Incorrect 4 ms 256 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 308 KB Output is correct
7 Correct 4 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 34 ms 1408 KB Output is correct
10 Correct 12 ms 512 KB Output is correct
11 Correct 23 ms 896 KB Output is correct
12 Correct 28 ms 1024 KB Output is correct
13 Correct 31 ms 1280 KB Output is correct
14 Correct 20 ms 896 KB Output is correct
15 Correct 8 ms 512 KB Output is correct
16 Correct 20 ms 896 KB Output is correct
17 Correct 46 ms 1656 KB Output is correct
18 Correct 28 ms 1152 KB Output is correct
19 Incorrect 4 ms 256 KB Output isn't correct
20 Halted 0 ms 0 KB -