답안 #58131

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
58131 2018-07-16T23:54:25 Z Benq Chessboard (IZhO18_chessboard) C++14
100 / 100
970 ms 87968 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

ll N,K,ans;
vector<pair<pi,pi>> v;

ll solve(int x, int y, int len) {
    int X = x%(2*len), Y = y%(2*len);
    // suppose bottom left square is black 
    ll z = (x/(2*len))*len;
    z += min(X,len);
    
    ll res = (ll)(y/(2*len))*len*x;
    res += min(Y,len)*z;
    res += max(Y-len,0)*(x-z);
    return res;
}

ll correct(pair<pi,pi> a, int len) {
    return solve(a.f.s,a.s.s,len)-solve(a.f.f-1,a.s.s,len)-solve(a.f.s,a.s.f-1,len)+solve(a.f.f-1,a.s.f-1,len);
}

ll area(pair<pi,pi> a) {
    return (ll)(a.f.s-a.f.f+1)*(a.s.s-a.s.f+1);
}

ll solve(int len) {
    ll ans = N*N-correct({{1,N},{1,N}},len);
    for (auto a: v) {
        ll x = correct(a,len);
        ans -= (area(a)-x);
        ans += x;
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> K;
    F0R(i,K) {
        pair<pi,pi> t; cin >> t.f.f >> t.s.f >> t.f.s >> t.s.s;
        v.pb(t);
    }
    FOR(i,1,N) if (N % i == 0) {
        ll t = solve(i);
        t = max(t,N*N-t);
        ans = max(ans,t);
    }
    cout << N*N-ans;
}

/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( ) 
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 3 ms 432 KB Output is correct
4 Correct 3 ms 432 KB Output is correct
5 Correct 3 ms 508 KB Output is correct
6 Correct 2 ms 508 KB Output is correct
7 Correct 2 ms 636 KB Output is correct
8 Correct 3 ms 636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 1788 KB Output is correct
2 Correct 10 ms 1788 KB Output is correct
3 Correct 28 ms 1788 KB Output is correct
4 Correct 28 ms 2528 KB Output is correct
5 Correct 31 ms 3788 KB Output is correct
6 Correct 19 ms 4892 KB Output is correct
7 Correct 7 ms 4892 KB Output is correct
8 Correct 31 ms 5980 KB Output is correct
9 Correct 55 ms 8512 KB Output is correct
10 Correct 38 ms 8956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8956 KB Output is correct
2 Correct 2 ms 8956 KB Output is correct
3 Correct 2 ms 8956 KB Output is correct
4 Correct 3 ms 8956 KB Output is correct
5 Correct 3 ms 8956 KB Output is correct
6 Correct 2 ms 8956 KB Output is correct
7 Correct 2 ms 8956 KB Output is correct
8 Correct 2 ms 8956 KB Output is correct
9 Correct 3 ms 8956 KB Output is correct
10 Correct 2 ms 8956 KB Output is correct
11 Correct 3 ms 8956 KB Output is correct
12 Correct 2 ms 8956 KB Output is correct
13 Correct 3 ms 8956 KB Output is correct
14 Correct 3 ms 8956 KB Output is correct
15 Correct 3 ms 8956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8956 KB Output is correct
2 Correct 2 ms 8956 KB Output is correct
3 Correct 2 ms 8956 KB Output is correct
4 Correct 3 ms 8956 KB Output is correct
5 Correct 3 ms 8956 KB Output is correct
6 Correct 2 ms 8956 KB Output is correct
7 Correct 2 ms 8956 KB Output is correct
8 Correct 2 ms 8956 KB Output is correct
9 Correct 3 ms 8956 KB Output is correct
10 Correct 2 ms 8956 KB Output is correct
11 Correct 3 ms 8956 KB Output is correct
12 Correct 2 ms 8956 KB Output is correct
13 Correct 3 ms 8956 KB Output is correct
14 Correct 3 ms 8956 KB Output is correct
15 Correct 3 ms 8956 KB Output is correct
16 Correct 18 ms 8956 KB Output is correct
17 Correct 45 ms 10120 KB Output is correct
18 Correct 58 ms 10160 KB Output is correct
19 Correct 150 ms 10160 KB Output is correct
20 Correct 303 ms 10160 KB Output is correct
21 Correct 45 ms 10160 KB Output is correct
22 Correct 5 ms 10160 KB Output is correct
23 Correct 44 ms 10160 KB Output is correct
24 Correct 49 ms 10160 KB Output is correct
25 Correct 9 ms 10160 KB Output is correct
26 Correct 36 ms 10160 KB Output is correct
27 Correct 74 ms 10160 KB Output is correct
28 Correct 61 ms 10160 KB Output is correct
29 Correct 15 ms 10160 KB Output is correct
30 Correct 5 ms 10160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 1788 KB Output is correct
2 Correct 10 ms 1788 KB Output is correct
3 Correct 28 ms 1788 KB Output is correct
4 Correct 28 ms 2528 KB Output is correct
5 Correct 31 ms 3788 KB Output is correct
6 Correct 19 ms 4892 KB Output is correct
7 Correct 7 ms 4892 KB Output is correct
8 Correct 31 ms 5980 KB Output is correct
9 Correct 55 ms 8512 KB Output is correct
10 Correct 38 ms 8956 KB Output is correct
11 Correct 3 ms 8956 KB Output is correct
12 Correct 2 ms 8956 KB Output is correct
13 Correct 2 ms 8956 KB Output is correct
14 Correct 3 ms 8956 KB Output is correct
15 Correct 3 ms 8956 KB Output is correct
16 Correct 2 ms 8956 KB Output is correct
17 Correct 2 ms 8956 KB Output is correct
18 Correct 2 ms 8956 KB Output is correct
19 Correct 3 ms 8956 KB Output is correct
20 Correct 2 ms 8956 KB Output is correct
21 Correct 3 ms 8956 KB Output is correct
22 Correct 2 ms 8956 KB Output is correct
23 Correct 3 ms 8956 KB Output is correct
24 Correct 3 ms 8956 KB Output is correct
25 Correct 3 ms 8956 KB Output is correct
26 Correct 18 ms 8956 KB Output is correct
27 Correct 45 ms 10120 KB Output is correct
28 Correct 58 ms 10160 KB Output is correct
29 Correct 150 ms 10160 KB Output is correct
30 Correct 303 ms 10160 KB Output is correct
31 Correct 45 ms 10160 KB Output is correct
32 Correct 5 ms 10160 KB Output is correct
33 Correct 44 ms 10160 KB Output is correct
34 Correct 49 ms 10160 KB Output is correct
35 Correct 9 ms 10160 KB Output is correct
36 Correct 36 ms 10160 KB Output is correct
37 Correct 74 ms 10160 KB Output is correct
38 Correct 61 ms 10160 KB Output is correct
39 Correct 15 ms 10160 KB Output is correct
40 Correct 5 ms 10160 KB Output is correct
41 Correct 137 ms 11936 KB Output is correct
42 Correct 73 ms 13924 KB Output is correct
43 Correct 86 ms 16180 KB Output is correct
44 Correct 54 ms 18172 KB Output is correct
45 Correct 50 ms 20416 KB Output is correct
46 Correct 191 ms 22720 KB Output is correct
47 Correct 62 ms 25092 KB Output is correct
48 Correct 73 ms 27184 KB Output is correct
49 Correct 52 ms 29088 KB Output is correct
50 Correct 611 ms 31060 KB Output is correct
51 Correct 843 ms 33316 KB Output is correct
52 Correct 644 ms 35648 KB Output is correct
53 Correct 699 ms 37792 KB Output is correct
54 Correct 718 ms 40108 KB Output is correct
55 Correct 666 ms 42352 KB Output is correct
56 Correct 590 ms 44632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 3 ms 432 KB Output is correct
4 Correct 3 ms 432 KB Output is correct
5 Correct 3 ms 508 KB Output is correct
6 Correct 2 ms 508 KB Output is correct
7 Correct 2 ms 636 KB Output is correct
8 Correct 3 ms 636 KB Output is correct
9 Correct 38 ms 1788 KB Output is correct
10 Correct 10 ms 1788 KB Output is correct
11 Correct 28 ms 1788 KB Output is correct
12 Correct 28 ms 2528 KB Output is correct
13 Correct 31 ms 3788 KB Output is correct
14 Correct 19 ms 4892 KB Output is correct
15 Correct 7 ms 4892 KB Output is correct
16 Correct 31 ms 5980 KB Output is correct
17 Correct 55 ms 8512 KB Output is correct
18 Correct 38 ms 8956 KB Output is correct
19 Correct 3 ms 8956 KB Output is correct
20 Correct 2 ms 8956 KB Output is correct
21 Correct 2 ms 8956 KB Output is correct
22 Correct 3 ms 8956 KB Output is correct
23 Correct 3 ms 8956 KB Output is correct
24 Correct 2 ms 8956 KB Output is correct
25 Correct 2 ms 8956 KB Output is correct
26 Correct 2 ms 8956 KB Output is correct
27 Correct 3 ms 8956 KB Output is correct
28 Correct 2 ms 8956 KB Output is correct
29 Correct 3 ms 8956 KB Output is correct
30 Correct 2 ms 8956 KB Output is correct
31 Correct 3 ms 8956 KB Output is correct
32 Correct 3 ms 8956 KB Output is correct
33 Correct 3 ms 8956 KB Output is correct
34 Correct 18 ms 8956 KB Output is correct
35 Correct 45 ms 10120 KB Output is correct
36 Correct 58 ms 10160 KB Output is correct
37 Correct 150 ms 10160 KB Output is correct
38 Correct 303 ms 10160 KB Output is correct
39 Correct 45 ms 10160 KB Output is correct
40 Correct 5 ms 10160 KB Output is correct
41 Correct 44 ms 10160 KB Output is correct
42 Correct 49 ms 10160 KB Output is correct
43 Correct 9 ms 10160 KB Output is correct
44 Correct 36 ms 10160 KB Output is correct
45 Correct 74 ms 10160 KB Output is correct
46 Correct 61 ms 10160 KB Output is correct
47 Correct 15 ms 10160 KB Output is correct
48 Correct 5 ms 10160 KB Output is correct
49 Correct 137 ms 11936 KB Output is correct
50 Correct 73 ms 13924 KB Output is correct
51 Correct 86 ms 16180 KB Output is correct
52 Correct 54 ms 18172 KB Output is correct
53 Correct 50 ms 20416 KB Output is correct
54 Correct 191 ms 22720 KB Output is correct
55 Correct 62 ms 25092 KB Output is correct
56 Correct 73 ms 27184 KB Output is correct
57 Correct 52 ms 29088 KB Output is correct
58 Correct 611 ms 31060 KB Output is correct
59 Correct 843 ms 33316 KB Output is correct
60 Correct 644 ms 35648 KB Output is correct
61 Correct 699 ms 37792 KB Output is correct
62 Correct 718 ms 40108 KB Output is correct
63 Correct 666 ms 42352 KB Output is correct
64 Correct 590 ms 44632 KB Output is correct
65 Correct 3 ms 44632 KB Output is correct
66 Correct 3 ms 44632 KB Output is correct
67 Correct 675 ms 46740 KB Output is correct
68 Correct 741 ms 49068 KB Output is correct
69 Correct 711 ms 51300 KB Output is correct
70 Correct 682 ms 53284 KB Output is correct
71 Correct 625 ms 55560 KB Output is correct
72 Correct 636 ms 57572 KB Output is correct
73 Correct 568 ms 59692 KB Output is correct
74 Correct 702 ms 61744 KB Output is correct
75 Correct 675 ms 63916 KB Output is correct
76 Correct 747 ms 66056 KB Output is correct
77 Correct 122 ms 68324 KB Output is correct
78 Correct 70 ms 70584 KB Output is correct
79 Correct 97 ms 72784 KB Output is correct
80 Correct 114 ms 74800 KB Output is correct
81 Correct 138 ms 76968 KB Output is correct
82 Correct 84 ms 78928 KB Output is correct
83 Correct 67 ms 81140 KB Output is correct
84 Correct 422 ms 83120 KB Output is correct
85 Correct 688 ms 85520 KB Output is correct
86 Correct 5 ms 85520 KB Output is correct
87 Correct 5 ms 85520 KB Output is correct
88 Correct 970 ms 87968 KB Output is correct
89 Correct 128 ms 87968 KB Output is correct
90 Correct 4 ms 87968 KB Output is correct