Submission #799100

# Submission time Handle Problem Language Result Execution time Memory
799100 2023-07-31T09:41:29 Z yeediot Type Printer (IOI08_printer) C++14
10 / 100
60 ms 2920 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pb push_back
#define sz(x) (int)(x.size())
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define vi vector<int>
#define vp vector<pii>
#define vvi vector<vi>
const int mxn=25005;
const int mxlen=21;
const int mul=9973;
const int mod=1e9+7;
int h[mxn][mxlen];
int p[mxlen];
void hsh(string s,int id){
    for(int i=0;i<sz(s);i++){
        h[id][i+1]=((h[id][i]*mul)%mod+(s[i]-'a'+1))%mod;
    }
}
int get(int a,int b,int id){
    return ((h[id][b+1]-(h[id][a]*p[b-a+1])%mod)+mod)%mod;
}
bool cmp(pair<string,int> a,pair<string,int> b){
    if(sz(a.F)!=sz(b.F)){
        return sz(a.F)<sz(b.F);
    }
    int l=0,r=sz(a.F)-1;
    while(l<r){
        int mm=l+r+1>>1;
        if(get(0,mm,a.S)==get(0,mm,b.S)){
            l=mm;
        }
        else{
            r=mm-1;
        }
    }
    if(l==sz(a.F)-1){
        return true;
    }
    return a.F[l+1]<b.F[l+1];
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    vector<pair<string,int>>s;
    for(int i=0;i<n;i++){
        string temp;
        cin>>temp;
        s.pb({temp,i});
    }
    for(int i=0;i<20;i++){
        p[i+1]=(p[i]*mul)%mod;
    }
    sort(all(s),cmp);
    string now="";
    vector<char>op;
    for(int i=0;i<n;i++){
        while(sz(now)>sz(s[i].F)){
            now.pop_back();
            op.pb('-');
        }
        while(sz(now) and now!=s[i].F.substr(0,sz(now))){
            now.pop_back();
            op.pb('-');
        }
        while(sz(now)<sz(s[i].F)){
            now+=s[i].F[sz(now)];
            op.pb(s[i].F[sz(now)-1]);
        }op.pb('P');
    }cout<<sz(op)<<'\n';
    for(auto i:op){
        cout<<i<<'\n';
    }
}
 /*
 input:
 
 */

Compilation message

printer.cpp: In function 'bool cmp(std::pair<std::__cxx11::basic_string<char>, long long int>, std::pair<std::__cxx11::basic_string<char>, long long int>)':
printer.cpp:35:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |         int mm=l+r+1>>1;
      |                ~~~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 324 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 596 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 724 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 1024 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 22 ms 1420 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 2444 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 60 ms 2920 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -