답안 #997454

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
997454 2024-06-12T10:50:36 Z hasan2006 Type Printer (IOI08_printer) C++17
100 / 100
68 ms 5584 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){
        l = 0;
        for(i  = 0; i < min(to.size(), d.size()); i++){
            if(d[i] != to[i])
                break;
            l++;
        }
        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:40:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'const long unsigned int' [-Wsign-compare]
   40 |         for(i  = 0; i < min(to.size(), d.size()); i++){
      |                     ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:45:24: warning: comparison of integer expressions of different signedness: 'std::deque<char>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   45 |         while(d.size() > l)
      |               ~~~~~~~~~^~~
printer.cpp:47: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]
   47 |         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 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 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 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 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 14 ms 1112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 2524 KB Output is correct
2 Correct 54 ms 4804 KB Output is correct
3 Correct 56 ms 3696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 2252 KB Output is correct
2 Correct 68 ms 5584 KB Output is correct
3 Correct 50 ms 4560 KB Output is correct
4 Correct 61 ms 5328 KB Output is correct