Submission #223330

# Submission time Handle Problem Language Result Execution time Memory
223330 2020-04-15T07:20:15 Z jamielim Trener (COCI20_trener) C++14
110 / 110
147 ms 18400 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
const ll MOD=1000000007;
string str[55][1505];
vector<pair<string,int> > str2[55];
 
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	char temp[55];
	for(int i=0;i<n;i++){
		for(int j=0;j<k;j++){
			scanf("%s",temp);
			str[i][j]=temp;
		}
		sort(str[i],str[i]+k);
		if(i!=0){
			for(int j=0;j<k;j++){
				string a,b;
				for(int l=0;l<i;l++){
					a+=str[i][j][l];
					b+=str[i][j][l+1];
				}
				if(a==b)str2[i].push_back(make_pair(a,j));
				else str2[i].push_back(make_pair(a,j)),str2[i].push_back(make_pair(b,j));
			}
			sort(str2[i].begin(),str2[i].end());
			//for(int j=0;j<2*k;j++)printf("%s ",str2[i][j].first.c_str());
			//printf("\n");
		}
	}
	ll dp[2][k]; memset(dp,0,sizeof(dp));
	for(int i=0;i<k;i++)dp[1][i]=1;
	for(int i=n-2;i>=0;i--){
		int ptr=0;
		for(int j=0;j<k;j++){
			if(j>0&&str[i][j]==str[i][j-1]){
				dp[0][j]=dp[0][j-1];continue;
			}
			while(ptr<(int)str2[i+1].size()){
				if(str[i][j]==str2[i+1][ptr].first){
					dp[0][j]+=dp[1][str2[i+1][ptr].second];
					dp[0][j]%=MOD;
				}else if(str[i][j]<str2[i+1][ptr].first)break;
				ptr++;
			}
		}
		for(int j=0;j<k;j++){dp[1][j]=dp[0][j];dp[0][j]=0;}
	}
	ll ans=0;
	for(int i=0;i<k;i++){ans+=dp[1][i];ans%=MOD;}
	printf("%lld",ans);
}

Compilation message

trener.cpp: In function 'int main()':
trener.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&k);
  ~~~~~^~~~~~~~~~~~~~
trener.cpp:16:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%s",temp);
    ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2944 KB Output is correct
2 Correct 6 ms 2944 KB Output is correct
3 Correct 6 ms 2944 KB Output is correct
4 Correct 6 ms 2944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 3968 KB Output is correct
2 Correct 14 ms 4096 KB Output is correct
3 Correct 14 ms 4096 KB Output is correct
4 Correct 11 ms 3584 KB Output is correct
5 Correct 15 ms 3968 KB Output is correct
6 Correct 15 ms 4096 KB Output is correct
7 Correct 11 ms 3584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2944 KB Output is correct
2 Correct 6 ms 2944 KB Output is correct
3 Correct 6 ms 2944 KB Output is correct
4 Correct 6 ms 2944 KB Output is correct
5 Correct 13 ms 3968 KB Output is correct
6 Correct 14 ms 4096 KB Output is correct
7 Correct 14 ms 4096 KB Output is correct
8 Correct 11 ms 3584 KB Output is correct
9 Correct 15 ms 3968 KB Output is correct
10 Correct 15 ms 4096 KB Output is correct
11 Correct 11 ms 3584 KB Output is correct
12 Correct 139 ms 18400 KB Output is correct
13 Correct 138 ms 17816 KB Output is correct
14 Correct 132 ms 17888 KB Output is correct
15 Correct 131 ms 17844 KB Output is correct
16 Correct 82 ms 12644 KB Output is correct
17 Correct 140 ms 17836 KB Output is correct
18 Correct 144 ms 18072 KB Output is correct
19 Correct 137 ms 18072 KB Output is correct
20 Correct 147 ms 18072 KB Output is correct
21 Correct 135 ms 18072 KB Output is correct
22 Correct 81 ms 12792 KB Output is correct