Submission #500352

# Submission time Handle Problem Language Result Execution time Memory
500352 2021-12-30T19:04:58 Z dostigator Chessboard (IZhO18_chessboard) C++14
39 / 100
188 ms 11888 KB
// author lox:(
#pragma GCC optimize("O3")
#pragma GCC target("popcnt")
#include <bits/stdc++.h>
using namespace std;
#define IZhO_SILVER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define popcnt __builtin_popcount
#define all(a) a.begin(),a.end()
#define low_b lower_bound
#define up_b upper_bound
#define vii vector<pair<ll,ll>>
#define vll vector<pair<ll,ll>>
#define pii pair<ll,ll>
#define mii map<ll,ll>
#define pll pair<ll,ll>
#define mll map<ll,ll>
#define vi vector<ll>
#define vl vector<ll>
#define pb push_back
#define endl '\n'
#define Y second
#define X first
typedef long double ld;
typedef long long ll;
const long long dx[4]={1,-1,0,0},dy[4]={0,0,1,-1},col=107,N=1e6+777;
const ll mod=1e9+7,inf=1e18;
void fre_open(){freopen("file.in","r",stdin);freopen("file.out","w",stdout);}
ll binpow(ll n,ll k){if(k<0)return 0ll;if(k==0)return 1ll;if(k%2)return (binpow(n,k-1)*n)%mod;ll kk=binpow(n,k/2)%mod;return (kk*kk)%mod;}
ll a[2001][2001];
ll n,k;
void solve(){
    cin>>n>>k;
    if(k==0){
        ll x=n*n/2;
        for(ll i=n/2; i>=1; --i)if(n%i==0)x=min(x,i*i*((n/i)*(n/i)/2));
        cout<<x;
        return;
    }
    if(n<=1000){
        for(ll i=1; i<=k; ++i){
            ll x,y,tox,toy;
            cin>>x>>y>>tox>>toy;
            a[x][y]=1;
        }
        ll ans=mod-10;
        for(ll d=1; d*d<=n; ++d){
            if(n%d!=0) continue;
            ll res=0,res2=0;
            for(ll i=1; i<=n; ++i){
                for(ll j=1; j<=n; ++j){
                    ll x=(i+(d-1))/d;
                    ll y=(j+(d-1))/d;
                    if((x+y)%2 && a[i][j]) ++res2;
                    if((x+y)%2 && !a[i][j]) ++res;
                    if(!((x+y)%2) && a[i][j]) ++res;
                    if(!((x+y)%2) && !a[i][j]) ++res2;
                }
            }
            ans=min({ans,res,res2});
            //cout<<d<<' '<<res<<' '<<res2<<endl;
            ll f=n/d;
            res=0,res2=0;
            for(ll i=1; i<=n; ++i){
                for(ll j=1; j<=n; ++j){
                    ll x=(i+(f-1))/f;
                    ll y=(j+(f-1))/f;
                    if((x+y)%2 && a[i][j]) ++res2;
                    if((x+y)%2 && !a[i][j]) ++res;
                    if(!((x+y)%2) && a[i][j]) ++res;
                    if(!((x+y)%2) && !a[i][j]) ++res2;
                }
            }
            if(d==1){
                ans=min(ans,max(res,res2));
                continue;
            }
            ans=min({ans,res,res2});
            //cout<<d<<' '<<res<<' '<<res2<<endl;
        }
        cout<<ans<<endl;
        return;
    }
    ll x=n*n/2;
    ll x2=x+1;
    for(ll c=0, i1,i2,j1,j2;c<k; ++c){
        cin>>i1>>j1>>i2>>j2;
        for(ll i=i1; i<=i2; ++i)
            for(ll j=j1; j<=j2; ++j)
            {
                if(i%2==j%2) x++,x2--;
                if(i%2!=j%2) x2++,x--;
            }
        cout<<min(x,x2);
    }
}
/*
6 8
3 3 3 3
1 2 1 2
3 4 3 4
5 5 5 5
4 3 4 3
4 4 4 4
2 1 2 1
3 6 3 6*/
int main() {
    //fre_open();
    IZhO_SILVER;
    ll tt=1;
    //cin>>tt;
    while(tt--) solve();
}

Compilation message

chessboard.cpp: In function 'void fre_open()':
chessboard.cpp:27:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 | void fre_open(){freopen("file.in","r",stdin);freopen("file.out","w",stdout);}
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
chessboard.cpp:27:53: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 | void fre_open(){freopen("file.in","r",stdin);freopen("file.out","w",stdout);}
      |                                              ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 900 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 0 ms 460 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 588 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 1 ms 588 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 0 ms 460 KB Output is correct
11 Correct 1 ms 588 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 588 KB Output is correct
14 Correct 1 ms 588 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 30 ms 10700 KB Output is correct
17 Correct 37 ms 11852 KB Output is correct
18 Correct 53 ms 11876 KB Output is correct
19 Correct 165 ms 11216 KB Output is correct
20 Correct 188 ms 11340 KB Output is correct
21 Correct 38 ms 11852 KB Output is correct
22 Correct 85 ms 1996 KB Output is correct
23 Correct 55 ms 11152 KB Output is correct
24 Correct 52 ms 11888 KB Output is correct
25 Correct 52 ms 9804 KB Output is correct
26 Correct 41 ms 11024 KB Output is correct
27 Correct 51 ms 11224 KB Output is correct
28 Correct 49 ms 11196 KB Output is correct
29 Correct 23 ms 11220 KB Output is correct
30 Correct 24 ms 6772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 900 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Incorrect 27 ms 900 KB Output isn't correct
10 Halted 0 ms 0 KB -