Submission #854160

# Submission time Handle Problem Language Result Execution time Memory
854160 2023-09-26T09:38:15 Z vjudge1 Chessboard (IZhO18_chessboard) C++17
70 / 100
449 ms 3724 KB
#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define pii pair<int,int>
#define pli pair<long long,int>
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
#define int long long
const int maxn=1e5+9;
struct rect{
int x1,y1,x2,y2;
}a[maxn];
long long cal(int len,bool odd){
if (!odd){
    if (len%2==1)len--;
    return (len-2)/2+1;
}
else {
    if (len%2==0)len--;
    return (len-1)/2+1;
}
}
long long x[2];
long long cal(int l,int r,bool odd){
if (odd){
if (r%2==0)r--;
if (l%2==0)l++;
if (l>r)return 0;
return (r-l)/2+1;
}
else {
if (r%2==1)r--;
if (l%2==1)l++;
if (l>r)return 0;
return (r-l)/2+1;
}
}
pair<long long,long long> solve(int x1, int y1,int i){
memset(x,0,sizeof(x));
if ((x1/i)==(y1/i)){
x[((x1+i-1)/i)%2]+=y1-x1+1;
//cout<<"yay";
}
else {
int len=(x1+i-1)/i;
//cerr<<len<<'\n';
x[len%2]+=(len)*i-x1+1;
x1=(len)*i+1;
x[((y1+i-1)/i)%2]+=(y1)%i;
y1-=(y1%i);
//cout<<x[0]<<" "<<y1<<'\n';
if (x1>y1)return {x[0],x[1]};
int l1=((x1+i-1)/i),l2=y1/i;
x[0]+=1ll*cal(l1,l2,0)*i;
x[1]+=1ll*cal(l1,l2,1)*i;
}
return {x[0],x[1]};
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("temp.INP","r",stdin);
    //freopen("temp.OUT","w",stdout);
    long long n;
    int k;
    cin>>n>>k;
    for1(i,1,k)cin>>a[i].x1>>a[i].y1>>a[i].x2>>a[i].y2;
    long long ans=n*n;
    for1(i,1,n-1){
    if (n%i!=0)continue;
    long long len=n/i;
    long long sum=cal(len,1)*cal(len,1)*i*i+cal(len,0)*cal(len,0)*i*i;
    long long sum2=cal(len,1)*cal(len,0)*i*i+cal(len,0)*cal(len,1)*i*i;
    for1(j,1,k){
    int x1=a[j].x1,y1=a[j].y1,x2=a[j].x2,y2=a[j].y2;
    pair<long long,long long>cordx=solve(x1,x2,i),cordy=solve(y1,y2,i);
    sum-=cordx.fi*cordy.fi;
    sum-=cordx.se*cordy.se;
    sum+=cordx.fi*cordy.se;
    sum+=cordx.se*cordy.fi;

    sum2+=cordx.fi*cordy.fi;
    sum2+=cordx.se*cordy.se;
    sum2-=cordx.fi*cordy.se;
    sum2-=cordx.se*cordy.fi;
    }
    ans=min(ans,sum);
    ans=min(ans,sum2);
    }
    cout<<ans;
}
# Verdict Execution time Memory 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 348 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
# Verdict Execution time Memory Grader output
1 Correct 17 ms 2652 KB Output is correct
2 Correct 5 ms 2648 KB Output is correct
3 Correct 11 ms 2652 KB Output is correct
4 Correct 12 ms 2648 KB Output is correct
5 Correct 15 ms 2704 KB Output is correct
6 Correct 10 ms 2652 KB Output is correct
7 Correct 3 ms 2648 KB Output is correct
8 Correct 10 ms 2652 KB Output is correct
9 Correct 25 ms 3016 KB Output is correct
10 Correct 14 ms 2652 KB Output is correct
# Verdict Execution time Memory 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 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory 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 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 8 ms 2652 KB Output is correct
17 Correct 19 ms 3156 KB Output is correct
18 Correct 32 ms 3724 KB Output is correct
19 Correct 88 ms 3164 KB Output is correct
20 Correct 96 ms 3420 KB Output is correct
21 Correct 21 ms 2956 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 19 ms 2652 KB Output is correct
24 Correct 25 ms 3160 KB Output is correct
25 Correct 4 ms 2544 KB Output is correct
26 Correct 17 ms 2652 KB Output is correct
27 Correct 23 ms 2648 KB Output is correct
28 Correct 29 ms 3204 KB Output is correct
29 Correct 8 ms 2704 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 2652 KB Output is correct
2 Correct 5 ms 2648 KB Output is correct
3 Correct 11 ms 2652 KB Output is correct
4 Correct 12 ms 2648 KB Output is correct
5 Correct 15 ms 2704 KB Output is correct
6 Correct 10 ms 2652 KB Output is correct
7 Correct 3 ms 2648 KB Output is correct
8 Correct 10 ms 2652 KB Output is correct
9 Correct 25 ms 3016 KB Output is correct
10 Correct 14 ms 2652 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 8 ms 2652 KB Output is correct
27 Correct 19 ms 3156 KB Output is correct
28 Correct 32 ms 3724 KB Output is correct
29 Correct 88 ms 3164 KB Output is correct
30 Correct 96 ms 3420 KB Output is correct
31 Correct 21 ms 2956 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 19 ms 2652 KB Output is correct
34 Correct 25 ms 3160 KB Output is correct
35 Correct 4 ms 2544 KB Output is correct
36 Correct 17 ms 2652 KB Output is correct
37 Correct 23 ms 2648 KB Output is correct
38 Correct 29 ms 3204 KB Output is correct
39 Correct 8 ms 2704 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 81 ms 3028 KB Output is correct
42 Correct 34 ms 3200 KB Output is correct
43 Correct 49 ms 2908 KB Output is correct
44 Correct 30 ms 3212 KB Output is correct
45 Correct 26 ms 3420 KB Output is correct
46 Correct 92 ms 3344 KB Output is correct
47 Correct 24 ms 2956 KB Output is correct
48 Correct 43 ms 3160 KB Output is correct
49 Correct 28 ms 2900 KB Output is correct
50 Correct 386 ms 3280 KB Output is correct
51 Correct 418 ms 3416 KB Output is correct
52 Correct 383 ms 3268 KB Output is correct
53 Correct 410 ms 3444 KB Output is correct
54 Correct 381 ms 3408 KB Output is correct
55 Correct 431 ms 3420 KB Output is correct
56 Correct 366 ms 3132 KB Output is correct
# Verdict Execution time Memory 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 348 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 Correct 17 ms 2652 KB Output is correct
10 Correct 5 ms 2648 KB Output is correct
11 Correct 11 ms 2652 KB Output is correct
12 Correct 12 ms 2648 KB Output is correct
13 Correct 15 ms 2704 KB Output is correct
14 Correct 10 ms 2652 KB Output is correct
15 Correct 3 ms 2648 KB Output is correct
16 Correct 10 ms 2652 KB Output is correct
17 Correct 25 ms 3016 KB Output is correct
18 Correct 14 ms 2652 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 8 ms 2652 KB Output is correct
35 Correct 19 ms 3156 KB Output is correct
36 Correct 32 ms 3724 KB Output is correct
37 Correct 88 ms 3164 KB Output is correct
38 Correct 96 ms 3420 KB Output is correct
39 Correct 21 ms 2956 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 19 ms 2652 KB Output is correct
42 Correct 25 ms 3160 KB Output is correct
43 Correct 4 ms 2544 KB Output is correct
44 Correct 17 ms 2652 KB Output is correct
45 Correct 23 ms 2648 KB Output is correct
46 Correct 29 ms 3204 KB Output is correct
47 Correct 8 ms 2704 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 81 ms 3028 KB Output is correct
50 Correct 34 ms 3200 KB Output is correct
51 Correct 49 ms 2908 KB Output is correct
52 Correct 30 ms 3212 KB Output is correct
53 Correct 26 ms 3420 KB Output is correct
54 Correct 92 ms 3344 KB Output is correct
55 Correct 24 ms 2956 KB Output is correct
56 Correct 43 ms 3160 KB Output is correct
57 Correct 28 ms 2900 KB Output is correct
58 Correct 386 ms 3280 KB Output is correct
59 Correct 418 ms 3416 KB Output is correct
60 Correct 383 ms 3268 KB Output is correct
61 Correct 410 ms 3444 KB Output is correct
62 Correct 381 ms 3408 KB Output is correct
63 Correct 431 ms 3420 KB Output is correct
64 Correct 366 ms 3132 KB Output is correct
65 Correct 0 ms 348 KB Output is correct
66 Correct 0 ms 344 KB Output is correct
67 Incorrect 449 ms 3312 KB Output isn't correct
68 Halted 0 ms 0 KB -