# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
378667 |
2021-03-17T03:04:11 Z |
fhvirus |
Gift (IZhO18_nicegift) |
C++17 |
|
1 ms |
364 KB |
// Knapsack DP is harder than FFT.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
#define ff first
#define ss second
#define pb emplace_back
#define FOR(i,n) for(int i = 0; i < (n); ++i)
#define FOO(i,a,b) for(int i = (a); i <= (b); ++i)
#define AI(x) begin(x),end(x)
template<class I> bool chmax(I &a, I b){ return a < b ? (a = b, true) : false;}
template<class I> bool chmin(I &a, I b){ return a > b ? (a = b, true) : false;}
#ifdef OWO
#define debug(args...) LKJ("[ " + string(#args) + " ]", args)
void LKJ(){ cerr << endl;}
template<class I, class...T> void LKJ(I&&x, T&&...t){ cerr<<x<<", ", LKJ(t...);}
template<class I> void DE(I a, I b){ while(a < b) cerr << *a << " \n"[next(a) == b], ++a;}
#else
#define debug(...) 0
#define DE(...) 0
#endif
const int N = 1e5 + 1;
int n, k;
void findfac(int n, vector<int> &fac){
for(int i = 1; i * i <= n; ++i){
if(n % i != 0) continue;
fac.pb(i);
fac.pb(n / i);
}
sort(AI(fac));
fac.erase(unique(AI(fac)), end(fac));
if(fac.back() == n) fac.pop_back();
}
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> k;
vector<int> facs;
findfac(n, facs);
// ca : has top left corner
// cb : does not
vector<ll> ca(facs.size());
vector<ll> cb(facs.size());
FOR(i,facs.size()){
int f = facs[i];
ll nn = n / f;
ll bc = (nn * nn + 1) / 2;
ca[i] = bc * f * f;
cb[i] = 1ll * n * n - ca[i];
}
FOR(_,k){
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
--x1, --y1, --x2, --y2;
FOR(i, facs.size()){
int f = facs[i];
int lx = x2 - x1 + 1;
int ly = y2 - y1 + 1;
lx %= f * 2, ly %= f * 2;
if(lx == 0 or ly == 0) continue;
int dx = x1 % f;
int dy = y1 % f;
ll v;
if(dx + lx - 1 < f and dy + ly - 1 < f){
v = lx * ly;
} else if(dx + lx - 1 < f){
ll a = f - dy;
ll b = ly - a;
v = 1ll * lx * (a - b);
} else if(dy + ly - 1 < f){
ll a = f - dx;
ll b = lx - a;
v = 1ll * ly * (a - b);
} else {
ll a = f - dx;
ll b = lx - a;
ll c = f - dy;
ll d = ly - c;
v = (a - b) * (c - d);
}
int x = x1 / f;
int y = y1 / f;
if((x + y) & 1) cb[i] -= v, ca[i] += v;
else ca[i] -= v, cb[i] += v;
}
}
DE(AI(facs));
DE(AI(ca));
DE(AI(cb));
cout << min(
*min_element(AI(ca)),
*min_element(AI(cb))
);
return 0;
}
Compilation message
nicegift.cpp: In function 'int32_t main()':
nicegift.cpp:9:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | #define FOR(i,n) for(int i = 0; i < (n); ++i)
| ^
nicegift.cpp:48:2: note: in expansion of macro 'FOR'
48 | FOR(i,facs.size()){
| ^~~
nicegift.cpp:9:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | #define FOR(i,n) for(int i = 0; i < (n); ++i)
| ^
nicegift.cpp:60:3: note: in expansion of macro 'FOR'
60 | FOR(i, facs.size()){
| ^~~
nicegift.cpp:21:17: warning: statement has no effect [-Wunused-value]
21 | #define DE(...) 0
| ^
nicegift.cpp:97:2: note: in expansion of macro 'DE'
97 | DE(AI(facs));
| ^~
nicegift.cpp:21:17: warning: statement has no effect [-Wunused-value]
21 | #define DE(...) 0
| ^
nicegift.cpp:98:2: note: in expansion of macro 'DE'
98 | DE(AI(ca));
| ^~
nicegift.cpp:21:17: warning: statement has no effect [-Wunused-value]
21 | #define DE(...) 0
| ^
nicegift.cpp:99:2: note: in expansion of macro 'DE'
99 | DE(AI(cb));
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Unexpected end of file - int64 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Unexpected end of file - int64 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Unexpected end of file - int64 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Expected int32, but "470745450496" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Unexpected end of file - int64 expected |
2 |
Halted |
0 ms |
0 KB |
- |