Task: | Hiitism |
Sender: | asdf4321 |
Submission time: | 2024-11-16 15:14:05 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.00 s | details |
#3 | ACCEPTED | 0.00 s | details |
#4 | ACCEPTED | 0.01 s | details |
#5 | ACCEPTED | 0.00 s | details |
#6 | ACCEPTED | 0.03 s | details |
#7 | ACCEPTED | 0.04 s | details |
#8 | ACCEPTED | 0.05 s | details |
#9 | ACCEPTED | 0.06 s | details |
#10 | ACCEPTED | 0.06 s | details |
#11 | ACCEPTED | 0.06 s | details |
#12 | ACCEPTED | 0.04 s | details |
#13 | ACCEPTED | 0.04 s | details |
#14 | ACCEPTED | 0.04 s | details |
#15 | ACCEPTED | 0.04 s | details |
#16 | ACCEPTED | 0.04 s | details |
#17 | ACCEPTED | 0.03 s | details |
#18 | ACCEPTED | 0.02 s | details |
#19 | ACCEPTED | 0.02 s | details |
#20 | ACCEPTED | 0.04 s | details |
#21 | ACCEPTED | 0.04 s | details |
#22 | ACCEPTED | 0.04 s | details |
#23 | ACCEPTED | 0.04 s | details |
#24 | ACCEPTED | 0.04 s | details |
#25 | ACCEPTED | 0.02 s | details |
#26 | ACCEPTED | 0.03 s | details |
#27 | ACCEPTED | 0.02 s | details |
#28 | ACCEPTED | 0.02 s | details |
#29 | ACCEPTED | 0.04 s | details |
#30 | ACCEPTED | 0.03 s | details |
Code
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, a, b) for (int i = a; i < (b); i++) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; const int N = 1005; int n, m; string a[N]; int b[N][N]; int row[N][5]; int col[N][5]; signed main() { #ifdef LOCAL freopen(".inp", "r", stdin); freopen(".out", "w", stdout); #endif cin >> n >> m; for (int i = 1; i <= n; i++) { cin >> a[i]; a[i] = '.' + a[i]; } int cnt = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (a[i][j] == '.') b[i][j] = 0; if (a[i][j] == 'H') cnt++, b[i][j] = 1; if (a[i][j] == 'I') cnt++, b[i][j] = 2; if (a[i][j] == 'T') cnt++, b[i][j] = 3; row[i][b[i][j]]++; col[j][b[i][j]]++; // cerr << i << ' ' << j << ' ' << b[i][j] << '\n'; } } vector<array<int, 3>> ops; while (cnt) { // cerr << cnt << '\n'; // search row { bool found = false; int ii = -1, vv = -1; for (int i = 1; i <= n && !found; i++) { int sum = row[i][0] + row[i][1] + row[i][2] + row[i][3]; if (!sum) continue; for (int val = 1; val <= 3 && !found; val++) { if (row[i][val] == sum) { found = true; ii = i; vv = val; break; } } } if (found) { // cerr << "row " << ii << ' ' << vv << '\n'; ops.push_back({0, ii, vv}); for (int j = 1; j <= m; j++) { if (b[ii][j] < 4) { col[j][vv]--; if (b[ii][j]) cnt--; b[ii][j] = 4; } } row[ii][0] = row[ii][1] = row[ii][2] = row[ii][3] = 0; continue; } } // search col { bool found = false; int jj = -1, vv = -1; for (int j = 1; j <= m && !found; j++) { int sum = col[j][0] + col[j][1] + col[j][2] + col[j][3]; if (!sum) continue; for (int val = 1; val <= 3 && !found; val++) { if (col[j][val] == sum) { found = true; jj = j; vv = val; break; } } } if (found) { // cerr << "col " << jj << ' ' << vv << '\n'; ops.push_back({1, jj, vv}); for (int i = 1; i <= n; i++) { if (b[i][jj] < 4) { row[i][vv]--; if (b[i][jj]) cnt--; b[i][jj] = 4; } } col[jj][0] = col[jj][1] = col[jj][2] = col[jj][3] = 0; continue; } else { cout << "Impossible"; return 0; } } } cout << sz(ops) << '\n'; reverse(all(ops)); for (auto x : ops) { if (x[0]) cout << "C "; else cout << "R "; cout << x[1] << ' '; if (x[2] == 1) cout << "H"; else if (x[2] == 2) cout << "I"; else cout << "T"; cout << '\n'; } }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
3 3 .H. IHI TTT |
correct output |
---|
3 R 2 I C 2 H R 3 T |
user output |
---|
3 R 2 I C 2 H R 3 T |
Test 2
Verdict: ACCEPTED
input |
---|
2 2 .H IH |
correct output |
---|
2 R 2 I C 2 H |
user output |
---|
2 R 2 I C 2 H |
Test 3
Verdict: ACCEPTED
input |
---|
10 10 T.TIH..... IIIIIIIIII T.TIH..... TIIIHIIIII ... |
correct output |
---|
7 C 3 T R 10 I R 4 I C 5 H ... |
user output |
---|
7 C 3 T R 10 I R 4 I C 5 H ... |
Test 4
Verdict: ACCEPTED
input |
---|
100 100 .............H........I.....IT... |
correct output |
---|
19 R 3 T C 44 H R 34 I C 30 T ... |
user output |
---|
19 R 3 T C 44 H R 34 I C 30 T ... |
Test 5
Verdict: ACCEPTED
input |
---|
100 100 .........................H....... |
correct output |
---|
Impossible |
user output |
---|
Impossible |
Test 6
Verdict: ACCEPTED
input |
---|
1000 1000 H.II..T.I.IH..I..H.I..I..ITHH.... |
correct output |
---|
Impossible |
user output |
---|
Impossible |
Test 7
Verdict: ACCEPTED
input |
---|
1000 1000 HHHIHHHHHHHHHHHHIHHHHHHHHHHHHH... |
correct output |
---|
Impossible |
user output |
---|
Impossible |
Test 8
Verdict: ACCEPTED
input |
---|
1000 1000 IHIHTI.T.H..IHHIIT.I.TT.HH.HI.... |
correct output |
---|
1552 C 822 I C 83 T C 55 I R 984 H ... |
user output |
---|
1552 C 886 H C 822 I C 83 T C 55 I ... |
Test 9
Verdict: ACCEPTED
input |
---|
1000 1000 HHHHHHHHHHHHHHHHHHHHHIHHHHHHHH... |
correct output |
---|
1727 R 500 I C 938 H C 804 H R 263 H ... |
user output |
---|
1727 R 500 I C 938 H R 263 H C 888 I ... |
Test 10
Verdict: ACCEPTED
input |
---|
1000 1000 TITTTHTITTHTHTHITTTTTTTHTHTTTI... |
correct output |
---|
1856 C 22 H R 531 T C 412 H C 288 H ... |
user output |
---|
1856 C 22 H R 531 T C 412 H C 288 H ... |
Test 11
Verdict: ACCEPTED
input |
---|
1000 1000 IHHTTTTHTIIIHTTTTHTIITTTHHITIT... |
correct output |
---|
1826 R 200 H R 167 I C 445 I C 355 I ... |
user output |
---|
1826 R 200 H C 445 I C 355 I C 303 I ... |
Test 12
Verdict: ACCEPTED
input |
---|
1000 1000 TTTTTITTTHTHTITIIHTIITIHTTIHTT... |
correct output |
---|
Impossible |
user output |
---|
Impossible |
Test 13
Verdict: ACCEPTED
input |
---|
1000 1000 TITHITITIITTIIIIIHIIIIHTIIIHTI... |
correct output |
---|
Impossible |
user output |
---|
Impossible |
Test 14
Verdict: ACCEPTED
input |
---|
1000 1000 TTTTTTTTTTTTTTTTTTTITTTTTTTITT... |
correct output |
---|
Impossible |
user output |
---|
Impossible |
Test 15
Verdict: ACCEPTED
input |
---|
1000 1000 IHTHHHIHIIIHHTTHHHHIHIIHHIHHHH... |
correct output |
---|
Impossible |
user output |
---|
Impossible |
Test 16
Verdict: ACCEPTED
input |
---|
1000 500 HIHHTHTITTHIHTHTTHIHTTIHTTHHTH... |
correct output |
---|
1417 C 75 I R 430 T C 195 H R 441 I ... |
user output |
---|
1417 C 75 I R 430 T C 201 I C 195 H ... |
Test 17
Verdict: ACCEPTED
input |
---|
500 1000 IHIIIHIIHIIIIIHIHHIIIIIIIIIIII... |
correct output |
---|
1418 C 971 T C 744 I C 654 I C 540 T ... |
user output |
---|
1418 C 971 T C 744 I C 654 I C 540 T ... |
Test 18
Verdict: ACCEPTED
input |
---|
1000 500 IIIIIIIIIIIIIIITIIIIIIITTIIIII... |
correct output |
---|
Impossible |
user output |
---|
Impossible |
Test 19
Verdict: ACCEPTED
input |
---|
500 1000 HIITITHHHHIHHIHHTHIIIHHHHTHTHH... |
correct output |
---|
Impossible |
user output |
---|
Impossible |
Test 20
Verdict: ACCEPTED
input |
---|
1000 1000 TIITIIIIIIIIIIIIIIIIIHIHIIIIII... |
correct output |
---|
Impossible |
user output |
---|
Impossible |
Test 21
Verdict: ACCEPTED
input |
---|
1000 1000 TTHTTTTTHTTTHTTTTTTTTHHTTTTTIT... |
correct output |
---|
Impossible |
user output |
---|
Impossible |
Test 22
Verdict: ACCEPTED
input |
---|
1000 1000 IHIIIIITHIIIHIHHHITHIIIIHTTIHI... |
correct output |
---|
Impossible |
user output |
---|
Impossible |
Test 23
Verdict: ACCEPTED
input |
---|
1000 1000 TTHIHIITHTI.HHIHHITIHIHIHIITIH... |
correct output |
---|
Impossible |
user output |
---|
Impossible |
Test 24
Verdict: ACCEPTED
input |
---|
1000 1000 IHIHIIIIIIIIIHIIIHIHIITIHIIIII... |
correct output |
---|
Impossible |
user output |
---|
Impossible |
Test 25
Verdict: ACCEPTED
input |
---|
1000 500 HIHITTIHITHHHTITHIHHHTHHIHHIII... |
correct output |
---|
Impossible |
user output |
---|
Impossible |
Test 26
Verdict: ACCEPTED
input |
---|
500 1000 HHHHHHHHHHHHHHHHHHHHHHHHHHHHHH... |
correct output |
---|
Impossible |
user output |
---|
Impossible |
Test 27
Verdict: ACCEPTED
input |
---|
1000 500 TTTTIHTTTHTTHTITTTTHTHTTHTITTI... |
correct output |
---|
Impossible |
user output |
---|
Impossible |
Test 28
Verdict: ACCEPTED
input |
---|
500 1000 HTIIIHIIIHITIHIIIIIIHTIIIIITHI... |
correct output |
---|
Impossible |
user output |
---|
Impossible |
Test 29
Verdict: ACCEPTED
input |
---|
1000 1000 ................................. |
correct output |
---|
0 |
user output |
---|
0 |
Test 30
Verdict: ACCEPTED
input |
---|
1000 1000 ................................. |
correct output |
---|
1 C 562 T |
user output |
---|
1 C 562 T |