CSES - HIIT Open 2024 - Results
Submission details
Task:Hiitism
Sender:¯\_(._.)_/¯
Submission time:2024-11-16 15:35:22 +0200
Language:C++ (C++17)
Status:READY
Result:
Test results
testverdicttime
#1ACCEPTED0.00 sdetails
#2ACCEPTED0.00 sdetails
#3ACCEPTED0.00 sdetails
#4ACCEPTED0.00 sdetails
#5ACCEPTED0.00 sdetails
#6ACCEPTED0.03 sdetails
#7ACCEPTED0.03 sdetails
#8ACCEPTED0.03 sdetails
#9ACCEPTED0.03 sdetails
#10ACCEPTED0.03 sdetails
#11ACCEPTED0.03 sdetails
#12ACCEPTED0.03 sdetails
#13ACCEPTED0.03 sdetails
#14ACCEPTED0.03 sdetails
#15ACCEPTED0.03 sdetails
#160.02 sdetails
#170.01 sdetails
#18ACCEPTED0.02 sdetails
#190.01 sdetails
#20ACCEPTED0.03 sdetails
#21ACCEPTED0.03 sdetails
#22ACCEPTED0.03 sdetails
#23ACCEPTED0.03 sdetails
#24ACCEPTED0.03 sdetails
#25ACCEPTED0.02 sdetails
#260.01 sdetails
#27ACCEPTED0.02 sdetails
#280.01 sdetails
#29ACCEPTED0.03 sdetails
#30ACCEPTED0.03 sdetails

Compiler report

input/code.cpp: In function 'long long int toIdx(char)':
input/code.cpp:18:1: warning: control reaches end of non-void function [-Wreturn-type]
   18 | }
      | ^

Code

#include <bits/stdc++.h>
#include <iostream>

#define int long long
using namespace std;


int toIdx(char c)
{
    if (c == '.')
        return -1;
    if (c == 'H')
        return 0;
    if (c == 'I')
        return 1;
    if (c == 'T')
        return 2;
}
char toC(int idx)
{
    if (idx == 0)
        return 'H';
    if (idx == 1)
        return 'I';
    if (idx == 2)
        return 'T';
    return '_';
}


void solve()
{
    int n, m;
    cin >> n >> m;

    vector<string> paint(n);
    for (int i = 0; i < n; i++)
        cin >> paint[i];
    
    vector<vector<int>> rows(n, {0, 0, 0});
    vector<vector<int>> cols(n, {0, 0, 0});
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            int idx = toIdx(paint[i][j]);
            if (idx == -1)
                continue;
            rows[i][idx]++;
            cols[j][idx]++;
        }
    }

    vector<pair<int, int>> res;

    vector<bool> usedC(m, false);
    vector<bool> usedR(n, false);

    int c = 0;
    int r = 0;

    int rH = 0;
    int rI = 0;
    int rT = 0;
    int cH = 0;
    int cI = 0;
    int cT = 0;

    bool stuck = false;
    while (!stuck)
    {
        stuck = true;
        for (int i = 0; i < m; i++)
        {
            if (usedC[i])
                continue;

            //cout << "Cols var: " << cols[i][0] << endl;

            if (cols[i][0]-cH >= n-c)
            {
                stuck = false;
                res.push_back({i, 0});
                usedC[i] = true;
                r++;
                rH++;
                //break;
            }
            if (cols[i][1]-cI >= n-c)
            {
                stuck = false;
                res.push_back({i, 1});
                usedC[i] = true;
                r++;
                rI++;
                //break;
            }
            if (cols[i][2]-cT >= n-c)
            {
                stuck = false;
                res.push_back({i, 2});
                usedC[i] = true;
                r++;
                rT++;
                //break;
            }
        }
        //if (cont)
        //    continue;
        for (int i = 0; i < n; i++)
        {
            if (usedR[i])
                continue;
            
            if (rows[i][0]-rH >= n-r)
            {
                stuck = false;
                res.push_back({i+100000, 0});
                usedR[i] = true;
                c++;
                cH++;
            }
            if (rows[i][1]-rI >= n-r)
            {
                stuck = false;
                res.push_back({i+100000, 1});
                usedR[i] = true;
                c++;
                cI++;
            }
            if (rows[i][2]-rT >= n-r)
            {
                stuck = false;
                res.push_back({i+100000, 2});
                usedR[i] = true;
                c++;
                cT++;
            }
        }
    }

    //*
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (paint[i][j] != '.' && !(usedR[i] || usedC[j]))
            {
                cout << "Impossible";
                return;
            }

        }
    }
    //*/

    cout << res.size() << '\n';
    for (int i = res.size()-1; i >= 0; i--)
    {
        if (res[i].first >= 100000)
            cout << "R ";
        else
            cout << "C ";
        int val = res[i].first % 100000;
        cout << val+1 << ' ' << toC(res[i].second) << '\n';
    }

}

signed main()
{
    solve();
    return 0;
}

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 822 I
C 83 T
C 55 I
R 984 H
...

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
C 804 H
R 952 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
R 167 I
C 445 I
C 355 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:

input
1000 500
HIHHTHTITTHIHTHTTHIHTTIHTTHHTH...

correct output
1417
C 75 I
R 430 T
C 195 H
R 441 I
...

user output
Impossible

Test 17

Verdict:

input
500 1000
IHIIIHIIHIIIIIHIHHIIIIIIIIIIII...

correct output
1418
C 971 T
C 744 I
C 654 I
C 540 T
...

user output
(empty)

Test 18

Verdict: ACCEPTED

input
1000 500
IIIIIIIIIIIIIIITIIIIIIITTIIIII...

correct output
Impossible

user output
Impossible

Test 19

Verdict:

input
500 1000
HIITITHHHHIHHIHHTHIIIHHHHTHTHH...

correct output
Impossible

user output
(empty)

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:

input
500 1000
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHH...

correct output
Impossible

user output
(empty)

Test 27

Verdict: ACCEPTED

input
1000 500
TTTTIHTTTHTTHTITTTTHTHTTHTITTI...

correct output
Impossible

user output
Impossible

Test 28

Verdict:

input
500 1000
HTIIIHIIIHITIHIIIIIIHTIIIIITHI...

correct output
Impossible

user output
(empty)

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