CSES - Leirikisa 9.12.2021 - Results
Submission details
Task:Ruudukko
Sender:Totska
Submission time:2021-12-09 16:57:35 +0200
Language:C++ (C++17)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#10.01 s1details
#20.01 s1details
#30.01 s1details
#40.01 s1details
#50.01 s1details
#60.78 s2details
#70.77 s2details
#80.01 s2details
#90.01 s2details
#100.01 s2details
#110.82 s3details
#120.82 s3details
#130.02 s3details
#140.46 s3details
#15--3details

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:53:16: warning: variable 'b' set but not used [-Wunused-but-set-variable]
             ll b; b = ll(z);
                ^
input/code.cpp:118:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for (ll i = 0; i < newnb.size(); i++)
                                ~~^~~~~~~~~~~~~~
input/code.cpp:129:22: warning: unused variable 'onefound' [-Wunused-variable]
                 bool onefound = false;
                      ^~~~~~~~
input/code.cpp:130:22: warning: unused variable 'twofound' [-Wunused-variable]
                 bool twofound = false;
                      ^~~~~~~~

Code

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define fr(x) for(ll i=0; i < x; i++)

string s = "";

vector<vector<ll>> grid;
ll n, ycur, xcur;

vector<pair<ll, ll>> nb, newnb, tempnb;
map<pair<ll, ll>, string> stored;


// bool mysort(pair<pair<ll, string>, pair<ll, ll>> i, pair<pair<ll, string>, pair<ll, ll>> j)
// {
//     return (i.first.first < j.first.first);
// }

ll getval(pair<ll, ll> nb)
{
    return grid[nb.first][nb.second];
}

vector<pair<ll, ll>> getnb(ll y, ll x)
{
    vector<pair<ll, ll>> nb;

    if(x != n-1){
        nb.push_back(pair(y, x+1));
    }
    if(y != n-1){
        nb.push_back(pair(y+1, x));
    }

    return nb;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;

    fr(n)
    {
        vector<ll> row;
        fr(n)
        {
            char z; cin >> z;
            ll b; b = ll(z);
            row.push_back(z);
        }

        grid.push_back(row);
    }

    ycur = xcur = 0;
    s += grid[0][0];

    while(ycur != n-1 && xcur != n-1)
    {
        nb = getnb(ycur, xcur);

        if(nb.size() == 1){
            ycur = nb[0].first;
            xcur = nb[0].second;

            s += (char)grid[ycur][xcur];
        }
        
        else if(getval(nb[0]) != getval(nb[1])){

            if(getval(nb[0]) < getval(nb[1])){
                ycur = nb[0].first; xcur = nb[0].second;
            }
            else{
                ycur = nb[1].first; xcur = nb[1].second;

            s += (char) grid[ycur][xcur];
            }
        }

        else{
            s += (char) grid[ycur][xcur];

            vector<pair<ll, ll>> eval;
            eval.push_back(nb[0]);
            eval.push_back(nb[1]);

            stored[nb[0]] = (char) grid[nb[0].first][nb[0].second];
            stored[nb[1]] = (char) grid[nb[1].first][nb[1].second];

            while(eval.size() != 0)
            {
                vector<pair<ll, ll>> values;

                newnb.clear();

                for(auto p : eval)
                {
                    tempnb = getnb(p.first, p.second);

                    for(auto v : tempnb)
                    {
                        if(v == pair(n-1, n-1)){
                            continue;
                        } 
                        newnb.push_back(v);
                        stored[v] = stored[p] + (char )grid[v.first][v.second];
                    }
                }

                eval.clear();

                for (ll i = 0; i < newnb.size(); i++)
                {
                    values.push_back(pair(grid[newnb[i].first][newnb[i].second], i));
                }

                ll minval = 180;
                for(auto val : values)
                {
                    minval = min(minval, val.first);
                }
                
                bool onefound = false;
                bool twofound = false;

                vector<ll> minvals;
                for(auto val : values)
                {
                    if(val.first == minval){
                        minvals.push_back(val.second);
                    }

                }

                if(minvals.size() > 1){
                    for(auto i : minvals)
                    {
                        eval.push_back(newnb[i]);
                    }
                }
                else{
                    ycur = newnb[minvals[0]].first;
                    xcur = newnb[minvals[0]].second;

                    s += stored[pair(ycur, xcur)];
                }

            }
            }
        }
    s += (char) grid[n-1][n-1];
    cout << s << endl;
}

Test details

Test 1

Group: 1

Verdict:

input
5
AAAAA
AAAAA
AAAAA
AAAAA
...

correct output
AAAAAAAAB

user output
(empty)

Test 2

Group: 1

Verdict:

input
5
ABABA
BABAB
ABABA
BABAB
...

correct output
ABABABABA

user output
(empty)

Test 3

Group: 1

Verdict:

input
5
WRYIU
TWLKH
UJMJC
GRDJW
...

correct output
WRWJMDJWK

user output
WWJDK

Test 4

Group: 1

Verdict:

input
5
RUEAE
ZYHHW
KDBPD
DXREW
...

correct output
RUEAEWDWX

user output
RX

Test 5

Group: 1

Verdict:

input
5
SRGYR
MYDOB
GNOVM
SZOZK
...

correct output
SMGNOOLTU

user output
SMGOLU

Test 6

Group: 2

Verdict:

input
100
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

correct output
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

user output
(empty)

Test 7

Group: 2

Verdict:

input
100
ABABABABABABABABABABABABABABAB...

correct output
ABABABABABABABABABABABABABABAB...

user output
(empty)

Test 8

Group: 2

Verdict:

input
100
FWOVNYKNMMQCNHJGUYPNEDXGVVGONC...

correct output
FWDBDECKBHKIACOVUCJGDJOHAYIBHO...

user output
FDBHVUCJGDDJOHAIBFJGFHPGACDTNB...
Truncated

Test 9

Group: 2

Verdict:

input
100
ETGCJABWKMAAEOQXWFFYMDJBMNKMQK...

correct output
EAARGLBRLHCDHHBPABHDAJBEEBHQBE...

user output
(empty)

Test 10

Group: 2

Verdict:

input
100
GNWMLJNHSBAADUFCSGIZMWHZTVDHNR...

correct output
GEGOFRDKBNLLEUOPOEQCEFMTKANLNC...

user output
(empty)

Test 11

Group: 3

Verdict:

input
500
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

correct output
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

user output
(empty)

Test 12

Group: 3

Verdict:

input
500
ABABABABABABABABABABABABABABAB...

correct output
ABABABABABABABABABABABABABABAB...

user output
(empty)

Test 13

Group: 3

Verdict:

input
500
HGADXTSFXYIEMDWMFIVQGHTACFUPYI...

correct output
HGADEJOGAKPJCRAHTABRSDLAVGBFAG...

user output
(empty)

Test 14

Group: 3

Verdict:

input
500
SBLNMAZESQVGWAPZYHQJMQTNGMEZWS...

correct output
SBLCAMDHILGIDRCIDUNMMAHFYCENOS...

user output
(empty)

Test 15

Group: 3

Verdict:

input
500
AOXYXRYFWPYWQDPWXQITLHQQUAYZAJ...

correct output
AOJLDOAPBGEKSGCNKBUMKAJCCWCOOD...

user output
(empty)