이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
IN THE NAME OF GOD
*/
#include <bits/stdc++.h>
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;
#define F first
#define S second
#define Mp make_pair
#define pb push_back
#define pf push_front
#define size(x) ((ll)x.size())
#define all(x) (x).begin(),(x).end()
#define kill(x) cout << x << '\n', exit(0);
#define fuck(x) cout << "(" << #x << " , " << x << ")" << endl
#define endl '\n'
const int N = 1e5+23, lg = 18;
ll Mod = 1e9+7; //998244353;
inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
ll ans = 1;
a=MOD(a, mod);
while (b) {
if (b & 1) ans = MOD(ans*a, mod);
b >>= 1;
a = MOD(a*a, mod);
}
return ans;
}
ll n, ans=1e18, k, pref[N], x[2][N], y[2][N];
int main () {
ios_base::sync_with_stdio(false), cin.tie(0);
cin>>n>>k;
for(int i=1; i<=k; i++) {
cin>>x[0][i]>>y[0][i]>>x[1][i]>>y[1][i];
}
for(ll d=1; d<n; d++) {
if(n%d != 0) continue;
for(int i=1; i<=n; i++) {
pref[i] = pref[i-1] + (((i-1)/d)%2==0 ? -1 : 1);
}
ll tmp = 0;
for(int i=1; i<=k; i++) {
ll sz = 0, tx = x[0][i], f = pref[y[1][i]] - pref[y[0][i]-1];
ll wh = (((tx-1)/d)%2==0 ? 1 : -1);
if(tx%d==0) tx++;
else tx += (d - (tx%d) + 1);
if(x[1][i] < tx) {
tmp += ((x[1][i]-x[0][i]+1) * wh * f);
continue;
}
tmp += ((tx - x[0][i]) * wh * f);
tx += (((x[1][i]-tx)/(2*d))*2*d);
if(x[1][i]-tx >= d) {
tmp += (d * -1ll * wh * f);
tmp += ((x[1][i]-d-tx+1) * wh * f);
} else {
tmp += ((x[1][i]-tx+1) * -1ll * wh * f);
}
}
ll res = ((n/d)/2) * n * d;
if((n/d)%2 == 1) {
res += (((n/d+1)/2) * d*d);
}
res += tmp;
ans = min(ans, res);
ans = min(ans, n*n - res);
}
cout<<ans<<endl;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
chessboard.cpp: In function 'int main()':
chessboard.cpp:59:7: warning: unused variable 'sz' [-Wunused-variable]
59 | ll sz = 0, tx = x[0][i], f = pref[y[1][i]] - pref[y[0][i]-1];
| ^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |