답안 #116911

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
116911 2019-06-14T04:14:42 Z TienDungz Lozinke (COCI17_lozinke) C++14
100 / 100
573 ms 29884 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
int res=0,n;
string t;
vector<string> adj;
unordered_map<string,int> cnt,cnt2;
bool cmp (string a,string b)
{
	return a.length()<b.length();
}
signed main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>t;
		adj.push_back(t);
	}
	sort(adj.begin(),adj.end(),cmp);
	for(int i=0;i<n;i++)
	{
		unordered_map<string,bool> cur;
		for(int k=1;k<=adj[i].length();k++)
		{
			string s;
			for(int j=0;j<=(adj[i].length()-1)-k+1;j++)
			{
				s=adj[i].substr(j,k);
				if(cnt[s]>=1&&cur[s]==false) 
				{
					res+=cnt[s];
					cur[s]=true;
				}
			}
		}
		cnt[adj[i]]++;
	}
	for(int i=n-1;i>=0;i--)
	{
		unordered_map<string,bool> cur;
		for(int k=1;k<=adj[i].length();k++)
		{
			string s;
			for(int j=0;j<=(adj[i].length()-1)-k+1;j++)
			{
				s=adj[i].substr(j,k);
				if(cur[s]==false) 
				{
					res+=cnt2[s];
					cur[s]=true;
				}
			}
		}
		cnt2[adj[i]]++;
	}
	cout<<res;
}

Compilation message

lozinke.cpp: In function 'int main()':
lozinke.cpp:24:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int k=1;k<=adj[i].length();k++)
               ~^~~~~~~~~~~~~~~~~
lozinke.cpp:27:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=0;j<=(adj[i].length()-1)-k+1;j++)
                ~^~~~~~~~~~~~~~~~~~~~~~~~~
lozinke.cpp:42:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int k=1;k<=adj[i].length();k++)
               ~^~~~~~~~~~~~~~~~~
lozinke.cpp:45:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=0;j<=(adj[i].length()-1)-k+1;j++)
                ~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 4 ms 512 KB Output is correct
5 Correct 13 ms 1024 KB Output is correct
6 Correct 35 ms 1024 KB Output is correct
7 Correct 28 ms 2552 KB Output is correct
8 Correct 39 ms 3960 KB Output is correct
9 Correct 114 ms 4208 KB Output is correct
10 Correct 196 ms 13520 KB Output is correct
11 Correct 181 ms 7536 KB Output is correct
12 Correct 573 ms 29884 KB Output is correct
13 Correct 249 ms 4216 KB Output is correct
14 Correct 389 ms 27416 KB Output is correct
15 Correct 503 ms 29596 KB Output is correct
16 Correct 244 ms 1528 KB Output is correct
17 Correct 146 ms 1528 KB Output is correct
18 Correct 114 ms 1528 KB Output is correct
19 Correct 318 ms 15144 KB Output is correct
20 Correct 177 ms 1528 KB Output is correct