답안 #314367

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
314367 2020-10-19T18:42:13 Z ShiftyBlock Type Printer (IOI08_printer) C++17
0 / 100
21 ms 4592 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);
        cout.tie(0);
    }
    
}
pair<int, string> arr[25001];
char s[25001][21];
int main() {
    setIO("printer", 0);
 
    int N;
    scanf("%d", &N);
    v<int> sim; sim.push_back(0);
    int worst=0;
    for (int i = 0; i < N; ++i)
    {
    	scanf("%s",s[i]);
    	if(strlen(s[worst])<strlen(s[i])){
    		worst=i;
    	}
    }
    rep(i,0,N){
    	int same=0;
    	rep(j,0, strlen(s[i])){
    		if(s[worst][j]==s[i][j]) same++;
    		else break;
    	}
    	arr[i]= make_pair( same, s[i]);
    }
	sort(arr,arr+N );
 	v<char> res;
    rep(i, 0,N){
    	int len=arr[i].s.size();
    	int plen=arr[i-1].s.size();
    	//cout<<arr[i].f<<endl;
    	if(i==0){
    		rep(j,0,len){
    			res.push_back(arr[i].s[j]);
    		}
    		res.push_back('P');
    	}
    	else{
    		int same=0;
    		rep(j,0,min(len,plen)){
    			if(arr[i].s[j]!=arr[i-1].s[j]) break;
    			same++;
    		}
    		rep(j,0, plen-same) {
    			res.push_back('-');
    		}
    		rep(j,same, len){
    			res.push_back(arr[i].s[j]);
    		}
    		res.push_back('P');
    	}
    	
    }
    printf("%d\n", res.size());
    for(char x: res){
    	printf("%s\n", x);
    }
    return 0;
}
 
 

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:8:34: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
    8 | #define rep(i,a,b) for(int i=a; i<b; i++)
......
   41 |      rep(j,0, strlen(s[i])){
      |          ~~~~~~~~~~~~~~~~~        
printer.cpp:41:6: note: in expansion of macro 'rep'
   41 |      rep(j,0, strlen(s[i])){
      |      ^~~
printer.cpp:75:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wformat=]
   75 |     printf("%d\n", res.size());
      |             ~^     ~~~~~~~~~~
      |              |             |
      |              int           std::vector<char>::size_type {aka long unsigned int}
      |             %ld
printer.cpp:77:15: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'int' [-Wformat=]
   77 |      printf("%s\n", x);
      |              ~^     ~
      |               |     |
      |               char* int
      |              %d
printer.cpp: In function 'void setIO(std::string, int)':
printer.cpp:13:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   13 |         freopen((name + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:14:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   14 |         freopen((name + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   29 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
printer.cpp:34:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |      scanf("%s",s[i]);
      |      ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 2432 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 2432 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 2432 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 2432 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 2432 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 2592 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 2816 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 11 ms 3488 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 21 ms 4592 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 21 ms 4348 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -