답안 #237247

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
237247 2020-06-05T12:42:07 Z wildturtle Type Printer (IOI08_printer) C++17
100 / 100
108 ms 24816 KB
#include<bits/stdc++.h>
using namespace std;
long long n,k,maxx,idx;
pair < long long, string > A[500005];
char s1[22],s[25004][22];
vector < char> v;
int main() {
           ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
           scanf("%d" , &n);
           for(long long i=1;i<=n;i++) {
                      scanf("%s" , s[i]);
                      if(maxx<strlen(s[i])) { maxx=strlen(s[i]); idx=i; }
           }
           for(long long i=0;i<strlen(s[idx]);i++)
           s1[i]=s[idx][i];
           for(long long i=1;i<=n;i++) {
                      A[i].second=s[i]; k=0;
                      for(long long j=0;j<strlen(s[i]);j++)
                      if(s[i][j]!=s1[j]) break;
                      else k++;
                      A[i].first=k;
           }
           sort(A+1,A+1+n);
           idx=0;
           for(long long i=1;i<=n;i++) {
                      for(long long j=idx;j<A[i].second.size();j++)
                      v.push_back(A[i].second[j]);
                      v.push_back('P');
                      if(i==n) break;
                      idx=A[i].second.size();
                      for(long long j=0;j<A[i].second.size();j++) {
                                 if(A[i].second[j]!=A[i+1].second[j]) { idx=j; break; }
                      }
                      for(long long j=idx;j<A[i].second.size();j++)
                      v.push_back('-');
           }
           printf("%d\n" , v.size());
           for(long long i=0;i<v.size();i++)
           printf("%c\n" , v[i]);
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:9:27: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
            scanf("%d" , &n);
                         ~~^
printer.cpp:12:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                       if(maxx<strlen(s[i])) { maxx=strlen(s[i]); idx=i; }
                          ~~~~^~~~~~~~~~~~~
printer.cpp:14:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
            for(long long i=0;i<strlen(s[idx]);i++)
                              ~^~~~~~~~~~~~~~~
printer.cpp:18:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                       for(long long j=0;j<strlen(s[i]);j++)
                                         ~^~~~~~~~~~~~~
printer.cpp:26:44: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                       for(long long j=idx;j<A[i].second.size();j++)
                                           ~^~~~~~~~~~~~~~~~~~~
printer.cpp:31:42: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                       for(long long j=0;j<A[i].second.size();j++) {
                                         ~^~~~~~~~~~~~~~~~~~~
printer.cpp:34:44: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                       for(long long j=idx;j<A[i].second.size();j++)
                                           ~^~~~~~~~~~~~~~~~~~~
printer.cpp:37:36: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<char>::size_type {aka long unsigned int}' [-Wformat=]
            printf("%d\n" , v.size());
                            ~~~~~~~~^
printer.cpp:38:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
            for(long long i=0;i<v.size();i++)
                              ~^~~~~~~~~
printer.cpp:9:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
            scanf("%d" , &n);
            ~~~~~^~~~~~~~~~~
printer.cpp:11:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
                       scanf("%s" , s[i]);
                       ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 19968 KB Output is correct
2 Correct 15 ms 19916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 19968 KB Output is correct
2 Correct 15 ms 19968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 19968 KB Output is correct
2 Correct 15 ms 19968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 19840 KB Output is correct
2 Correct 16 ms 19840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 19968 KB Output is correct
2 Correct 16 ms 19968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 19968 KB Output is correct
2 Correct 19 ms 20096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 20224 KB Output is correct
2 Correct 28 ms 20608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 20736 KB Output is correct
2 Correct 25 ms 20480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 21616 KB Output is correct
2 Correct 82 ms 23660 KB Output is correct
3 Correct 55 ms 23152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 21364 KB Output is correct
2 Correct 108 ms 24432 KB Output is correct
3 Correct 63 ms 23540 KB Output is correct
4 Correct 98 ms 24816 KB Output is correct