QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#563109 | #4148. 打地鼠 | Elegia | 100 ✓ | 1ms | 3760kb | C++23 | 2.9kb | 2024-09-14 02:47:38 | 2024-09-14 02:47:39 |
Judging History
answer
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>
#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>
#define LOG(FMT...) fprintf(stderr, FMT)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
for (T& x : v)
is >> x;
return is;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
if (!v.empty()) {
os << v.front();
for (int i = 1; i < v.size(); ++i)
os << ' ' << v[i];
}
return os;
}
const int N = 110;
int a[N][N];
int x[N][N];
pair<int, int> ways[N * N];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
#ifdef ELEGIA
freopen("test.in", "r", stdin);
int nol_cl = clock();
#endif
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
int sum = 0, rg = 0, cg = 0;
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j) {
cin >> a[i][j];
sum += a[i][j];
}
for (int i = 0; i < n; ++i) {
int s = 0;
for (int j = 0; j < m; ++j)
s += a[i][j];
rg = gcd(rg, s);
}
for (int j = 0; j < m; ++j) {
int s = 0;
for (int i = 0; i < n; ++i)
s += a[i][j];
cg = gcd(cg, s);
}
for (int i = 0; i <= n; ++i)
for (int j = m; j; --j)
a[i][j] -= a[i][j - 1];
for (int i = n; i; --i)
for (int j = 0; j <= m; ++j)
a[i][j] -= a[i - 1][j];
int cnt = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j)
if (rg % j == 0 && cg % i == 0)
ways[++cnt] = make_pair(i, j);
auto check = [&](int u, int v) {
memcpy(x, a, sizeof(x));
for (int i = 0; i <= n; ++i)
for (int j = v; j <= m; ++j)
x[i][j] += x[i][j - v];
for (int j = 0; j <= m; ++j)
for (int i = u; i <= n; ++i)
x[i][j] += x[i - u][j];
for (int i = 0; i <= n; ++i)
for (int j = 0; j <= m; ++j) {
if (i <= n - u && j <= m - v) {
if (x[i][j] < 0)
return false;
} else if (x[i][j])
return false;
}
return true;
};
sort(ways + 1, ways + cnt + 1, [&](const pair<int, int>& lhs, const pair<int, int>& rhs) { return lhs.first * lhs.second > rhs.first * rhs.second; });
for (int i = 1; i <= cnt; ++i)
if (check(ways[i].first, ways[i].second)) {
cout << (sum / ways[i].first / ways[i].second);
break;
}
#ifdef ELEGIA
LOG("Time: %dms\n", int ((clock()
-nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Pretests
Final Tests
Test #1:
score: 10
Accepted
time: 0ms
memory: 3636kb
input:
5 3 334 500 169 1058 978 527 1686 942 1063 1107 745 1532 145 281 827
output:
5947
result:
ok single line: '5947'
Test #2:
score: 10
Accepted
time: 0ms
memory: 3672kb
input:
4 5 995 1937 1769 1263 436 1386 2932 3275 2318 589 683 1669 2309 2192 869 292 674 803 1137 716
output:
7061
result:
ok single line: '7061'
Test #3:
score: 10
Accepted
time: 0ms
memory: 3676kb
input:
5 5 447 1173 1497 1309 538 869 1781 1579 966 299 35 929 1597 1514 811 322 655 1006 1337 664 141 852 964 1121 868
output:
11637
result:
ok single line: '11637'
Test #4:
score: 10
Accepted
time: 0ms
memory: 3624kb
input:
25 30 662 1419 1456 2315 3038 3779 4308 5086 5402 5437 5627 6469 6757 6863 6903 7183 6426 6389 5530 4807 4066 3537 2759 2443 2408 2218 1376 1088 982 942 926 2331 2814 4478 6091 7561 8460 9588 9910 10046 10629 12019 12936 13665 13789 14759 13354 12871 11207 9594 8124 7225 6097 5775 5639 5056 3666 274...
output:
113549
result:
ok single line: '113549'
Test #5:
score: 10
Accepted
time: 0ms
memory: 3696kb
input:
30 29 3 872 1733 2421 2822 3608 2994 2556 1870 2054 1447 1477 1142 1566 1598 2173 2720 3564 3307 2844 2808 2165 2209 2369 2583 1862 1673 697 368 695 1989 3405 4527 5477 6012 5485 4637 3577 3930 3635 3292 3235 3878 4188 4697 5634 6604 6505 5912 6138 5159 4849 4869 4633 2963 2581 1410 784 981 2380 428...
output:
301844
result:
ok single line: '301844'
Test #6:
score: 10
Accepted
time: 0ms
memory: 3696kb
input:
30 28 220 402 923 831 369 878 259 8 619 971 3 945 781 504 392 685 313 698 589 722 938 37 410 461 234 508 961 959 713 917 1192 1768 1238 936 959 979 883 1088 218 1500 1596 834 431 897 601 780 1543 807 1648 521 1184 841 1049 1459 1502 1074 1392 1027 2090 1841 2026 1913 1091 1935 1572 1201 226 2441 238...
output:
387835
result:
ok single line: '387835'
Test #7:
score: 10
Accepted
time: 1ms
memory: 3760kb
input:
70 100 253 1175 1810 2453 3341 3494 3726 4473 5153 6079 6757 7207 8008 8969 9168 10023 10386 11102 11675 12236 12481 12954 13228 13778 14131 14059 13424 13488 12955 12710 13022 12962 12744 13045 12231 12029 11960 11406 11335 11807 11757 11766 11082 11498 11257 11177 11135 11519 11262 11115 11512 121...
output:
2323477
result:
ok single line: '2323477'
Test #8:
score: 10
Accepted
time: 1ms
memory: 3680kb
input:
100 80 334 981 1407 1450 1694 2286 3047 3316 3491 3630 4326 4807 5278 5546 6259 6925 6955 7761 7870 8160 8219 8903 9449 10208 10311 10917 11308 11401 11597 12180 13130 13687 14122 14134 14801 15670 15835 16738 17377 17521 17611 17717 17988 17396 16635 16366 16191 16052 15356 14875 14404 14136 13423 ...
output:
1602806
result:
ok single line: '1602806'
Test #9:
score: 10
Accepted
time: 1ms
memory: 3672kb
input:
90 99 807 1024 1350 1367 1547 1604 2473 3009 3467 4167 4789 5063 5898 6726 7640 8598 9497 9924 10516 11437 11777 11866 12402 12445 12938 13084 13105 13933 14027 14245 15047 15990 16486 16513 16730 16815 17218 17890 18666 19351 20062 19321 19358 19386 20311 20774 21217 20498 20828 20579 20413 20189 2...
output:
2037604
result:
ok single line: '2037604'
Test #10:
score: 10
Accepted
time: 0ms
memory: 3740kb
input:
100 100 667 1056 1121 2082 2680 2361 2876 3355 3260 3247 3161 2400 2454 2491 2547 3072 3215 3611 2996 2876 2678 3383 2582 3284 2952 3255 2779 2751 2342 2234 1931 1552 1389 1735 1941 2138 2220 3210 2490 2856 2155 2521 2144 2736 2287 2876 2424 2356 2076 2302 2527 3104 3094 3424 3537 3300 2662 2274 223...
output:
3568696
result:
ok single line: '3568696'