Submission #28688703
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int H, W, K;
cin >> H >> W >> K;
vector<int> hv(H), wv(W);
int htot = 0, wtot = 0;
for(int i=0;i<H;i++) {
cin >> hv[i];
htot = (htot + hv[i]) % K;
}
for(int i=0;i<W;i++) {
cin >> wv[i];
wtot = (wtot + wv[i]) % K;
}
if(wtot != htot) {
return cout << -1 << endl, 0;
}
if(H == 1) {
long long res = accumulate(wv.begin(), wv.end(), 0LL);
cout << res << endl;
return 0;
}
if(W == 1) {
long long res = accumulate(hv.begin(), hv.end(), 0LL);
cout << res << endl;
return 0;
}
long long res = 1LL * (H) * (W) * (K - 1);
long long hr = 0, wr = 0;
for(int x:hv) {
hr += (1LL * (K - 1) * W - x) % K;
}
for(int x:wv) {
wr += (1LL * (K - 1) * H - x) % K;
}
cout << res - max(hr, wr) << endl;
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Row Column Sums |
| User | yhchang3 |
| Language | C++ (GCC 9.2.1) |
| Score | 500 |
| Code Size | 871 Byte |
| Status | AC |
| Exec Time | 43 ms |
| Memory | 4732 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00-sample-001.txt, 00-sample-002.txt |
| All | 00-sample-001.txt, 00-sample-002.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00-sample-001.txt | AC | 7 ms | 3468 KiB |
| 00-sample-002.txt | AC | 2 ms | 3556 KiB |
| 01-001.txt | AC | 2 ms | 3520 KiB |
| 01-002.txt | AC | 2 ms | 3584 KiB |
| 01-003.txt | AC | 21 ms | 3584 KiB |
| 01-004.txt | AC | 19 ms | 3908 KiB |
| 01-005.txt | AC | 6 ms | 3668 KiB |
| 01-006.txt | AC | 21 ms | 3696 KiB |
| 01-007.txt | AC | 29 ms | 4232 KiB |
| 01-008.txt | AC | 17 ms | 3688 KiB |
| 01-009.txt | AC | 30 ms | 4216 KiB |
| 01-010.txt | AC | 32 ms | 4176 KiB |
| 01-011.txt | AC | 21 ms | 3720 KiB |
| 01-012.txt | AC | 23 ms | 4100 KiB |
| 01-013.txt | AC | 32 ms | 4224 KiB |
| 01-014.txt | AC | 12 ms | 3740 KiB |
| 01-015.txt | AC | 35 ms | 4732 KiB |
| 01-016.txt | AC | 40 ms | 4704 KiB |
| 01-017.txt | AC | 43 ms | 4700 KiB |
| 01-018.txt | AC | 39 ms | 4700 KiB |
| 01-019.txt | AC | 41 ms | 4644 KiB |
| 01-020.txt | AC | 41 ms | 4712 KiB |
| 01-021.txt | AC | 42 ms | 4644 KiB |
| 01-022.txt | AC | 40 ms | 4668 KiB |