답안 #997457

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
997457 2024-06-12T10:54:16 Z hasan2006 Type Printer (IOI08_printer) C++17
100 / 100
66 ms 5068 KB
#include <bits/stdc++.h>
using namespace std;

#define all(s) s.begin(),s.end()
#define pb push_back
#define ll long long

vector<string>v;
deque<char>d;
vector<char>ans;
string a;

bool cmp(string b , string c){
    int i = 0;
    for(i = 0; i < min(b.size() , c.size()); i++){
        if(b[i] == c[i] && (b[i] == a[i]))
            continue;
        if(b[i] == a[i])
            return 0;
        if(c[i] == a[i])
            return 1;
        return b < c;
    }
    return (b.size() < c.size());
}

void solve()
{
    ll n , i , l , mx = 0;
    cin>>n;
    v.resize(n);
    for(i = 0; i < n; i++){
        cin>>v[i];
        if(v[i].size() > mx)
            mx = v[i].size() , a = v[i];
    }
    sort(all(v) , cmp);
    for(auto to : v){
        for(l  = 0; l < min(to.size(), d.size()); l++)
            if(d[l] != to[l])
                break;
        while(d.size() > l)
            ans.pb('-') , d.pop_back();
        while(l < to.size())
            ans.pb(to[l]) ,d.pb(to[l]) , l++;
        ans.pb('P');
    }
    cout<<ans.size()<<"\n";
    for(auto to : ans)
        cout<<char(to)<<"\n";
}

int main(){
    solve();
}
// Author : حسن

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 'const long unsigned int' [-Wsign-compare]
   15 |     for(i = 0; i < min(b.size() , c.size()); i++){
      |                ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp: In function 'void solve()':
printer.cpp:34:24: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   34 |         if(v[i].size() > mx)
      |            ~~~~~~~~~~~~^~~~
printer.cpp:39:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'const long unsigned int' [-Wsign-compare]
   39 |         for(l  = 0; l < min(to.size(), d.size()); l++)
      |                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:42:24: warning: comparison of integer expressions of different signedness: 'std::deque<char>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   42 |         while(d.size() > l)
      |               ~~~~~~~~~^~~
printer.cpp:44:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         while(l < to.size())
      |               ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 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 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 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 1 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 600 KB Output is correct
2 Correct 10 ms 1112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 1240 KB Output is correct
2 Correct 11 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 2264 KB Output is correct
2 Correct 54 ms 4292 KB Output is correct
3 Correct 44 ms 3280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 2088 KB Output is correct
2 Correct 66 ms 5068 KB Output is correct
3 Correct 48 ms 3796 KB Output is correct
4 Correct 63 ms 4812 KB Output is correct