Submission #151328

# Submission time Handle Problem Language Result Execution time Memory
151328 2019-09-02T13:11:38 Z GioChkhaidze Type Printer (IOI08_printer) C++14
100 / 100
105 ms 7740 KB
#include <bits/stdc++.h>

#define F first
#define S second

using namespace std;

int n,Con[25005],Cs,M;
string s[25005];
char C[2500100];

pair < int , string > P[25005];

main () {
    cin>>n;

    for (int i=1; i<=n; i++) {
        cin>>s[i];
        if (i==1) M=1;
            else
        if (s[i].size()>s[M].size()) M=i;
    }

    for (int i=1; i<=n; i++) {
        int x=s[i].size(),y=s[M].size();
        for (int j=0; j<min(x,y); j++) {
            if (s[i][j]==s[M][j]) P[i].F++;
                              else break;
        }

        P[i].S=s[i];
    }

    sort(P+1,P+n+1);

    for (int i=2; i<=n; i++) {
        int x=P[i].S.size(),y=P[i].S.size();
        for (int j=0; j<min(x,y); j++) {
            if (P[i].S[j]==P[i-1].S[j]) Con[i]++;
                else break;
        }
    }

    for (int i=1; i<=n; i++) {
        for (int j=Con[i]; j<P[i].S.size(); j++)
            C[++Cs]=P[i].S[j];

        C[++Cs]='P';

        if (i!=n)
            for (int j=Con[i+1]; j<P[i].S.size(); j++)
                C[++Cs]='-';
    }

    printf("%d\n",Cs);

    for (int i=1; i<=Cs; i++)
        printf("%c\n",C[i]);
}

Compilation message

printer.cpp:14:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
printer.cpp: In function 'int main()':
printer.cpp:45:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j=Con[i]; j<P[i].S.size(); j++)
                            ~^~~~~~~~~~~~~~
printer.cpp:51:35: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int j=Con[i+1]; j<P[i].S.size(); j++)
                                  ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2168 KB Output is correct
2 Correct 3 ms 2168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2040 KB Output is correct
2 Correct 4 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2168 KB Output is correct
2 Correct 4 ms 2168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2040 KB Output is correct
2 Correct 4 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2040 KB Output is correct
2 Correct 5 ms 2168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2168 KB Output is correct
2 Correct 6 ms 2168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 2296 KB Output is correct
2 Correct 19 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 2552 KB Output is correct
2 Correct 23 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 3596 KB Output is correct
2 Correct 88 ms 6844 KB Output is correct
3 Correct 68 ms 5880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 2940 KB Output is correct
2 Correct 105 ms 7740 KB Output is correct
3 Correct 77 ms 6392 KB Output is correct
4 Correct 95 ms 7672 KB Output is correct