Submission #57763

# Submission time Handle Problem Language Result Execution time Memory
57763 2018-07-16T03:24:25 Z gnoor Type Printer (IOI08_printer) C++17
40 / 100
384 ms 16360 KB
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>

using namespace std;

vector<string> tbl;
vector<char> ans;
map<string,int> mp;

bool cmp(const string &a ,const string &b) {
	string x;
	int cur=0;
	while (a[cur]==b[cur]) {
		x.push_back(a[cur]);
		cur++;		
	}
	string y=x;
	x.push_back(a[cur]);
	y.push_back(b[cur]);
	//cout << x << " " << y << " " << mp[x] << " " << mp[y] << endl;
	return mp[x]<mp[y];
}

int main () {
	int n;
	scanf("%d",&n);
	string x;
	string y;
	for (int i=0;i<n;i++) {
		cin >> x;
		tbl.push_back(x);
		y.clear();
		for (int j=0;j<(int)x.size();j++) {
			y.push_back(x[j]);
			mp[y]=max(mp[y],(int)x.size());
		}
	}
	sort(tbl.begin(),tbl.end(),cmp);
	for (int i=0;i<(int)tbl[0].size();i++) {
		ans.push_back(tbl[0][i]);
	}
	ans.push_back('P');
	for (int i=1;i<n;i++) {
		int cnt=0;
		while (tbl[i][cnt]==tbl[i-1][cnt]) cnt++;
		for (int j=0;j<(int)tbl[i-1].size()-cnt;j++) {
			ans.push_back('-');
		}
		for (int j=cnt;j<(int)tbl[i].size();j++) {
			ans.push_back(tbl[i][j]);
		}
		ans.push_back('P');
	}
	printf("%d\n",ans.size());
	for (int i=0;i<(int)ans.size();i++) {
		printf("%c\n",ans[i]);
	}
	return 0;
}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:58:26: 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",ans.size());
                ~~~~~~~~~~^
printer.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 492 KB Output is correct
2 Correct 3 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 508 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 592 KB Output is correct
2 Correct 3 ms 592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 1272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 49 ms 3016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 147 ms 6832 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 384 ms 16360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 384 ms 16360 KB Output isn't correct
2 Halted 0 ms 0 KB -