Submission #289653

#TimeUsernameProblemLanguageResultExecution timeMemory
289653luciocfChessboard (IZhO18_chessboard)C++14
70 / 100
272 ms1144 KiB
#include <bits/stdc++.h> #define ff first #define ss second using namespace std; typedef pair<int, int> pii; typedef long long ll; const int maxn = 1e5+10; const ll inf = 1e18+10; pii pt[maxn]; int main(void) { int n, k; scanf("%d %d", &n, &k); for (int i = 1; i <= k; i++) { scanf("%d %d", &pt[i].ff, &pt[i].ss); scanf("%d %d", &pt[i].ff, &pt[i].ss); pt[i].ff--, pt[i].ss--; } vector<int> D; for (int d = 1; d*d <= n; d++) { if (n%d) continue; D.push_back(d); if (n/d != d) D.push_back(n/d); } ll ans = inf; for (auto d: D) { if (d == n) continue; int p = 0, b = 0; for (int i = 1; i <= k; i++) { int ma = pt[i].ff%(2*d); int mb = pt[i].ss%(2*d); if ((ma < d && mb < d) || (ma >= d && mb >= d)) p++; else b++; } ll x = ((n+2*d-1)/(2*d)); ll y = n/(2*d); ll tot_p = 1ll*d*d*(x*x+y*y); ans = min(ans, (tot_p-p)+b); swap(p, b); tot_p = 1ll*n*n-tot_p; ans = min(ans, (tot_p-p)+b); } printf("%lld\n", ans); }

Compilation message (stderr)

chessboard.cpp: In function 'int main()':
chessboard.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   19 |  scanf("%d %d", &n, &k);
      |  ~~~~~^~~~~~~~~~~~~~~~~
chessboard.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |   scanf("%d %d", &pt[i].ff, &pt[i].ss);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
chessboard.cpp:24:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |   scanf("%d %d", &pt[i].ff, &pt[i].ss);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...