답안 #870342

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
870342 2023-11-07T13:13:25 Z Essa2006 Type Printer (IOI08_printer) C++14
100 / 100
454 ms 44008 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl '\n'
#define FF first
#define SS second
#define all(a) a.begin(), a.end()
#define mod (ll)(1000000007)
int mp[26];
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n;
    cin>>n;
    vector<string>A(n);
    string a="";
    map<string, bool>mp;
    for(int i=0;i<n;i++){
        cin>>A[i];
        if(A[i].size()>a.size())
            a=A[i];
        mp[A[i]]=1;
    }
    sort(all(A));
    string last="";
    vector<char>Ans;
    for(int f=0;f<a.size();f++){
        for(int i=0;i<n;i++){
            if(mp[A[i]] && (A[i].size()>f && A[i][f]!=a[f])){
                int cur=last.size()-1;
                int same=-1;
                for(int j=0;j<min(last.size(), A[i].size());j++){
                    if(A[i][j]==last[j])
                        same=j;
                    else
                        break;
                }
                while(cur>same)
                    Ans.push_back('-'), cur--, last.pop_back();
                for(int j=same+1;j<A[i].size();j++){
                    Ans.push_back(A[i][j]);
                    last.push_back(A[i][j]);
                    if(mp[last]){
                        Ans.push_back('P');
                        mp[last]=0;
                    }
                }
            }
        }
    }
    int cur=last.size()-1;
    int same=-1;
    for(int j=0;j<min(last.size(), a.size());j++){
        if(a[j]==last[j])
            same=j;
        else
            break;
    }
    while(cur>same)
        Ans.push_back('-'), cur--, last.pop_back();
    for(int j=same+1;j<a.size();j++){
        Ans.push_back(a[j]);
        last.push_back(a[j]);
        if(mp[last]){
            Ans.push_back('P');
            mp[last]=0;
        }
    }
    cout<<Ans.size()<<endl;
    for(int i=0;i<Ans.size();i++){
        cout<<Ans[i]<<endl;
    }
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:26:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int f=0;f<a.size();f++){
      |                 ~^~~~~~~~~
printer.cpp:28:40: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   28 |             if(mp[A[i]] && (A[i].size()>f && A[i][f]!=a[f])){
      |                             ~~~~~~~~~~~^~
printer.cpp:31:30: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   31 |                 for(int j=0;j<min(last.size(), A[i].size());j++){
      |                             ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:39:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |                 for(int j=same+1;j<A[i].size();j++){
      |                                  ~^~~~~~~~~~~~
printer.cpp:52:18: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   52 |     for(int j=0;j<min(last.size(), a.size());j++){
      |                 ~^~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |     for(int j=same+1;j<a.size();j++){
      |                      ~^~~~~~~~~
printer.cpp:69:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |     for(int i=0;i<Ans.size();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 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 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 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 3 ms 712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 860 KB Output is correct
2 Correct 7 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 2652 KB Output is correct
2 Correct 48 ms 5432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 6100 KB Output is correct
2 Correct 45 ms 2140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 162 ms 15032 KB Output is correct
2 Correct 382 ms 36724 KB Output is correct
3 Correct 196 ms 19656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 121 ms 11724 KB Output is correct
2 Correct 454 ms 44008 KB Output is correct
3 Correct 246 ms 22476 KB Output is correct
4 Correct 418 ms 40748 KB Output is correct