답안 #969627

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
969627 2024-04-25T11:21:50 Z SeenSiravit Type Printer (IOI08_printer) C++14
10 / 100
1000 ms 1364 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;
    }

    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";
    cout<< "P" << "\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++){
      |                 ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Incorrect 1 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 126 ms 528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 903 ms 1100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1040 ms 1360 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1039 ms 1364 KB Time limit exceeded
2 Halted 0 ms 0 KB -