Submission #44039

# Submission time Handle Problem Language Result Execution time Memory
44039 2018-03-29T12:16:42 Z Nordway Chessboard (IZhO18_chessboard) C++14
8 / 100
98 ms 4120 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;

bool isprime(int v){
    for(int i = 2; i * i <= v; i++){
        if(v % i == 0)return false;
    }
    return true;
}

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 Subtask2(int n, int k){
    if(n == 2){
        if(k == 4)cout << 2;
        else if(k == 3)cout << 1;
        else {
            int a = 0, b = 0;
            for(int i = 1; i <= k; i++){
                if(x1[i] == y[i])a++;
                else b++;
            }
            if(a == 2 || b == 2)cout << 0;
            else cout << 1;
        }
    }
    else{
        ll a = 0, b = 0;
        for(int i = 1; i <= k; i++){
            if(x1[i] % 2 == 1){
                if(y[i] % 2 == 1)b++;
                else a++;
            }
            else {
                if(y[i] % 2 == 1)a++;
                else b++;
            }
        }
        ll c = (n / 2) * (n / 2 + 1) * 2 - a + b;
        ll d = ((n / 2) * (n / 2) + (n / 2 + 1) * (n / 2 + 1)) - b + a;
        cout << min(c, d);
    }
    exit(0);
}

int main(){
    int n, k;
    cin >> n >> k;
    for(int i = 1; i <= k; i++){
        cin >> x1[i] >> y[i] >> x2[i] >> y2[i];
    }
    if(k > 0 && isprime(n))Subtask2(n, k);
    for(int i = 1; i < n; i++){
        if(n % i == 0){
            if(k == 0){
                Subtask1(n, i);
            }
        }
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 480 KB Output is correct
3 Correct 2 ms 480 KB Output is correct
4 Correct 2 ms 480 KB Output is correct
5 Correct 2 ms 480 KB Output is correct
6 Correct 2 ms 572 KB Output is correct
7 Correct 2 ms 572 KB Output is correct
8 Correct 2 ms 572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 98 ms 3132 KB Output is correct
2 Correct 26 ms 3132 KB Output is correct
3 Incorrect 61 ms 4120 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 98 ms 3132 KB Output is correct
2 Correct 26 ms 3132 KB Output is correct
3 Incorrect 61 ms 4120 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 480 KB Output is correct
3 Correct 2 ms 480 KB Output is correct
4 Correct 2 ms 480 KB Output is correct
5 Correct 2 ms 480 KB Output is correct
6 Correct 2 ms 572 KB Output is correct
7 Correct 2 ms 572 KB Output is correct
8 Correct 2 ms 572 KB Output is correct
9 Correct 98 ms 3132 KB Output is correct
10 Correct 26 ms 3132 KB Output is correct
11 Incorrect 61 ms 4120 KB Output isn't correct
12 Halted 0 ms 0 KB -