Submission #334354

#TimeUsernameProblemLanguageResultExecution timeMemory
334354beksultan04Chessboard (IZhO18_chessboard)C++14
70 / 100
903 ms4972 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...