CSES - Datatähti 2018 loppu - Results
Submission details
Task:Merkkijono
Sender:suola_makkara
Submission time:2018-01-18 15:31:36 +0200
Language:C++
Status:READY
Result:100
Feedback
groupverdictscore
#1ACCEPTED100
Test results
testverdicttime
#1ACCEPTED0.04 sdetails
#2ACCEPTED0.04 sdetails
#3ACCEPTED0.05 sdetails
#4ACCEPTED0.04 sdetails
#5ACCEPTED0.04 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:51:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j = 0; j < ops.size(); j++)
                      ^
input/code.cpp:54:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(j != ops.size() - 1) cout << "SWAP" << '\n';
              ^

Code

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

string done = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main()
{
    string abc;
    cin >> abc;
    
    vector<int> ops;
    int op = 0;
    
    int moved = 0;
    
    while(true)
    {
        for(int i = abc.length() - 1; i > 0; i--)
        {
            if(abc[i] < abc[i - 1])
            {
                swap(abc[i], abc[i - 1]);

                op += 1;
                int req = abc.length() - i + 1;
                if(req < moved)
                {
                    req += abc.length() - moved;
                    moved -= abc.length();
                }
                else req -= moved;
                ops.push_back(req);
                op += req;
                moved += req;
            }
        }
        if(abc == done)
        {
            int k = abc.length() - moved;
            ops.push_back(k);
            op += k;
            break;
        }
        
    }
    cout << op << '\n';
    for(int j = 0; j < ops.size(); j++)
    {
        for(int i = 0; i < ops[j]; i++) cout << "MOVE" << '\n';
        if(j != ops.size() - 1) cout << "SWAP" << '\n';
    }
    
    return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
ABCDEFGHIJKLMNOPQRSTUVWXYZ

correct output
0

user output
26
MOVE
MOVE
MOVE
MOVE
...

Test 2

Verdict: ACCEPTED

input
ZYXWVUTSRQPONMLKJIHGFEDCBA

correct output
923
MOVE
MOVE
SWAP
MOVE
...

user output
975
MOVE
MOVE
SWAP
MOVE
...

Test 3

Verdict: ACCEPTED

input
RPJMFWBHYQOTXUAENLDGZISCVK

correct output
611
SWAP
MOVE
MOVE
SWAP
...

user output
613
MOVE
MOVE
SWAP
MOVE
...

Test 4

Verdict: ACCEPTED

input
GWJSPBHANMXYFLKIDORVUCEZQT

correct output
659
MOVE
SWAP
MOVE
SWAP
...

user output
689
MOVE
MOVE
MOVE
SWAP
...

Test 5

Verdict: ACCEPTED

input
BJYNFLKEIUCZMQHRAXOGWPSDTV

correct output
624
MOVE
SWAP
MOVE
SWAP
...

user output
704
MOVE
MOVE
MOVE
MOVE
...