답안 #957566

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
957566 2024-04-04T03:38:05 Z hirayuu_oj Type Printer (IOI08_printer) C++17
40 / 100
39 ms 9040 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];
    }
    sort(all(s));
    rep(i,n){
        s.push_back(s[i]);
    }
    rep(i,n){
        s.push_back(s[i]);
    }
    vector<char> fin;
    rep(_,2){
        int mx=-INF;
        int pos=0;
        rep(i,n){
            ll ng=0;
            rep(j,min(s[i].size(),s[i+1].size())){
                if(s[i][j]==s[i+1][j]){
                    ng++;
                }
                else{
                    break;
                }
            }
            int now=(s[i].size()+s[i+1].size()-ng*2)-s[i+1].size();
            if(mx<now){
                mx=now;
                pos=i+1;
            }
        }
        vector<char> ans;
        for(char i:s[pos]){
            ans.push_back(i);
        }
        ans.push_back('P');
        rep2(i,pos,pos+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');
        }
        if(fin.size()==0 or fin.size()>=ans.size()){
            fin=ans;
        }
        reverse(all(s));
    }
    cout<<fin.size()<<"\n";
    for(char i:fin){
        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 'const long unsigned int' [-Wsign-compare]
    3 | #define rep(i,n) for(int i=0; i<(n); i++)
      |                                ^
printer.cpp:31:13: note: in expansion of macro 'rep'
   31 |             rep(j,min(s[i].size(),s[i+1].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:52:13: note: in expansion of macro 'rep'
   52 |             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:60:13: note: in expansion of macro 'rep'
   60 |             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:63:13: note: in expansion of macro 'rep2'
   63 |             rep2(j,ng,s[i+1].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 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1080 KB Output is correct
2 Incorrect 7 ms 1576 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 2060 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 4288 KB Output is correct
2 Correct 39 ms 9040 KB Output is correct
3 Incorrect 25 ms 7244 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 4396 KB Output isn't correct
2 Halted 0 ms 0 KB -