답안 #957569

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
957569 2024-04-04T04:06:51 Z hirayuu_oj Type Printer (IOI08_printer) C++17
100 / 100
49 ms 7880 KB
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,a,b) for(int i=a; i<(b); i++)
#define all(x) x.begin(),x.end()
using ll=long long;
const int INF=INT_MAX>>1;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<string> s(n);
    rep(i,n){
        cin>>s[i];
    }
    string mx="";
    rep(i,n){
        if(mx.size()<s[i].size()){
            mx=s[i];
        }
    }
    vector<pair<int,string>> ns(n);
    rep(i,n){
        ns[i].second=s[i];
        ns[i].first=0;
        rep(j,s[i].size()){
            if(s[i][j]==mx[j]){
                ns[i].first++;
            }
            else{
                break;
            }
        }
    }
    sort(all(ns));
    rep(i,n){
        s[i]=ns[i].second;
    }
    vector<char> ans;
    for(char i:s[0]){
        ans.push_back(i);
    }
    ans.push_back('P');
    rep(i,n-1){
        ll ng=0;
        rep(j,min(s[i].size(),s[i+1].size())){
            if(s[i][j]==s[i+1][j]){
                ng++;
            }
            else{
                break;
            }
        }
        rep(j,s[i].size()-ng){
            ans.push_back('-');
        }
        rep2(j,ng,s[i+1].size()){
            ans.push_back(s[i+1][j]);
        }
        ans.push_back('P');
    }
    std::cout<<ans.size()<<"\n";
    for(char i:ans){
        std::cout<<i<<"\n";
    }
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:3:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    3 | #define rep(i,n) for(int i=0; i<(n); i++)
      |                                ^
printer.cpp:28:9: note: in expansion of macro 'rep'
   28 |         rep(j,s[i].size()){
      |         ^~~
printer.cpp:3:32: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
    3 | #define rep(i,n) for(int i=0; i<(n); i++)
      |                                ^
printer.cpp:48:9: note: in expansion of macro 'rep'
   48 |         rep(j,min(s[i].size(),s[i+1].size())){
      |         ^~~
printer.cpp:3:32: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
    3 | #define rep(i,n) for(int i=0; i<(n); i++)
      |                                ^
printer.cpp:56:9: note: in expansion of macro 'rep'
   56 |         rep(j,s[i].size()-ng){
      |         ^~~
printer.cpp:4:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 | #define rep2(i,a,b) for(int i=a; i<(b); i++)
      |                                   ^
printer.cpp:59:9: note: in expansion of macro 'rep2'
   59 |         rep2(j,ng,s[i+1].size()){
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 452 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 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 516 KB Output is correct
2 Correct 0 ms 456 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 1 ms 600 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 856 KB Output is correct
2 Correct 7 ms 1368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1748 KB Output is correct
2 Correct 6 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 3528 KB Output is correct
2 Correct 34 ms 6608 KB Output is correct
3 Correct 26 ms 5588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 3168 KB Output is correct
2 Correct 41 ms 7880 KB Output is correct
3 Correct 29 ms 6360 KB Output is correct
4 Correct 49 ms 7528 KB Output is correct