Submission #44065

# Submission time Handle Problem Language Result Execution time Memory
44065 2018-03-29T13:37:11 Z Nordway Chessboard (IZhO18_chessboard) C++14
16 / 100
126 ms 2132 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 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;

int x1[N], y[N], x2[N], y2[N];
ll ans = LLONG_MAX;

void Subtask1(int n, int i){
    ll d = n / i;
    ans = min(ans, (d % 2 == 0) ? (d / 2) * d * i * i : (d / 2 + 1) * (d / 2) * 2 * i * i);
}
void Subtask2345(int n, int i, int k){
    ll d = n / i;
    ll a = 0, b = 0;
    if(d % 2 == 0){
        for(int j = 1; j <= k; j++){
            if(((x1[j] / i) - (x1[j] % i == 0)) % 2 == 0){
                if(((y[j] / i) - (y[j] % i == 0)) % 2 == 1)b++;
                else a++;
            }
            else{
                if(((y[j] / i) - (y[j] % i == 0)) % 2 == 1)a++;
                else b++;
            }
        }
        //cout << (d / 2) * d * i * i - a + b << endl;
        ans = min(ans, (d / 2) * d * i * i - a + b);
    }
    else{
        for(int j = 1; j <= k; j++){
            if(((x1[j] / i) - (x1[j] % i == 0)) % 2 == 0){
                if(((y[j] / i) - (y[j] % i == 0)) % 2 == 1)a++;
                else b++;
            }
            else{
                if(((y[j] / i) - (y[j] % i == 0)) % 2 == 1)b++;
                else a++;
            }
        }
        ll c = (d / 2) * (d / 2 + 1) * 2 * i * i - a + b;
        ll e = ((d / 2 + 1) * (d / 2 + 1) + (d / 2) * (d / 2)) * i * i - b + a;
        //cout << min(c, e) << endl;
        ans = min(ans, min(c, e));
    }
}

int main(){
    int n, k;
    cin >> n >> k;
    for(int i = 1; i <= k; i++){
        cin >> x1[i] >> y[i] >> x2[i] >> y2[i];
    }
    for(int i = 1; i <= sqrt(n); i++){
        if(n % i == 0){
            if(k == 0){
                Subtask1(n, i);
                if(i != 1)Subtask1(n, n / i);
            }
            else{
                Subtask2345(n, i, k);
                if(i != 1)Subtask2345(n, n / i, k);
            }
        }
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 104 ms 1512 KB Output is correct
2 Correct 23 ms 1512 KB Output is correct
3 Correct 56 ms 1512 KB Output is correct
4 Correct 56 ms 1512 KB Output is correct
5 Correct 80 ms 1512 KB Output is correct
6 Correct 50 ms 1512 KB Output is correct
7 Correct 13 ms 1512 KB Output is correct
8 Correct 51 ms 1512 KB Output is correct
9 Correct 126 ms 2132 KB Output is correct
10 Correct 80 ms 2132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2132 KB Output is correct
2 Correct 2 ms 2132 KB Output is correct
3 Correct 2 ms 2132 KB Output is correct
4 Correct 4 ms 2132 KB Output is correct
5 Correct 3 ms 2132 KB Output is correct
6 Incorrect 2 ms 2132 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2132 KB Output is correct
2 Correct 2 ms 2132 KB Output is correct
3 Correct 2 ms 2132 KB Output is correct
4 Correct 4 ms 2132 KB Output is correct
5 Correct 3 ms 2132 KB Output is correct
6 Incorrect 2 ms 2132 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 104 ms 1512 KB Output is correct
2 Correct 23 ms 1512 KB Output is correct
3 Correct 56 ms 1512 KB Output is correct
4 Correct 56 ms 1512 KB Output is correct
5 Correct 80 ms 1512 KB Output is correct
6 Correct 50 ms 1512 KB Output is correct
7 Correct 13 ms 1512 KB Output is correct
8 Correct 51 ms 1512 KB Output is correct
9 Correct 126 ms 2132 KB Output is correct
10 Correct 80 ms 2132 KB Output is correct
11 Correct 2 ms 2132 KB Output is correct
12 Correct 2 ms 2132 KB Output is correct
13 Correct 2 ms 2132 KB Output is correct
14 Correct 4 ms 2132 KB Output is correct
15 Correct 3 ms 2132 KB Output is correct
16 Incorrect 2 ms 2132 KB Output isn't correct
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 2 ms 640 KB Output is correct
5 Correct 2 ms 640 KB Output is correct
6 Correct 2 ms 640 KB Output is correct
7 Correct 2 ms 640 KB Output is correct
8 Correct 2 ms 640 KB Output is correct
9 Correct 104 ms 1512 KB Output is correct
10 Correct 23 ms 1512 KB Output is correct
11 Correct 56 ms 1512 KB Output is correct
12 Correct 56 ms 1512 KB Output is correct
13 Correct 80 ms 1512 KB Output is correct
14 Correct 50 ms 1512 KB Output is correct
15 Correct 13 ms 1512 KB Output is correct
16 Correct 51 ms 1512 KB Output is correct
17 Correct 126 ms 2132 KB Output is correct
18 Correct 80 ms 2132 KB Output is correct
19 Correct 2 ms 2132 KB Output is correct
20 Correct 2 ms 2132 KB Output is correct
21 Correct 2 ms 2132 KB Output is correct
22 Correct 4 ms 2132 KB Output is correct
23 Correct 3 ms 2132 KB Output is correct
24 Incorrect 2 ms 2132 KB Output isn't correct
25 Halted 0 ms 0 KB -