Submission #334354

# Submission time Handle Problem Language Result Execution time Memory
334354 2020-12-09T04:15:34 Z beksultan04 Chessboard (IZhO18_chessboard) C++14
70 / 100
903 ms 4972 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define pb push_back
#define endi puts("");
const int N = 1e5+12,INF=1e9+7;
int resh[N],ans[N],n;
vector <int> v[N];
int fun(int x){
    int i,j,ans=0,cnt=0,res=0,c=1;
    for (i=0;i<n;++i){
        if (i % x == 0  && i != 0){
            c++;
        }

        if (c%2 ){
            res += (((n/x)+1)/2)*x;
        }
        else {
            res += ((((n-x)/x)+1)/2)*x;
        }
    }
    c=1;
    for (i=1;i<=n;++i){
        for (j=0;j<v[i].size();++j){
            int y = (v[i][j]-1)/x;
            if (y%2 == 0 && c%2 == 1 || y%2 == 1 && c%2 == 0 )res--;
            else res++;
        }
        if (i % x == 0)
            c++;
    }
    ret (res);
}
int fun1(int x){
    int i,j,ans=0,cnt=0,res=0,c=0;
    for (i=0;i<n;++i){
        if (i % x == 0  && i != 0){
            c++;
        }

        if (c%2 ){
            res += (((n/x)+1)/2)*x;
        }
        else {
            res += ((((n-x)/x)+1)/2)*x;
        }
    }
    c=0;
    for (i=1;i<=n;++i){
        for (j=0;j<v[i].size();++j){
            int y = (v[i][j]-1)/x;
            if (y%2 == 0 && c%2 == 1 || y%2 == 1 && c%2 == 0 )res--;
            else res++;
        }
        if (i % x == 0)
            c++;
    }
    ret (res);

}

main(){
    int k,i,j;
    vector <int> pr;
    scan2(n,k)

    while (k--){
        int x1,x2,y1,y2;
        scan2(x1,y1)
        scan2(x2,y2)
        v[x1].pb(y1);
    }
    /// ///////////////////////
    for (i=2;i*i<=n;++i){
        if (n%i==0){
            pr.pb(i);
            if (i*i != n)pr.pb(n/i);
        }
    }
    int ans=min(fun(1),fun1(1));
    for (i=0;i<pr.size();++i){
        ans = min(ans,min(fun(pr[i]),fun1(pr[i])));
    }
    cout <<ans;
}


















Compilation message

chessboard.cpp: In function 'long long int fun(long long int)':
chessboard.cpp:34:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for (j=0;j<v[i].size();++j){
      |                  ~^~~~~~~~~~~~
chessboard.cpp:36:26: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   36 |             if (y%2 == 0 && c%2 == 1 || y%2 == 1 && c%2 == 0 )res--;
      |                 ~~~~~~~~~^~~~~~~~~~~
chessboard.cpp:19:13: warning: unused variable 'ans' [-Wunused-variable]
   19 |     int i,j,ans=0,cnt=0,res=0,c=1;
      |             ^~~
chessboard.cpp:19:19: warning: unused variable 'cnt' [-Wunused-variable]
   19 |     int i,j,ans=0,cnt=0,res=0,c=1;
      |                   ^~~
chessboard.cpp: In function 'long long int fun1(long long int)':
chessboard.cpp:60:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |         for (j=0;j<v[i].size();++j){
      |                  ~^~~~~~~~~~~~
chessboard.cpp:62:26: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   62 |             if (y%2 == 0 && c%2 == 1 || y%2 == 1 && c%2 == 0 )res--;
      |                 ~~~~~~~~~^~~~~~~~~~~
chessboard.cpp:45:13: warning: unused variable 'ans' [-Wunused-variable]
   45 |     int i,j,ans=0,cnt=0,res=0,c=0;
      |             ^~~
chessboard.cpp:45:19: warning: unused variable 'cnt' [-Wunused-variable]
   45 |     int i,j,ans=0,cnt=0,res=0,c=0;
      |                   ^~~
chessboard.cpp: At global scope:
chessboard.cpp:72:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   72 | main(){
      |      ^
chessboard.cpp: In function 'int main()':
chessboard.cpp:91:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   91 |     for (i=0;i<pr.size();++i){
      |              ~^~~~~~~~~~
chessboard.cpp:73:13: warning: unused variable 'j' [-Wunused-variable]
   73 |     int k,i,j;
      |             ^
chessboard.cpp:10:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~
chessboard.cpp:75:5: note: in expansion of macro 'scan2'
   75 |     scan2(n,k)
      |     ^~~~~
chessboard.cpp:10:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~
chessboard.cpp:79:9: note: in expansion of macro 'scan2'
   79 |         scan2(x1,y1)
      |         ^~~~~
chessboard.cpp:10:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~
chessboard.cpp:80:9: note: in expansion of macro 'scan2'
   80 |         scan2(x2,y2)
      |         ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 3948 KB Output is correct
2 Correct 11 ms 3052 KB Output is correct
3 Correct 30 ms 3820 KB Output is correct
4 Correct 23 ms 3436 KB Output is correct
5 Correct 44 ms 3968 KB Output is correct
6 Correct 25 ms 3564 KB Output is correct
7 Correct 7 ms 3052 KB Output is correct
8 Correct 25 ms 3564 KB Output is correct
9 Correct 52 ms 4332 KB Output is correct
10 Correct 34 ms 3816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 3 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 2 ms 2668 KB Output is correct
12 Correct 2 ms 2668 KB Output is correct
13 Correct 3 ms 2668 KB Output is correct
14 Correct 3 ms 2668 KB Output is correct
15 Correct 2 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 3 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
9 Correct 2 ms 2668 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 2 ms 2668 KB Output is correct
12 Correct 2 ms 2668 KB Output is correct
13 Correct 3 ms 2668 KB Output is correct
14 Correct 3 ms 2668 KB Output is correct
15 Correct 2 ms 2668 KB Output is correct
16 Correct 15 ms 3072 KB Output is correct
17 Correct 37 ms 3820 KB Output is correct
18 Correct 45 ms 3820 KB Output is correct
19 Correct 85 ms 3820 KB Output is correct
20 Correct 94 ms 3820 KB Output is correct
21 Correct 34 ms 3820 KB Output is correct
22 Correct 3 ms 2668 KB Output is correct
23 Correct 25 ms 3200 KB Output is correct
24 Correct 43 ms 3820 KB Output is correct
25 Correct 7 ms 2796 KB Output is correct
26 Correct 27 ms 3436 KB Output is correct
27 Correct 35 ms 3692 KB Output is correct
28 Correct 43 ms 3820 KB Output is correct
29 Correct 16 ms 3180 KB Output is correct
30 Correct 4 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 3948 KB Output is correct
2 Correct 11 ms 3052 KB Output is correct
3 Correct 30 ms 3820 KB Output is correct
4 Correct 23 ms 3436 KB Output is correct
5 Correct 44 ms 3968 KB Output is correct
6 Correct 25 ms 3564 KB Output is correct
7 Correct 7 ms 3052 KB Output is correct
8 Correct 25 ms 3564 KB Output is correct
9 Correct 52 ms 4332 KB Output is correct
10 Correct 34 ms 3816 KB Output is correct
11 Correct 2 ms 2668 KB Output is correct
12 Correct 2 ms 2668 KB Output is correct
13 Correct 2 ms 2668 KB Output is correct
14 Correct 3 ms 2668 KB Output is correct
15 Correct 2 ms 2668 KB Output is correct
16 Correct 2 ms 2668 KB Output is correct
17 Correct 2 ms 2668 KB Output is correct
18 Correct 2 ms 2668 KB Output is correct
19 Correct 2 ms 2668 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 2 ms 2668 KB Output is correct
22 Correct 2 ms 2668 KB Output is correct
23 Correct 3 ms 2668 KB Output is correct
24 Correct 3 ms 2668 KB Output is correct
25 Correct 2 ms 2668 KB Output is correct
26 Correct 15 ms 3072 KB Output is correct
27 Correct 37 ms 3820 KB Output is correct
28 Correct 45 ms 3820 KB Output is correct
29 Correct 85 ms 3820 KB Output is correct
30 Correct 94 ms 3820 KB Output is correct
31 Correct 34 ms 3820 KB Output is correct
32 Correct 3 ms 2668 KB Output is correct
33 Correct 25 ms 3200 KB Output is correct
34 Correct 43 ms 3820 KB Output is correct
35 Correct 7 ms 2796 KB Output is correct
36 Correct 27 ms 3436 KB Output is correct
37 Correct 35 ms 3692 KB Output is correct
38 Correct 43 ms 3820 KB Output is correct
39 Correct 16 ms 3180 KB Output is correct
40 Correct 4 ms 2668 KB Output is correct
41 Correct 213 ms 4700 KB Output is correct
42 Correct 82 ms 4844 KB Output is correct
43 Correct 128 ms 4588 KB Output is correct
44 Correct 76 ms 4716 KB Output is correct
45 Correct 70 ms 4972 KB Output is correct
46 Correct 228 ms 4856 KB Output is correct
47 Correct 59 ms 4716 KB Output is correct
48 Correct 109 ms 4844 KB Output is correct
49 Correct 69 ms 4716 KB Output is correct
50 Correct 887 ms 4716 KB Output is correct
51 Correct 887 ms 4844 KB Output is correct
52 Correct 877 ms 4716 KB Output is correct
53 Correct 878 ms 4844 KB Output is correct
54 Correct 860 ms 4716 KB Output is correct
55 Correct 903 ms 4972 KB Output is correct
56 Correct 853 ms 4844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB Output is correct
2 Correct 2 ms 2668 KB Output is correct
3 Correct 2 ms 2668 KB Output is correct
4 Correct 2 ms 2668 KB Output is correct
5 Correct 2 ms 2668 KB Output is correct
6 Correct 2 ms 2668 KB Output is correct
7 Correct 2 ms 2668 KB Output is correct
8 Correct 2 ms 2668 KB Output is correct
9 Correct 40 ms 3948 KB Output is correct
10 Correct 11 ms 3052 KB Output is correct
11 Correct 30 ms 3820 KB Output is correct
12 Correct 23 ms 3436 KB Output is correct
13 Correct 44 ms 3968 KB Output is correct
14 Correct 25 ms 3564 KB Output is correct
15 Correct 7 ms 3052 KB Output is correct
16 Correct 25 ms 3564 KB Output is correct
17 Correct 52 ms 4332 KB Output is correct
18 Correct 34 ms 3816 KB Output is correct
19 Correct 2 ms 2668 KB Output is correct
20 Correct 2 ms 2668 KB Output is correct
21 Correct 2 ms 2668 KB Output is correct
22 Correct 3 ms 2668 KB Output is correct
23 Correct 2 ms 2668 KB Output is correct
24 Correct 2 ms 2668 KB Output is correct
25 Correct 2 ms 2668 KB Output is correct
26 Correct 2 ms 2668 KB Output is correct
27 Correct 2 ms 2668 KB Output is correct
28 Correct 2 ms 2688 KB Output is correct
29 Correct 2 ms 2668 KB Output is correct
30 Correct 2 ms 2668 KB Output is correct
31 Correct 3 ms 2668 KB Output is correct
32 Correct 3 ms 2668 KB Output is correct
33 Correct 2 ms 2668 KB Output is correct
34 Correct 15 ms 3072 KB Output is correct
35 Correct 37 ms 3820 KB Output is correct
36 Correct 45 ms 3820 KB Output is correct
37 Correct 85 ms 3820 KB Output is correct
38 Correct 94 ms 3820 KB Output is correct
39 Correct 34 ms 3820 KB Output is correct
40 Correct 3 ms 2668 KB Output is correct
41 Correct 25 ms 3200 KB Output is correct
42 Correct 43 ms 3820 KB Output is correct
43 Correct 7 ms 2796 KB Output is correct
44 Correct 27 ms 3436 KB Output is correct
45 Correct 35 ms 3692 KB Output is correct
46 Correct 43 ms 3820 KB Output is correct
47 Correct 16 ms 3180 KB Output is correct
48 Correct 4 ms 2668 KB Output is correct
49 Correct 213 ms 4700 KB Output is correct
50 Correct 82 ms 4844 KB Output is correct
51 Correct 128 ms 4588 KB Output is correct
52 Correct 76 ms 4716 KB Output is correct
53 Correct 70 ms 4972 KB Output is correct
54 Correct 228 ms 4856 KB Output is correct
55 Correct 59 ms 4716 KB Output is correct
56 Correct 109 ms 4844 KB Output is correct
57 Correct 69 ms 4716 KB Output is correct
58 Correct 887 ms 4716 KB Output is correct
59 Correct 887 ms 4844 KB Output is correct
60 Correct 877 ms 4716 KB Output is correct
61 Correct 878 ms 4844 KB Output is correct
62 Correct 860 ms 4716 KB Output is correct
63 Correct 903 ms 4972 KB Output is correct
64 Correct 853 ms 4844 KB Output is correct
65 Correct 2 ms 2668 KB Output is correct
66 Incorrect 2 ms 2668 KB Output isn't correct
67 Halted 0 ms 0 KB -