답안 #91643

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91643 2018-12-29T01:25:24 Z Retro3014 Type Printer (IOI08_printer) C++17
100 / 100
108 ms 5744 KB
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;
#define MAX_N 25000

int N;
string str[MAX_N+1];
string l;
vector<char> stack, ans;

bool sf(string s1, string s2){
    int t=0;
    while(1){
        if(s1.size()<=t || s2.size()<=t)    return s1<s2;
        if(s1[t]==l[t] && s2[t]==l[t]) t++;
        else if(s1[t]==l[t])    return false;
        else if(s2[t]==l[t])    return true;
        else    return s1<s2;
    }
}

int main(){
    scanf("%d", &N);
    for(int i=0; i<N; i++){
        cin>>str[i];
        if(l.size()<str[i].size()){
            l=str[i];
        }
    }
    sort(str, str+N, sf);
    for(int i=0; i<N; i++){
        for(int j=0; j<str[i].size(); j++){
            if(stack.size()==j){
                stack.push_back(str[i][j]);
                ans.push_back(str[i][j]);
            }
            while(stack.size()>j && stack[j]!=str[i][j]){
                stack.pop_back();   ans.push_back('-');
            }
            if(stack.size()==j){
                stack.push_back(str[i][j]);
                ans.push_back(str[i][j]);
            }
        }
        ans.push_back('P');
    }
    printf("%d\n", (int)ans.size());
    for(int i=0; i<ans.size(); i++){
        printf("%c\n", ans[i]);
    }
    return 0;
}

Compilation message

printer.cpp: In function 'bool sf(std::__cxx11::string, std::__cxx11::string)':
printer.cpp:17:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(s1.size()<=t || s2.size()<=t)    return s1<s2;
            ~~~~~~~~~^~~
printer.cpp:17:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(s1.size()<=t || s2.size()<=t)    return s1<s2;
                            ~~~~~~~~~^~~
printer.cpp: In function 'int main()':
printer.cpp:35:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0; j<str[i].size(); j++){
                      ~^~~~~~~~~~~~~~
printer.cpp:36:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(stack.size()==j){
                ~~~~~~~~~~~~^~~
printer.cpp:40:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while(stack.size()>j && stack[j]!=str[i][j]){
                   ~~~~~~~~~~~~^~
printer.cpp:43:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(stack.size()==j){
                ~~~~~~~~~~~~^~~
printer.cpp:51:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<ans.size(); i++){
                  ~^~~~~~~~~~~
printer.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1144 KB Output is correct
2 Correct 8 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1144 KB Output is correct
2 Correct 2 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1016 KB Output is correct
2 Correct 2 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1144 KB Output is correct
2 Correct 2 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1204 KB Output is correct
2 Correct 3 ms 1144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1144 KB Output is correct
2 Correct 5 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1400 KB Output is correct
2 Correct 18 ms 1784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 1908 KB Output is correct
2 Correct 24 ms 1656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 2676 KB Output is correct
2 Correct 90 ms 4848 KB Output is correct
3 Correct 76 ms 3952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 2284 KB Output is correct
2 Correct 108 ms 5744 KB Output is correct
3 Correct 82 ms 4212 KB Output is correct
4 Correct 100 ms 5484 KB Output is correct