답안 #883212

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
883212 2023-12-04T19:33:02 Z JakobZorz Type Printer (IOI08_printer) C++14
100 / 100
76 ms 7008 KB
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<limits.h>
#include<math.h>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<iomanip>
#include<cstring>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;
//const int MOD=1e9+7;
//typedef pair<ll,ll>Point;
//typedef pair<ll,ll>Line;
//#define x first
//#define y second

void solve(){
    int n;
    cin>>n;
    vector<string>arr(n);
    string m;
    for(string&i:arr){
        cin>>i;
        if(i.size()>m.size())
            m=i;
    }
    sort(arr.begin(),arr.end());
    
    for(int p=1;p<m.size();p++){
        vector<string>pref,suf;
        for(int i=0;i<n;i++){
            bool matches=true;
            if(arr[i].size()<p)
                matches=false;
            else{
                for(int j=0;j<p;j++)
                    if(m[j]!=arr[i][j])
                        matches=false;
            }
            
            if(matches)
                suf.push_back(arr[i]);
            else
                pref.push_back(arr[i]);
        }
        
        arr=pref;
        arr.insert(arr.end(),suf.begin(),suf.end());
    }
    
    vector<char>res;
    string prev;
    for(int i=0;i<n;i++){
        while(arr[i].substr(0,prev.size())!=prev){
            prev.pop_back();
            res.push_back('-');
        }
        while(prev!=arr[i]){
            res.push_back(arr[i][(int)prev.size()]);
            prev.push_back(arr[i][(int)prev.size()]);
        }
        res.push_back('P');
    }
    
    cout<<res.size()<<"\n";
    for(char c:res)
        cout<<c<<"\n";
}

int main(){
    ios::sync_with_stdio(false);cout.tie(NULL);cin.tie(NULL);
    //freopen("bank.in","r",stdin);freopen("bank.out","w",stdout);
    int t=1;//cin>>t;
    while(t--)solve();
    return 0;
}

Compilation message

printer.cpp: In function 'void solve()':
printer.cpp:36:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for(int p=1;p<m.size();p++){
      |                 ~^~~~~~~~~
printer.cpp:40:29: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   40 |             if(arr[i].size()<p)
      |                ~~~~~~~~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 600 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 2 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 860 KB Output is correct
2 Correct 14 ms 1320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 1716 KB Output is correct
2 Correct 17 ms 2100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 4008 KB Output is correct
2 Correct 64 ms 5852 KB Output is correct
3 Correct 51 ms 5244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 3252 KB Output is correct
2 Correct 76 ms 7008 KB Output is correct
3 Correct 56 ms 5800 KB Output is correct
4 Correct 69 ms 6684 KB Output is correct