Submission #199995

# Submission time Handle Problem Language Result Execution time Memory
199995 2020-02-04T17:17:09 Z davitmarg Cubeword (CEOI19_cubeword) C++17
84 / 100
1100 ms 30280 KB
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <stack>
#include <cassert>
#include <iterator>
#include <bitset>
#include <fstream>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(),v.end()
using namespace std;
 
 
LL ml(LL a,LL b)
{
	return (a*b)%mod;
}
 
int N;
 
int n;
string s;
vector<string> str;
vector<char> chars;
char id;
map<char,char> newchar;
map<string,bool> used;
 
LL p[12][70][70],dp[12][70][70][70],ans;
 
int main()
{
	cin>>n;
	while(n--)
	{
		cin>>s;
		str.PB(s);
		while(!s.empty())
		{
			chars.PB(s.back());
			s.pop_back();	
		}
	}
 
 
	id=0;
	sort(all(chars));
	for(int i=0;i<chars.size();i++)
		if(!i || chars[i]!=chars[i-1])
			newchar[chars[i]]=id++;
 
	N=id;
	id--;
 
	while(!str.empty())
	{
		s=str.back();
		str.pop_back();
		for(int i=0;i<s.size();i++)
			s[i]=newchar[s[i]];
		
		if(!used[s])
		{
			p[s.length()][s[0]][s.back()]++;
			used[s]=1;
		}
		reverse(all(s));
		if(!used[s])
		{
			p[s.length()][s[0]][s.back()]++;
			used[s]=1;
		}
	}
 
	for(int len=1;len<=10;len++)
	{
		for(int i=0;i<N;i++)
			for(int a=0;a<N;a++)
				for(int b=0;b<N;b++)
					for(int c=0;c<N;c++)
					{
						dp[len][a][b][c]+=ml(p[len][i][a],ml(p[len][i][b],p[len][i][c]));
						dp[len][a][b][c]%=mod;
					}
 
		for(int a=0;a<N;a++)
			for(int b=0;b<N;b++)
				for(int c=0;c<N;c++)
					for(int d=0;d<N;d++)
					{
						ans+=ml(dp[len][a][b][c],ml(dp[len][a][b][d],ml(dp[len][a][d][c],dp[len][d][b][c])));
						ans%=mod;
					}
	}
	cout<<ans<<endl;
	return 0;
}

Compilation message

cubeword.cpp: In function 'int main()':
cubeword.cpp:60:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<chars.size();i++)
              ~^~~~~~~~~~~~~
cubeword.cpp:71:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i=0;i<s.size();i++)
               ~^~~~~~~~~
cubeword.cpp:76:22: warning: array subscript has type 'char' [-Wchar-subscripts]
    p[s.length()][s[0]][s.back()]++;
                      ^
cubeword.cpp:76:32: warning: array subscript has type 'char' [-Wchar-subscripts]
    p[s.length()][s[0]][s.back()]++;
                                ^
cubeword.cpp:82:22: warning: array subscript has type 'char' [-Wchar-subscripts]
    p[s.length()][s[0]][s.back()]++;
                      ^
cubeword.cpp:82:32: warning: array subscript has type 'char' [-Wchar-subscripts]
    p[s.length()][s[0]][s.back()]++;
                                ^
