Submission #44067

# Submission time Handle Problem Language Result Execution time Memory
44067 2018-03-29T14:05:19 Z Nordway Chessboard (IZhO18_chessboard) C++14
16 / 100
142 ms 2116 KB
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string.h>
#include <stdio.h>
#include <assert.h>

#define x first
#define y second
#define pb push_back
#define mp make_pair
#define low_b lower_bound
#define up_b upper_bound
#define all(v) v.begin(), v.end()

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef set<int> si;

const int N = 1e+5 + 5;

pair < pair < int, int >, pair < int, int > > a[N];
ll ans = LLONG_MAX;
int n, k;
void solve(int v){
    ll d = n / v;
    if(d % 2 == 0){
        ll res = (d / 2) * d * v * v;
        for(int i = 1; i <= k; i++){
            int x = a[i].x.x;
            int y = a[i].x.y;
            if(((x / v) - (x % v == 0)) % 2 == 0){
                if(((y / v) - (y % v == 0)) % 2 == 1)res++;
                else res--;
            }
            else{
                if(((y / v) - (y  % v == 0)) % 2 == 1)res--;
                else res++;
            }
        }
            ans = min(ans, res);
    }
    else{
        ll l = ((d / 2) * (d / 2) + (d / 2 + 1) * (d / 2 + 1)) * v * v;
        ll r = ((d / 2) * (d / 2 + 1) + (d / 2 + 1) * (d / 2)) * v * v;
        for(int i = 1; i <= k; i++){
            int x = a[i].x.x;
            int y = a[i].x.y;
            if(((x / v) - (x % v == 0)) % 2 == 0){
                if(((y / v) - (y % v == 0)) % 2 == 1)r--, l++;
                else l--, r++;
            }
            else{
                if(((y / v) - (y  % v == 0)) % 2 == 1)r++, l--;
                else r--, l++;
            }
        }
        ans = min(ans, min(l, r));
    }
}

int main(){
    cin >> n >> k;
    for(int i = 1; i <= k; i++){
        cin >> a[i].x.x >> a[i].x.y >> a[i].y.x >> a[i].y.y;
    }
    solve(1);
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0){
            solve(i);
            solve(n / i);
        }
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 484 KB Output is correct
7 Correct 2 ms 520 KB Output is correct
8 Correct 2 ms 532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 1440 KB Output is correct
2 Correct 25 ms 1440 KB Output is correct
3 Correct 73 ms 1440 KB Output is correct
4 Correct 58 ms 1440 KB Output is correct
5 Correct 81 ms 1440 KB Output is correct
6 Correct 54 ms 1440 KB Output is correct
7 Correct 12 ms 1440 KB Output is correct
8 Correct 54 ms 1440 KB Output is correct
9 Correct 142 ms 2116 KB Output is correct
10 Correct 73 ms 2116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2116 KB Output is correct
2 Correct 2 ms 2116 KB Output is correct
3 Correct 2 ms 2116 KB Output is correct
4 Correct 4 ms 2116 KB Output is correct
5 Correct 3 ms 2116 KB Output is correct
6 Incorrect 2 ms 2116 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2116 KB Output is correct
2 Correct 2 ms 2116 KB Output is correct
3 Correct 2 ms 2116 KB Output is correct
4 Correct 4 ms 2116 KB Output is correct
5 Correct 3 ms 2116 KB Output is correct
6 Incorrect 2 ms 2116 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 93 ms 1440 KB Output is correct
2 Correct 25 ms 1440 KB Output is correct
3 Correct 73 ms 1440 KB Output is correct
4 Correct 58 ms 1440 KB Output is correct
5 Correct 81 ms 1440 KB Output is correct
6 Correct 54 ms 1440 KB Output is correct
7 Correct 12 ms 1440 KB Output is correct
8 Correct 54 ms 1440 KB Output is correct
9 Correct 142 ms 2116 KB Output is correct
10 Correct 73 ms 2116 KB Output is correct
11 Correct 2 ms 2116 KB Output is correct
12 Correct 2 ms 2116 KB Output is correct
13 Correct 2 ms 2116 KB Output is correct
14 Correct 4 ms 2116 KB Output is correct
15 Correct 3 ms 2116 KB Output is correct
16 Incorrect 2 ms 2116 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 2 ms 484 KB Output is correct
4 Correct 2 ms 484 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 484 KB Output is correct
7 Correct 2 ms 520 KB Output is correct
8 Correct 2 ms 532 KB Output is correct
9 Correct 93 ms 1440 KB Output is correct
10 Correct 25 ms 1440 KB Output is correct
11 Correct 73 ms 1440 KB Output is correct
12 Correct 58 ms 1440 KB Output is correct
13 Correct 81 ms 1440 KB Output is correct
14 Correct 54 ms 1440 KB Output is correct
15 Correct 12 ms 1440 KB Output is correct
16 Correct 54 ms 1440 KB Output is correct
17 Correct 142 ms 2116 KB Output is correct
18 Correct 73 ms 2116 KB Output is correct
19 Correct 2 ms 2116 KB Output is correct
20 Correct 2 ms 2116 KB Output is correct
21 Correct 2 ms 2116 KB Output is correct
22 Correct 4 ms 2116 KB Output is correct
23 Correct 3 ms 2116 KB Output is correct
24 Incorrect 2 ms 2116 KB Output isn't correct
25 Halted 0 ms 0 KB -