Submission #969625

# Submission time Handle Problem Language Result Execution time Memory
969625 2024-04-25T11:19:32 Z SeenSiravit Type Printer (IOI08_printer) C++14
0 / 100
1000 ms 1708 KB
#include<bits/stdc++.h>

using namespace std;

int n;
vector<string> words;
int base = 0;

int find_position(string s , string res){
    for(int i=0;i<min(s.length() , res.length());i++){
        if(res[i] != s[i]) return i;
    }

    return min(s.length() , res.length());
}

int main(){

    cin>> n;

    words.assign(n , "");

    for(int i=0;i<n;i++){
        cin>> words[i];

        if(words[i].length() > words[base].length()) base = i;
    }

    /*
        word 1 -> word 2 -> word 3 -> ...-> word n-1 -> word n (base) 
        each step must change as least as possible
        reverse : word n -> word n-1 -> ... -> word 2 -> word 1

        O(n^2 * mxLen)
        25000^2 * 20 = 12,500,000
    */

    int ans = 0;
    stack<char> st;

    swap(words[0] , words[base]);

    for(int i=0;i<n-1;i++){
        int pos = i+1 , mn = INT_MAX , idx = 0;
        for(int j=i+1;j<n;j++){
            int dummy = find_position(words[j] , words[i]);
            int op = words[i].length() + words[j].length() - 2*dummy;
            if(op < mn) pos = j , mn = op , idx = dummy;
        }

        ans += mn + 1;

        st.push('P');
        int curr = words[i].length() - 1;
        while(curr >= idx) st.push(words[i][curr--]);
        for(int j=words[pos].length()-1;j>=idx;j--) st.push('-');

        swap(words[i+1] , words[pos]);
        // cout<< ans << "\n";
    }

    ans += words[n-1].length() + 1;
    cout<< ans << "\n";

    for(auto c : words[n-1]) cout<< c << "\n";

    while(!st.empty()) cout<< st.top() << "\n" , st.pop();

    return 0;
}

Compilation message

printer.cpp: In function 'int find_position(std::string, std::string)':
printer.cpp:10:18: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   10 |     for(int i=0;i<min(s.length() , res.length());i++){
      |                 ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 476 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 124 ms 596 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 888 ms 1708 KB Line "" doesn't correspond to pattern "[a-z\-P]{1}"
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1046 ms 1432 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1008 ms 1616 KB Time limit exceeded
2 Halted 0 ms 0 KB -