답안 #340369

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
340369 2020-12-27T13:29:30 Z scales Chessboard (IZhO18_chessboard) C++17
70 / 100
508 ms 5580 KB
#include <bits/stdc++.h>
/*#ifndef LOCAL_RUN
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC optimize("fast-math")
    #pragma GCC target("avx2,tune=native")
#endif*/
using namespace std;
int main()
{
      ios::sync_with_stdio(false);
      cin.tie(0);
     // freopen("input.txt","r",stdin);
     // freopen("output.txt","w",stdout);
     long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,g,p,l,r,sum,maxi,kol,v,f,s,h,z1;
     dno=0;
     cin>>n;
     cin>>k;
     z=0;
     tip=0;
     maxi=100000000000;
     vector<long long> a(k),b(k),c(k),d(k);
     for(i=0;i<k;i++)
     {
         cin>>a[i];
         cin>>b[i];
         cin>>c[i];
         cin>>d[i];
         a[i]--;
         b[i]--;
         c[i]--;
         d[i]--;
         tip=tip+(c[i]-a[i]+1)*(d[i]-b[i]+1);
     }
     vector<long long> viv;
     for(i=1;i<n;i++)
     {
         if(n%i==0)
         {
             viv.push_back(i);
         }
     }
     z1=viv.size();
     //cout<<"tip="<<tip<<endl;
     //cout<<"z1="<<z1<<endl;
        for(i=0;i<z1;i++)
        {
             kol=0;
             w=viv[i];
             //cout<<"w="<<w<<endl;
             //cout<<"w="<<w<<endl;
             for(j=0;j<k;j++)
             {
                 //cout<<"a="<<a[j]<<" b="<<b[j]<<" "<<a[j]%(2*w)<<" "<<b[j]%(2*w)<<endl;
                 z=(c[j]-a[j])/(2*w);
                 g=z*w;
                 x=a[j]%(2*w);
                 y=c[j]%(2*w);
                 if(x<=y)
                 {
                     l=x;
                     r=min(w-1,y);
                 }
                 else
                 {
                     if(x>y)
                     {
                        l=0;
                        r=min(w-1,y);
                     }
                     else
                     {
                         r=0;
                         l=1;
                     }
                 }
                 g=g+max(dno,(r-l+1));

                 z=(d[j]-b[j])/(2*w);
                 x=b[j]%(2*w);
                 y=d[j]%(2*w);
                 h=z*w;
                   // cout<<"h="<<h<<" z="<<z<<endl;
                 if(x<=y)
                 {
                     l=x;
                     r=min(w-1,y);
                 }
                 else
                 {
                     if(x>y)
                     {
                        l=0;
                        r=min(w-1,y);
                     }
                     else
                     {
                         r=0;
                         l=1;
                     }
                 }
                 //cout<<"h="<<h<<" dno="<<dno<<endl;
                 h=h+max(dno,(r-l+1));
                 //cout<<"g="<<g<<" h="<<h<<endl;
                 kol=kol+g*(d[j]-b[j]+1-h)+h*(c[j]-a[j]+1-g);

             }
             v=(n*n)/(w*w);
             if(v%2==0)
             {
                 f=n*n/2;
                 s=n*n/2;
             }
             else
             {
                 s=(n*n-w*w)/2;
                 f=n*n-s;
             }
             kol=tip-kol;
             //cout<<"kol="<<kol<<" f="<<f<<" s="<<s<<" maxi=";
             maxi=min({maxi,(f-kol+tip-kol),(kol+s-tip+kol)});
             //cout<<maxi<<endl;
        }
        cout<<maxi<<endl;
    return 0;
}

Compilation message

chessboard.cpp: In function 'int main()':
chessboard.cpp:15:16: warning: unused variable 't' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,g,p,l,r,sum,maxi,kol,v,f,s,h,z1;
      |                ^
chessboard.cpp:15:34: warning: unused variable 'm' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,g,p,l,r,sum,maxi,kol,v,f,s,h,z1;
      |                                  ^
chessboard.cpp:15:40: warning: unused variable 'x1' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,g,p,l,r,sum,maxi,kol,v,f,s,h,z1;
      |                                        ^~
chessboard.cpp:15:43: warning: unused variable 'y1' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,g,p,l,r,sum,maxi,kol,v,f,s,h,z1;
      |                                           ^~
chessboard.cpp:15:52: warning: unused variable 'p' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,g,p,l,r,sum,maxi,kol,v,f,s,h,z1;
      |                                                    ^
chessboard.cpp:15:58: warning: unused variable 'sum' [-Wunused-variable]
   15 |      long long t,i,j,dno,x,y,z,w,m,k,n,x1,y1,tip,g,p,l,r,sum,maxi,kol,v,f,s,h,z1;
      |                                                          ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 2924 KB Output is correct
