Submission #236402

# Submission time Handle Problem Language Result Execution time Memory
236402 2020-06-01T23:22:26 Z nickmet2004 Type Printer (IOI08_printer) C++11
0 / 100
678 ms 3448 KB
#include<bits/stdc++.h>

using namespace std;

const int N = 25005;

int n;
string s[N];
vector<string> groups[26];
int mx = 0 , id = -1, gr_id = -1;
int pr[30][N];
char ans[20 * N];

int main (){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; ++i) cin >> s[i];
    sort(s , s + n);
    for(int i = 0; i < n; ++i) groups[(int)(s[i][0] - 'a')].emplace_back(s[i]);
    for(int i = 0; i < 26; ++i){
        if(!groups[i].size()) continue;
        for(int j = 0; j < groups[i].size(); ++j){
            if(groups[i][j].size() > mx){
                mx = groups[i][j].size(); id = j; gr_id = i;
            }
        }
    }
    //cerr << groups[gr_id][id] << " " << endl;
    int cnt = 0;
    int P = 0;
    for(int i = 0; i < 26; ++i){
        if(!groups[i].size()) continue;
        if(groups[i].size() == 1 && i != gr_id){
            cnt += groups[i][0].size()*2;
            for(int k = 0; k < groups[i][0].size(); ++k){
                ans[P] = groups[i][0][k];
                ++P;
            }ans[P] = 'P'; P++;
            for(int k = 0; k < groups[i][0].size(); ++k){ans[P] = '-'; ++P;}
            continue;
        }
        string prev = groups[i][0];
        cnt += prev.size();
        if(i != gr_id){for(int k = 0; k < prev.size(); ++k) {ans[P] = prev[k]; ++P;}}
        //for(int k = 0; k < prev.size(); ++k)
        for(int j = 1; j < groups[i].size(); ++j){
            string cur = groups[i][j];
            //int pr = 0;
            for(int k = 0; k < min(prev.size() , cur.size()); ++k){
                if(prev[k] != cur[k]) break;
                pr[i][j]++;
            }
            cnt += prev.size() - pr[i][j] + cur.size() - pr[i][j];
            ///
            if(i != gr_id){
                for(int k = 1; k <= prev.size() - pr[i][j]; ++k) {ans[P] = '-'; ++P;}
                for(int k  = 0; k < cur.size() - pr[i][j]; ++k){ans[P] = cur[k + pr[i][j]]; ++P;}
                ans[P] = 'P'; P++;
            }
            ///
            prev = cur;
        }
        cnt += prev.size();
    }
    cnt -= groups[gr_id][id].size(); cnt += n;
    cout << cnt << endl;
    if(groups[gr_id].size() == 1){
        for(int k = 0; k < groups[gr_id][0].size(); ++k){
            ans[P] = groups[gr_id][0][k];
            ++P;
        } ans[P] = 'P'; ++P;
        for(int k = 0; k < groups[gr_id][0].size(); ++k){ans[P] = '-'; ++P;}

    } else {
        string prev = "";
        if(groups[gr_id].size() > id + 1) prev = groups[gr_id][id + 1];
        for(int k = 0; k < prev.size(); ++k) {ans[P] = prev[k]; ++P;}
        //ans[P] = 'P'; ++P;
        for(int j = id + 2; j < groups[gr_id].size(); ++ j){
            string cur= groups[gr_id][j];
            for(int k = 1;k <= prev.size() - pr[gr_id][j]; ++k){ans[P] = '-'; ++P;}
            for(int k = 0; k < cur.size() - pr[gr_id][j]; ++k){ans[P] = cur[k + pr[gr_id][j]]; ++P;}
            ans[P] = 'P'; ++P;
            prev = cur;
        }
        prev = groups[gr_id][0];
        for(int k = 0; k < prev.size(); ++k) {ans[P] = prev[k]; ++P;}
        ans[P] = 'P'; ++P;
        for(int j = 1; j <= id; ++j){
            string cur = groups[gr_id][j];
            for(int k = 1; k <= prev.size() - pr[gr_id][j]; ++k) {ans[P] = '-'; ++P;}
            for(int k  = 0; k < cur.size() - pr[gr_id][j]; ++k){ans[P] = cur[k + pr[gr_id][j]]; ++P;}
            ans[P] = 'P'; ++P;
            prev = cur;
        }
    }
    for(int i = 0; i < P; ++i) cout << ans[i] << endl;

return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:23:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0; j < groups[i].size(); ++j){
                        ~~^~~~~~~~~~~~~~~~~~
printer.cpp:24:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(groups[i][j].size() > mx){
                ~~~~~~~~~~~~~~~~~~~~^~~~
printer.cpp:36:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int k = 0; k < groups[i][0].size(); ++k){
                            ~~^~~~~~~~~~~~~~~~~~~~~
printer.cpp:40:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int k = 0; k < groups[i][0].size(); ++k){ans[P] = '-'; ++P;}
                            ~~^~~~~~~~~~~~~~~~~~~~~
printer.cpp:45:41: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(i != gr_id){for(int k = 0; k < prev.size(); ++k) {ans[P] = prev[k]; ++P;}}
                                       ~~^~~~~~~~~~~~~
printer.cpp:47:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 1; j < groups[i].size(); ++j){
                        ~~^~~~~~~~~~~~~~~~~~
printer.cpp:50:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int k = 0; k < min(prev.size() , cur.size()); ++k){
                            ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:57:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(int k = 1; k <= prev.size() - pr[i][j]; ++k) {ans[P] = '-'; ++P;}
                                ~~^~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:58:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 for(int k  = 0; k < cur.size() - pr[i][j]; ++k){ans[P] = cur[k + pr[i][j]]; ++P;}
                                 ~~^~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:69:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int k = 0; k < groups[gr_id][0].size(); ++k){
                        ~~^~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:73:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int k = 0; k < groups[gr_id][0].size(); ++k){ans[P] = '-'; ++P;}
                        ~~^~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:77:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(groups[gr_id].size() > id + 1) prev = groups[gr_id][id + 1];
            ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
printer.cpp:78:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int k = 0; k < prev.size(); ++k) {ans[P] = prev[k]; ++P;}
                        ~~^~~~~~~~~~~~~
printer.cpp:80:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = id + 2; j < groups[gr_id].size(); ++ j){
                             ~~^~~~~~~~~~~~~~~~~~~~~~
printer.cpp:82:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int k = 1;k <= prev.size() - pr[gr_id][j]; ++k){ans[P] = '-'; ++P;}
                           ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:83:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int k = 0; k < cur.size() - pr[gr_id][j]; ++k){ans[P] = cur[k + pr[gr_id][j]]; ++P;}
                            ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:88:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int k = 0; k < prev.size(); ++k) {ans[P] = prev[k]; ++P;}
                        ~~^~~~~~~~~~~~~
printer.cpp:92:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int k = 1; k <= prev.size() - pr[gr_id][j]; ++k) {ans[P] = '-'; ++P;}
                            ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:93:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int k  = 0; k < cur.size() - pr[gr_id][j]; ++k){ans[P] = cur[k + pr[gr_id][j]]; ++P;}
                             ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1152 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1152 KB Expected EOF
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1152 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1152 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 1280 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 1408 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 105 ms 1708 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 271 ms 2168 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 678 ms 3448 KB printed invalid word
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 524 ms 3200 KB printed invalid word
2 Halted 0 ms 0 KB -