Submission #334324

# Submission time Handle Problem Language Result Execution time Memory
334324 2020-12-09T03:14:05 Z beksultan04 Chessboard (IZhO18_chessboard) C++14
39 / 100
76 ms 25464 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 q[2501][2501],dp[2501][2501],resh[N],ans[N],n;

int sum(int x1,int y1,int x2,int y2){
    ret dp[x2][y2]+dp[x1][y1]-dp[x1][y2]-dp[x2][y1];
}

int fun(int x){
    int i,j,ans=0,res=0,c=1;
    for (i=0;i<n;i+=x){
        if (c%2)
            for (j=0;j<n;j+=x*2){
                res += x*x-sum(i,j,i+x,j+x);
            }
        else {
            for (j=x;j<n;j+=x*2){
                res += x*x-sum(i,j,i+x,j+x);
            }

        }
        c++;
    }
    c=0;
    for (i=0;i<n;i+=x){
        if (c%2)
            for (j=0;j<n;j+=x*2){
                res += sum(i,j,i+x,j+x);
            }
        else {
            for (j=x;j<n;j+=x*2){
                res += sum(i,j,i+x,j+x);
            }

        }
        c++;
    }
    ret (res);

}
int fun1(int x){
    int i,j,ans=0,res=0,c=0;
    for (i=0;i<n;i+=x){
        if (c%2)
            for (j=0;j<n;j+=x*2){
                res += x*x-sum(i,j,i+x,j+x);
            }
        else {
            for (j=x;j<n;j+=x*2){
                res += x*x-sum(i,j,i+x,j+x);
            }

        }
        c++;
    }
    c=1;
    for (i=0;i<n;i+=x){
        if (c%2)
            for (j=0;j<n;j+=x*2){
                res += sum(i,j,i+x,j+x);
            }
        else {
            for (j=x;j<n;j+=x*2){
                res += sum(i,j,i+x,j+x);
            }

        }
        c++;
    }
    ret (res);

}

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

    while (k--){
        int x1,x2,y1,y2;
        scan2(x1,y1)
        scan2(x2,y2)
        q[x1][y1]++;
        q[x2+1][y2+1]++;
        q[x1][y2+1]--;
        q[x2+1][y1]--;
    }
    for (i=1;i<=n;++i){
        for (j=1;j<=n;++j){
            q[i][j]+=q[i-1][j]+q[i][j-1]-q[i-1][j-1];
        }
    }
    for (i=1;i<=n;++i){
        for (j=1;j<=n;++j){
            dp[i][j] = dp[i][j-1]+dp[i-1][j]-dp[i-1][j-1]+q[i][j];
        }
    }

    for (i=2;i*i<=n;++i){
        if (n%i==0){
            v.pb(i);
            if (i*i != n)v.pb(n/i);
        }
    }
    int ans=min(fun(1),fun1(1));
    for (i=0;i<v.size();++i){
        ans = min(ans,min(fun(v[i]),fun1(v[i])));
    }
    cout <<ans;

}


















Compilation message

chessboard.cpp: In function 'long long int fun(long long int)':
chessboard.cpp:23:13: warning: unused variable 'ans' [-Wunused-variable]
   23 |     int i,j,ans=0,res=0,c=1;
      |             ^~~
chessboard.cpp: In function 'long long int fun1(long long int)':
chessboard.cpp:55:13: warning: unused variable 'ans' [-Wunused-variable]
   55 |     int i,j,ans=0,res=0,c=0;
      |             ^~~
chessboard.cpp: At global scope:
chessboard.cpp:87:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   87 | main(){
      |      ^
chessboard.cpp: In function 'int main()':
chessboard.cpp:119: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]
  119 |     for (i=0;i<v.size();++i){
      |              ~^~~~~~~~~
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:90:5: note: in expansion of macro 'scan2'
   90 |     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:94:9: note: in expansion of macro 'scan2'
   94 |         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:95:9: note: in expansion of macro 'scan2'
   95 |         scan2(x2,y2)
      |         ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 1260 KB Output is correct
3 Correct 1 ms 1260 KB Output is correct
4 Correct 1 ms 1260 KB Output is correct
5 Correct 1 ms 1260 KB Output is correct
6 Correct 1 ms 1260 KB Output is correct
7 Correct 1 ms 1260 KB Output is correct
8 Correct 1 ms 1260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Correct 1 ms 876 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 1 ms 1152 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 2 ms 1132 KB Output is correct
8 Correct 1 ms 876 KB Output is correct
9 Correct 1 ms 1260 KB Output is correct
10 Correct 1 ms 1004 KB Output is correct
11 Correct 1 ms 876 KB Output is correct
12 Correct 1 ms 896 KB Output is correct
13 Correct 1 ms 1004 KB Output is correct
14 Correct 1 ms 1004 KB Output is correct
15 Correct 2 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1004 KB Output is correct
2 Correct 1 ms 876 KB Output is correct
3 Correct 1 ms 1132 KB Output is correct
4 Correct 1 ms 1132 KB Output is correct
5 Correct 1 ms 1152 KB Output is correct
6 Correct 1 ms 1004 KB Output is correct
7 Correct 2 ms 1132 KB Output is correct
8 Correct 1 ms 876 KB Output is correct
9 Correct 1 ms 1260 KB Output is correct
10 Correct 1 ms 1004 KB Output is correct
11 Correct 1 ms 876 KB Output is correct
12 Correct 1 ms 896 KB Output is correct
13 Correct 1 ms 1004 KB Output is correct
14 Correct 1 ms 1004 KB Output is correct
15 Correct 2 ms 748 KB Output is correct
16 Correct 37 ms 22636 KB Output is correct
17 Correct 74 ms 25344 KB Output is correct
18 Correct 74 ms 25464 KB Output is correct
19 Correct 70 ms 24032 KB Output is correct
20 Correct 76 ms 24172 KB Output is correct
21 Correct 64 ms 25196 KB Output is correct
22 Correct 27 ms 24044 KB Output is correct
23 Correct 46 ms 23660 KB Output is correct
24 Correct 71 ms 25324 KB Output is correct
25 Correct 28 ms 23020 KB Output is correct
26 Correct 53 ms 23276 KB Output is correct
27 Correct 64 ms 23788 KB Output is correct
28 Correct 71 ms 23912 KB Output is correct
29 Correct 40 ms 23404 KB Output is correct
30 Correct 35 ms 23404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 1260 KB Output is correct
3 Correct 1 ms 1260 KB Output is correct
4 Correct 1 ms 1260 KB Output is correct
5 Correct 1 ms 1260 KB Output is correct
6 Correct 1 ms 1260 KB Output is correct
7 Correct 1 ms 1260 KB Output is correct
8 Correct 1 ms 1260 KB Output is correct
9 Runtime error 6 ms 492 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Halted 0 ms 0 KB -