2 Correct 8 ms 1260 KB Output is correct
3 Correct 18 ms 2156 KB Output is correct
4 Correct 22 ms 2412 KB Output is correct
5 Correct 24 ms 2796 KB Output is correct
6 Correct 18 ms 2028 KB Output is correct
7 Correct 4 ms 748 KB Output is correct
8 Correct 16 ms 2028 KB Output is correct
9 Correct 39 ms 3820 KB Output is correct
10 Correct 22 ms 2540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 15 ms 1644 KB Output is correct
17 Correct 32 ms 3564 KB Output is correct
18 Correct 44 ms 4224 KB Output is correct
19 Correct 111 ms 3820 KB Output is correct
20 Correct 122 ms 4204 KB Output is correct
21 Correct 36 ms 3436 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 25 ms 2028 KB Output is correct
24 Correct 40 ms 3820 KB Output is correct
25 Correct 6 ms 748 KB Output is correct
26 Correct 26 ms 2540 KB Output is correct
27 Correct 37 ms 2924 KB Output is correct
28 Correct 42 ms 4076 KB Output is correct
29 Correct 16 ms 1772 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 2924 KB Output is correct
2 Correct 8 ms 1260 KB Output is correct
3 Correct 18 ms 2156 KB Output is correct
4 Correct 22 ms 2412 KB Output is correct
5 Correct 24 ms 2796 KB Output is correct
6 Correct 18 ms 2028 KB Output is correct
7 Correct 4 ms 748 KB Output is correct
8 Correct 16 ms 2028 KB Output is correct
9 Correct 39 ms 3820 KB Output is correct
10 Correct 22 ms 2540 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 15 ms 1644 KB Output is correct
27 Correct 32 ms 3564 KB Output is correct
28 Correct 44 ms 4224 KB Output is correct
29 Correct 111 ms 3820 KB Output is correct
30 Correct 122 ms 4204 KB Output is correct
31 Correct 36 ms 3436 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 25 ms 2028 KB Output is correct
34 Correct 40 ms 3820 KB Output is correct
35 Correct 6 ms 748 KB Output is correct
36 Correct 26 ms 2540 KB Output is correct
37 Correct 37 ms 2924 KB Output is correct
38 Correct 42 ms 4076 KB Output is correct
39 Correct 16 ms 1772 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 102 ms 3564 KB Output is correct
42 Correct 55 ms 4096 KB Output is correct
43 Correct 71 ms 3564 KB Output is correct
44 Correct 47 ms 3820 KB Output is correct
45 Correct 42 ms 4076 KB Output is correct
46 Correct 117 ms 3932 KB Output is correct
47 Correct 44 ms 3692 KB Output is correct
48 Correct 57 ms 3692 KB Output is correct
49 Correct 43 ms 3564 KB Output is correct
50 Correct 449 ms 3948 KB Output is correct
51 Correct 477 ms 4064 KB Output is correct
52 Correct 448 ms 3820 KB Output is correct
53 Correct 483 ms 4076 KB Output is correct
54 Correct 446 ms 3820 KB Output is correct
55 Correct 508 ms 4076 KB Output is correct
56 Correct 436 ms 3744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 28 ms 2924 KB Output is correct
10 Correct 8 ms 1260 KB Output is correct
11 Correct 18 ms 2156 KB Output is correct
12 Correct 22 ms 2412 KB Output is correct
13 Correct 24 ms 2796 KB Output is correct
14 Correct 18 ms 2028 KB Output is correct
15 Correct 4 ms 748 KB Output is correct
16 Correct 16 ms 2028 KB Output is correct
17 Correct 39 ms 3820 KB Output is correct
18 Correct 22 ms 2540 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 15 ms 1644 KB Output is correct
35 Correct 32 ms 3564 KB Output is correct
36 Correct 44 ms 4224 KB Output is correct
37 Correct 111 ms 3820 KB Output is correct
38 Correct 122 ms 4204 KB Output is correct
39 Correct 36 ms 3436 KB Output is correct
40 Correct 1 ms 364 KB Output is correct
41 Correct 25 ms 2028 KB Output is correct
42 Correct 40 ms 3820 KB Output is correct
43 Correct 6 ms 748 KB Output is correct
44 Correct 26 ms 2540 KB Output is correct
45 Correct 37 ms 2924 KB Output is correct
46 Correct 42 ms 4076 KB Output is correct
47 Correct 16 ms 1772 KB Output is correct
48 Correct 2 ms 492 KB Output is correct
49 Correct 102 ms 3564 KB Output is correct
50 Correct 55 ms 4096 KB Output is correct
51 Correct 71 ms 3564 KB Output is correct
52 Correct 47 ms 3820 KB Output is correct
53 Correct 42 ms 4076 KB Output is correct
54 Correct 117 ms 3932 KB Output is correct
55 Correct 44 ms 3692 KB Output is correct
56 Correct 57 ms 3692 KB Output is correct
57 Correct 43 ms 3564 KB Output is correct
58 Correct 449 ms 3948 KB Output is correct
59 Correct 477 ms 4064 KB Output is correct
60 Correct 448 ms 3820 KB Output is correct
61 Correct 483 ms 4076 KB Output is correct
62 Correct 446 ms 3820 KB Output is correct
63 Correct 508 ms 4076 KB Output is correct
64 Correct 436 ms 3744 KB Output is correct
65 Correct 1 ms 364 KB Output is correct
66 Correct 1 ms 364 KB Output is correct
67 Incorrect 469 ms 5580 KB Output isn't correct
68 Halted 0 ms 0 KB -