# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
28554 | 2017-07-16T07:17:04 Z | 흐훗흐흐훗핫(#1176, dtc03012, iriszero) | Play Onwards (FXCUP2_onward) | C++ | 123 ms | 2308 KB |
#include <iostream> #include <string> #include <vector> #include <queue> using namespace std; string tmp[333]; int dp[333]; vector<int> arr[333]; int main(void) { int n,m; cin >> n >> m; for(int e=0;e<n;e++) cin >> tmp[e]; for(int e=0;e<n;e++) { for(int p=e+1;p<n;p++) { int mm=0,qq=0,rr=0; for(int q=0;q<tmp[e].size();q++) { for(int r=0;r<tmp[p].size();r++) { if(tmp[e][q]==tmp[p][r]) { rr=0; qq=0; for(int ee=r;ee<tmp[p].size()&&q+qq<tmp[e].size();ee++,qq++) { if(tmp[e][q+qq]==tmp[p][ee]) { rr++; mm=max(mm,rr); } else { break; } } } } } if(mm>=m) { arr[e].push_back(p); arr[p].push_back(e); } } } queue<int> q; for(int e=0;e<n;e++) { if(dp[e]==0) { dp[e]=1; q.push(e); while(!q.empty()) { int now=q.front();q.pop(); for(int p=0;p<arr[now].size();p++) { int next=arr[now][p]; if(dp[next]==0) { if(dp[now]==1) dp[next]=2; else dp[next]=1; q.push(next); } else { if(dp[next]==dp[now]) { cout << "No"; return 0; } } } } } } for(int e=0;e<n;e++) if(dp[e]==0) dp[e]=1; int pp=0; for(int e=0;e<n;e++) if(dp[e]==1) pp++; if(pp==0) dp[0]=1; if(pp==n) dp[0]=2; cout << "Yes\n"; for(int e=0;e<n;e++) cout << dp[e] << "\n"; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 2044 KB | Output is correct |
2 | Correct | 0 ms | 2044 KB | Output is correct |
3 | Correct | 0 ms | 2044 KB | Output is correct |
4 | Correct | 0 ms | 2044 KB | Output is correct |
5 | Correct | 123 ms | 2308 KB | Output is correct |
6 | Correct | 3 ms | 2308 KB | Output is correct |
7 | Correct | 9 ms | 2044 KB | Output is correct |
8 | Correct | 9 ms | 2044 KB | Output is correct |
9 | Correct | 9 ms | 2044 KB | Output is correct |
10 | Correct | 6 ms | 2044 KB | Output is correct |
11 | Correct | 66 ms | 2044 KB | Output is correct |
12 | Correct | 19 ms | 2044 KB | Output is correct |
13 | Correct | 36 ms | 2044 KB | Output is correct |
14 | Correct | 53 ms | 2044 KB | Output is correct |
15 | Correct | 0 ms | 2044 KB | Output is correct |
16 | Correct | 0 ms | 2044 KB | Output is correct |
17 | Correct | 0 ms | 2044 KB | Output is correct |
18 | Correct | 19 ms | 2044 KB | Output is correct |
19 | Correct | 3 ms | 2044 KB | Output is correct |
20 | Correct | 13 ms | 2044 KB | Output is correct |
21 | Correct | 9 ms | 2044 KB | Output is correct |