답안 #960235

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
960235 2024-04-10T00:33:25 Z irmuun Type Printer (IOI08_printer) C++17
100 / 100
75 ms 5608 KB
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

string t="";
bool cmp(string a,string b){
    int i1=-1,i2=-1;
    for(int i=0;i<a.size();i++){
        if(a[i]!=t[i]){
            break;
        }
        i1++;
    }
    for(int i=0;i<b.size();i++){
        if(b[i]!=t[i]){
            break;
        }
        i2++;
    }
    if(i1==i2){
        return (a<b);
    }
    return (i1<i2);
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n;
    cin>>n;
    string s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    for(int i=0;i<n;i++){
        if(t.size()<s[i].size()){
            t=s[i];
        }
    }
    sort(s,s+n,cmp);
    vector<char>ans;
    string cur="";
    for(int i=0;i<n;i++){
        while(cur.size()>s[i].size()){
            ans.pb('-');
            cur.pop_back();
        }
        while(!cur.empty()&&s[i].substr(0,cur.size())!=cur){
            ans.pb('-');
            cur.pop_back();
        }
        for(int j=cur.size();j<s[i].size();j++){
            ans.pb(s[i][j]);
            cur+=s[i][j];
        }
        ans.pb('P');
    }
    cout<<ans.size()<<"\n";
    for(auto x:ans){
        cout<<x<<'\n';
    }
}

Compilation message

printer.cpp: In function 'bool cmp(std::string, std::string)':
printer.cpp:15:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |     for(int i=0;i<a.size();i++){
      |                 ~^~~~~~~~~
printer.cpp:21:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(int i=0;i<b.size();i++){
      |                 ~^~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:58:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         for(int j=cur.size();j<s[i].size();j++){
      |                              ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 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 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 604 KB Output is correct
2 Correct 9 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 1248 KB Output is correct
2 Correct 11 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 2508 KB Output is correct
2 Correct 59 ms 4804 KB Output is correct
3 Correct 46 ms 3740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 2268 KB Output is correct
2 Correct 75 ms 5608 KB Output is correct
3 Correct 47 ms 4292 KB Output is correct
4 Correct 75 ms 5320 KB Output is correct