Submission #337311

# Submission time Handle Problem Language Result Execution time Memory
337311 2020-12-19T16:49:19 Z Giselus Type Printer (IOI08_printer) C++14
100 / 100
221 ms 62720 KB
#include<cstdio>
#include<algorithm>
#include<vector>
#include<iostream>

using namespace std;

vector < vector < int > > L;
vector < int > Q;
vector < bool > odw;
//vector < vector < pair < int , char > > > L2;
vector < int > dp;
void DFS(int x, int r){
    dp[x] = 1;
    for(int i = 0 ; i < 26;i++){
        if(L[x][i] && L[x][i] != r){
            DFS(L[x][i],x);
            dp[x] = max(dp[x],dp[L[x][i]] + 1);
        }
    }
    //printf("%d %d\n",x,dp[x]);
}

void DFS2(int x, int r, bool pisz){
if(odw[x])
    printf("P\n");
bool used = 0;
int last = 0;
for(int i = 0 ; i < 26;i++){
    if(L[x][i] && L[x][i] != r){
        if(!used && pisz == 0 && dp[L[x][i]] + 1 == dp[x]){
            used = 1;
            last = i;
        }else{
            printf("%c\n",i + 'a');
            DFS2(L[x][i],x,1);
        }
    }
}
if(used){
    printf("%c\n",last + 'a');
    DFS2(L[x][last],x,0);
}
if(pisz)
    printf("-\n");

}

int main(void){
int n,m,a,b,c,d,x;
string s;
char ch;
scanf("%d",&n);
L.resize(1);
L[0].resize(26);
odw.push_back(0);
int licznik = 0;
for(int i = 1; i<=n;i++){
    cin >> s;
    b = 0;
    for(int a = 0 ;a < s.size();a++){
        ch = s[a];
        if(L[b][ch-'a']){
            b = L[b][ch-'a'];
        }else{
            licznik++;
            odw.push_back(0);
            L[b][ch-'a'] = licznik;
            L.push_back(Q);
            L[licznik].resize(26);
            b = licznik;
        }
    }
    odw[b] = 1;
}
dp.resize(L.size());
DFS(0,0);
printf("%d\n",2*licznik-dp[0] + n + 1);
DFS2(0,0,0);
return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:61:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for(int a = 0 ;a < s.size();a++){
      |                    ~~^~~~~~~~~~
printer.cpp:50:7: warning: unused variable 'm' [-Wunused-variable]
   50 | int n,m,a,b,c,d,x;
      |       ^
printer.cpp:50:9: warning: unused variable 'a' [-Wunused-variable]
   50 | int n,m,a,b,c,d,x;
      |         ^
printer.cpp:50:13: warning: unused variable 'c' [-Wunused-variable]
   50 | int n,m,a,b,c,d,x;
      |             ^
printer.cpp:50:15: warning: unused variable 'd' [-Wunused-variable]
   50 | int n,m,a,b,c,d,x;
      |               ^
printer.cpp:50:17: warning: unused variable 'x' [-Wunused-variable]
   50 | int n,m,a,b,c,d,x;
      |                 ^
printer.cpp:53:6: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   53 | scanf("%d",&n);
      | ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1260 KB Output is correct
2 Correct 5 ms 1644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 3876 KB Output is correct
2 Correct 28 ms 7968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 9376 KB Output is correct
2 Correct 13 ms 2344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 23184 KB Output is correct
2 Correct 187 ms 52736 KB Output is correct
3 Correct 104 ms 27280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 18076 KB Output is correct
2 Correct 221 ms 62720 KB Output is correct
3 Correct 119 ms 30992 KB Output is correct
4 Correct 183 ms 59264 KB Output is correct