# Verdict Execution time Memory Grader output
1 Correct 407 ms 20192 KB Output is correct
2 Correct 406 ms 20188 KB Output is correct
3 Correct 422 ms 20288 KB Output is correct
4 Correct 394 ms 20064 KB Output is correct
5 Correct 408 ms 20288 KB Output is correct
6 Correct 400 ms 20060 KB Output is correct
7 Correct 426 ms 20188 KB Output is correct
8 Correct 398 ms 20060 KB Output is correct
9 Correct 415 ms 20388 KB Output is correct
10 Correct 397 ms 20060 KB Output is correct
11 Correct 412 ms 20208 KB Output is correct
12 Correct 400 ms 20060 KB Output is correct
13 Correct 409 ms 20188 KB Output is correct
14 Correct 398 ms 20064 KB Output is correct
15 Correct 399 ms 20060 KB Output is correct
16 Correct 416 ms 20060 KB Output is correct
17 Correct 395 ms 20060 KB Output is correct
18 Correct 404 ms 20060 KB Output is correct
19 Correct 410 ms 20180 KB Output is correct
20 Correct 403 ms 20060 KB Output is correct
21 Correct 407 ms 20188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 407 ms 20192 KB Output is correct
2 Correct 406 ms 20188 KB Output is correct
3 Correct 422 ms 20288 KB Output is correct
4 Correct 394 ms 20064 KB Output is correct
5 Correct 408 ms 20288 KB Output is correct
6 Correct 400 ms 20060 KB Output is correct
7 Correct 426 ms 20188 KB Output is correct
8 Correct 398 ms 20060 KB Output is correct
9 Correct 415 ms 20388 KB Output is correct
10 Correct 397 ms 20060 KB Output is correct
11 Correct 412 ms 20208 KB Output is correct
12 Correct 400 ms 20060 KB Output is correct
13 Correct 409 ms 20188 KB Output is correct
14 Correct 398 ms 20064 KB Output is correct
15 Correct 399 ms 20060 KB Output is correct
16 Correct 416 ms 20060 KB Output is correct
17 Correct 395 ms 20060 KB Output is correct
18 Correct 404 ms 20060 KB Output is correct
19 Correct 410 ms 20180 KB Output is correct
20 Correct 403 ms 20060 KB Output is correct
21 Correct 407 ms 20188 KB Output is correct
22 Correct 419 ms 22220 KB Output is correct
23 Correct 413 ms 22364 KB Output is correct
24 Correct 420 ms 22236 KB Output is correct
25 Correct 411 ms 22236 KB Output is correct
26 Correct 421 ms 22236 KB Output is correct
27 Correct 416 ms 22236 KB Output is correct
28 Correct 418 ms 22236 KB Output is correct
29 Correct 412 ms 22212 KB Output is correct
30 Correct 415 ms 22328 KB Output is correct
31 Correct 406 ms 22236 KB Output is correct
32 Correct 416 ms 22108 KB Output is correct
33 Correct 409 ms 22108 KB Output is correct
34 Correct 416 ms 22268 KB Output is correct
35 Correct 419 ms 22240 KB Output is correct
36 Correct 418 ms 22172 KB Output is correct
37 Correct 430 ms 22236 KB Output is correct
38 Correct 418 ms 22236 KB Output is correct
39 Correct 417 ms 22236 KB Output is correct
40 Correct 410 ms 22236 KB Output is correct
41 Correct 422 ms 22228 KB Output is correct
42 Correct 426 ms 22120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 407 ms 20192 KB Output is correct
2 Correct 406 ms 20188 KB Output is correct
3 Correct 422 ms 20288 KB Output is correct
4 Correct 394 ms 20064 KB Output is correct
5 Correct 408 ms 20288 KB Output is correct
6 Correct 400 ms 20060 KB Output is correct
7 Correct 426 ms 20188 KB Output is correct
8 Correct 398 ms 20060 KB Output is correct
9 Correct 415 ms 20388 KB Output is correct
10 Correct 397 ms 20060 KB Output is correct
11 Correct 412 ms 20208 KB Output is correct
12 Correct 400 ms 20060 KB Output is correct
13 Correct 409 ms 20188 KB Output is correct
14 Correct 398 ms 20064 KB Output is correct
15 Correct 399 ms 20060 KB Output is correct
16 Correct 416 ms 20060 KB Output is correct
17 Correct 395 ms 20060 KB Output is correct
18 Correct 404 ms 20060 KB Output is correct
19 Correct 410 ms 20180 KB Output is correct
20 Correct 403 ms 20060 KB Output is correct
21 Correct 407 ms 20188 KB Output is correct
22 Correct 419 ms 22220 KB Output is correct
23 Correct 413 ms 22364 KB Output is correct
24 Correct 420 ms 22236 KB Output is correct
25 Correct 411 ms 22236 KB Output is correct
26 Correct 421 ms 22236 KB Output is correct
27 Correct 416 ms 22236 KB Output is correct
28 Correct 418 ms 22236 KB Output is correct
29 Correct 412 ms 22212 KB Output is correct
30 Correct 415 ms 22328 KB Output is correct
31 Correct 406 ms 22236 KB Output is correct
32 Correct 416 ms 22108 KB Output is correct
33 Correct 409 ms 22108 KB Output is correct
34 Correct 416 ms 22268 KB Output is correct
35 Correct 419 ms 22240 KB Output is correct
36 Correct 418 ms 22172 KB Output is correct
37 Correct 430 ms 22236 KB Output is correct
38 Correct 418 ms 22236 KB Output is correct
39 Correct 417 ms 22236 KB Output is correct
40 Correct 410 ms 22236 KB Output is correct
41 Correct 422 ms 22228 KB Output is correct
42 Correct 426 ms 22120 KB Output is correct
43 Correct 563 ms 27356 KB Output is correct
44 Correct 565 ms 27356 KB Output is correct
45 Correct 562 ms 27228 KB Output is correct
46 Correct 561 ms 27376 KB Output is correct
47 Correct 567 ms 27356 KB Output is correct
48 Correct 561 ms 27228 KB Output is correct
49 Correct 563 ms 27228 KB Output is correct
50 Correct 578 ms 27276 KB Output is correct
51 Correct 571 ms 27356 KB Output is correct
52 Correct 552 ms 27228 KB Output is correct
53 Correct 551 ms 27380 KB Output is correct
54 Correct 568 ms 27232 KB Output is correct
55 Correct 564 ms 27228 KB Output is correct
56 Correct 555 ms 27232 KB Output is correct
57 Correct 605 ms 27432 KB Output is correct
58 Correct 566 ms 27228 KB Output is correct
59 Correct 560 ms 27228 KB Output is correct
60 Correct 555 ms 27360 KB Output is correct
61 Correct 567 ms 27228 KB Output is correct
62 Correct 559 ms 27228 KB Output is correct
63 Correct 574 ms 27228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 407 ms 20192 KB Output is correct
2 Correct 406 ms 20188 KB Output is correct
3 Correct 422 ms 20288 KB Output is correct
4 Correct 394 ms 20064 KB Output is correct
5 Correct 408 ms 20288 KB Output is correct
6 Correct 400 ms 20060 KB Output is correct
7 Correct 426 ms 20188 KB Output is correct
8 Correct 398 ms 20060 KB Output is correct
9 Correct 415 ms 20388 KB Output is correct
10 Correct 397 ms 20060 KB Output is correct
11 Correct 412 ms 20208 KB Output is correct
12 Correct 400 ms 20060 KB Output is correct
13 Correct 409 ms 20188 KB Output is correct
14 Correct 398 ms 20064 KB Output is correct
15 Correct 399 ms 20060 KB Output is correct
16 Correct 416 ms 20060 KB Output is correct
17 Correct 395 ms 20060 KB Output is correct
18 Correct 404 ms 20060 KB Output is correct
19 Correct 410 ms 20180 KB Output is correct
20 Correct 403 ms 20060 KB Output is correct
21 Correct 407 ms 20188 KB Output is correct
22 Correct 419 ms 22220 KB Output is correct
23 Correct 413 ms 22364 KB Output is correct
24 Correct 420 ms 22236 KB Output is correct
25 Correct 411 ms 22236 KB Output is correct
26 Correct 421 ms 22236 KB Output is correct
27 Correct 416 ms 22236 KB Output is correct
28 Correct 418 ms 22236 KB Output is correct
29 Correct 412 ms 22212 KB Output is correct
30 Correct 415 ms 22328 KB Output is correct
31 Correct 406 ms 22236 KB Output is correct
32 Correct 416 ms 22108 KB Output is correct
33 Correct 409 ms 22108 KB Output is correct
34 Correct 416 ms 22268 KB Output is correct
35 Correct 419 ms 22240 KB Output is correct
36 Correct 418 ms 22172 KB Output is correct
37 Correct 430 ms 22236 KB Output is correct
38 Correct 418 ms 22236 KB Output is correct
39 Correct 417 ms 22236 KB Output is correct
40 Correct 410 ms 22236 KB Output is correct
41 Correct 422 ms 22228 KB Output is correct
42 Correct 426 ms 22120 KB Output is correct
43 Correct 563 ms 27356 KB Output is correct
44 Correct 565 ms 27356 KB Output is correct
45 Correct 562 ms 27228 KB Output is correct
46 Correct 561 ms 27376 KB Output is correct
47 Correct 567 ms 27356 KB Output is correct
48 Correct 561 ms 27228 KB Output is correct
49 Correct 563 ms 27228 KB Output is correct
50 Correct 578 ms 27276 KB Output is correct
51 Correct 571 ms 27356 KB Output is correct
52 Correct 552 ms 27228 KB Output is correct
53 Correct 551 ms 27380 KB Output is correct
54 Correct 568 ms 27232 KB Output is correct
55 Correct 564 ms 27228 KB Output is correct
56 Correct 555 ms 27232 KB Output is correct
57 Correct 605 ms 27432 KB Output is correct
58 Correct 566 ms 27228 KB Output is correct
59 Correct 560 ms 27228 KB Output is correct
60 Correct 555 ms 27360 KB Output is correct
61 Correct 567 ms 27228 KB Output is correct
62 Correct 559 ms 27228 KB Output is correct
63 Correct 574 ms 27228 KB Output is correct
64 Execution timed out 1167 ms 30280 KB Time limit exceeded
65 Halted 0 ms 0 KB -