# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
314323 | 2020-10-19T17:14:04 Z | ShiftyBlock | Type Printer (IOI08_printer) | C++17 | 1000 ms | 2992 KB |
#include <bits/stdc++.h> using namespace std; #define f first #define s second #define pii pair<int, int> #define long long long #define v vector #define rep(i,a,b) for(int i=a; i<b; i++) void setIO(string name, int submit) { if (submit) { ios_base::sync_with_stdio(0); cin.tie(0); freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } else{ ios_base::sync_with_stdio(0); cin.tie(0); } } string longest; bool compare(string a, string b){ int samea=0; int sameb=0; rep(j,0, a.size()){ if(longest[j]==a[j]) samea++; else break; } rep(j,0, b.size()){ if(longest[j]==b[j]) sameb++; else break; } if(samea==sameb){ int cmp= a.compare(b); if(cmp<0) return true; else return false; } return samea<sameb; } int main() { setIO("printer", 0); int N; cin>>N; v<string> arr; for (int i = 0; i < N; ++i) { string line; cin>>line; arr.push_back(line); } sort(arr.begin(), arr.end()); int basecost=0; int worst=0; rep(i,0,N){ int len=arr[i].size();int plen=arr[i-1].size(); if(arr[worst].size()<len){ worst=i; } if(i==0){ basecost+=len; } else{ basecost+=plen; int same=0; rep(j,0, min(plen, len)){ if(arr[i-1][j]==arr[i][j]) same++; else break; } basecost-=same; basecost+=len-same; } } longest=arr[worst]; cout<<basecost+arr.size()+arr[arr.size()-1].size()-arr[worst].size()<<endl; sort(arr.begin(), arr.end(), compare); rep(i, 0,N){ int len=arr[i].size(); int plen=arr[i-1].size(); if(i==0){ rep(j,0,len){ cout<<arr[i][j]<<endl; } cout<<"P"<<endl; } else{ int same=0; rep(j,0, min(plen,len)){ if(arr[i-1][j]==arr[i][j]) same++; else break; } rep(j,0, plen-same) { cout<<"-"<<endl; } rep(j,same, len){ cout<<arr[i][j]<<endl; } cout<<"P"<<endl; } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 1 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 384 KB | Output is correct |
2 | Correct | 17 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 31 ms | 384 KB | Output is correct |
2 | Correct | 40 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 116 ms | 656 KB | Output is correct |
2 | Correct | 254 ms | 920 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 304 ms | 1184 KB | Output is correct |
2 | Correct | 105 ms | 1176 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 767 ms | 1828 KB | Output is correct |
2 | Execution timed out | 1044 ms | 2796 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 637 ms | 1772 KB | Output is correct |
2 | Execution timed out | 1050 ms | 2992 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |