답안 #116860

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
116860 2019-06-14T02:55:47 Z MrUnknown Lozinke (COCI17_lozinke) C++11
90 / 100
1000 ms 15288 KB
//#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
//#define f_(i,a,b) for (int i=a;i>=b;i--)
//#define f(i,a,b) for (int i=a;i<=b;i++)

int n;
string s[20005];
long long dem=0;
unordered_map<string,bool> mb;
unordered_map<string,ll> m;
bool ss(int x,int y) {
	if (s[x].size()>s[y].size()) return false;
	if (s[x].size()<s[y].size()) return true;
	for (int i=0;i<s[x].size();i++) {
		if (s[x][i]>s[y][i]) return false;
		if (s[x][i]<s[y][i]) return true;
	}
	return true;
}
void xot(int l,int r) {
	if (l>=r) return ;
	int pos;
	pos=l;
	string si;
	for (int i=l;i<r;i++) {
		if (ss(i,r)) {
			si=s[i];
			s[i]=s[pos];
			s[pos]=si;
			pos++;
		}
	}
	si=s[r];
	s[r]=s[pos];
	s[pos]=si;
	xot(l,pos-1);
	xot(pos+1,r);
}
int main() {
//	freopen("","r",stdin);
//	freopen("","w",stdout);
	scanf("%d", &n);
	for (int i=1;i<=n;i++) {
		cin>>s[i];
	}
	xot(1,n);
	for (int i=1;i<=n;i++) {
		mb.clear();
		for (int j=0;j<s[i].size();j++) {
			string si;
			for (int l=j;l<s[i].size();l++) {
				si=si+s[i][l];
				if (!mb[si]) {
					mb[si]=true;
					dem+=m[si];
				}
			}
		}
		dem+=m[s[i]];
		m[s[i]]++;
	}
	printf("%lld", dem);
	return 0;
}

Compilation message

lozinke.cpp: In function 'bool ss(int, int)':
lozinke.cpp:16:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i=0;i<s[x].size();i++) {
               ~^~~~~~~~~~~~
lozinke.cpp: In function 'int main()':
lozinke.cpp:51:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int j=0;j<s[i].size();j++) {
                ~^~~~~~~~~~~~
lozinke.cpp:53:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int l=j;l<s[i].size();l++) {
                 ~^~~~~~~~~~~~
lozinke.cpp:44:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1024 KB Output is correct
2 Correct 3 ms 1024 KB Output is correct
3 Correct 3 ms 1024 KB Output is correct
4 Correct 3 ms 1024 KB Output is correct
5 Correct 8 ms 1280 KB Output is correct
6 Correct 11 ms 1280 KB Output is correct
7 Correct 14 ms 2048 KB Output is correct
8 Correct 20 ms 2688 KB Output is correct
9 Correct 53 ms 2680 KB Output is correct
10 Correct 109 ms 7304 KB Output is correct
11 Correct 89 ms 4264 KB Output is correct
12 Correct 254 ms 15288 KB Output is correct
13 Correct 135 ms 2552 KB Output is correct
14 Correct 203 ms 13984 KB Output is correct
15 Correct 266 ms 14904 KB Output is correct
16 Correct 252 ms 1092 KB Output is correct
17 Execution timed out 1067 ms 1392 KB Time limit exceeded
18 Execution timed out 1064 ms 1608 KB Time limit exceeded
19 Correct 162 ms 7940 KB Output is correct
20 Correct 100 ms 1056 KB Output is correct