Submission #487441

# Submission time Handle Problem Language Result Execution time Memory
487441 2021-11-15T13:47:28 Z Nimbostratus Vlak (COCI20_vlak) C++17
20 / 70
17 ms 13904 KB
#include "bits/stdc++.h"
using namespace std;
#define endl '\n'
using lint = long long;
using pii = pair<int,int>;
constexpr int maxn = 2e5+5;
constexpr int maxc = 'z' + 10;
constexpr int inf = 2e9;
constexpr int mod = 1e9+7;

int n, m;
string s[maxn], t[maxn];
bool sc[maxn][maxc], tc[maxn][maxc], win[maxn][maxc];
vector<vector<bool>> dp;
int maxl;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cin >> n;
	for(int i = 0; i < n; i++) {
		cin >> s[i];
		maxl = max(maxl, (int)s[i].size());
	}
	cin >> m;
	for(int i = 0; i < m; i++) {
		cin >> t[i];
		maxl = max(maxl, (int)t[i].size());
	}

	for(int i = 0; i < n; i++)
		while(s[i].size() < maxl)
			s[i] += char('z' + 1);
	for(int i = 0; i < m; i++)
		while(t[i].size() < maxl)
			t[i] += char('z' + 2);

	dp = vector<vector<bool>>(maxl + 10, vector<bool>(max(n, m) + 10));

	for(int k = 0; k < maxl; k++)
		for(int i = 0; i < n; i++)
			sc[k][s[i][k]] = true;
	for(int k = 0; k < maxl; k++)
		for(int i = 0; i < m; i++)
			tc[k][t[i][k]] = true;	
	for(int i = 'a'; i <= 'z' + 2; i++)
		win[maxl][i] = true;

	for(int k = maxl - 1; k >= 0; k--) {
		bool f = k == maxl - 1;
		if(k % 2 == 0) {
			for(int i = 0; i < n; i++) {
				dp[k][i] = !tc[k][s[i][k]] || !win[k + 1][s[i][k]] || f;
				if(k >= 1)
					win[k][s[i][k - 1]] = win[k][s[i][k - 1]] || dp[k][i] || f;
			}
		}
		else {
			for(int i = 0; i < m; i++) {
				dp[k][i] = !sc[k][t[i][k]] || !win[k + 1][t[i][k]] || f;
				if(k >= 1)
					win[k][t[i][k - 1]] = win[k][t[i][k - 1]] || dp[k][i] || f;
			}
		}
	}

	bool ans = false;
	for(int i = 0; i < n; i++)
		ans |= dp[0][i];
	cout << (ans ? "Nina" : "Emilija") << endl;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:32:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   32 |   while(s[i].size() < maxl)
      |         ~~~~~~~~~~~~^~~~~~
Main.cpp:35:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   35 |   while(t[i].size() < maxl)
      |         ~~~~~~~~~~~~^~~~~~
Main.cpp:42:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   42 |    sc[k][s[i][k]] = true;
      |                 ^
Main.cpp:45:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   45 |    tc[k][t[i][k]] = true;
      |                 ^
Main.cpp:53:30: warning: array subscript has type 'char' [-Wchar-subscripts]
   53 |     dp[k][i] = !tc[k][s[i][k]] || !win[k + 1][s[i][k]] || f;
      |                              ^
Main.cpp:53:54: warning: array subscript has type 'char' [-Wchar-subscripts]
   53 |     dp[k][i] = !tc[k][s[i][k]] || !win[k + 1][s[i][k]] || f;
      |                                                      ^
Main.cpp:55:24: warning: array subscript has type 'char' [-Wchar-subscripts]
   55 |      win[k][s[i][k - 1]] = win[k][s[i][k - 1]] || dp[k][i] || f;
      |                        ^
Main.cpp:55:46: warning: array subscript has type 'char' [-Wchar-subscripts]
   55 |      win[k][s[i][k - 1]] = win[k][s[i][k - 1]] || dp[k][i] || f;
      |                                              ^
Main.cpp:60:30: warning: array subscript has type 'char' [-Wchar-subscripts]
   60 |     dp[k][i] = !sc[k][t[i][k]] || !win[k + 1][t[i][k]] || f;
      |                              ^
Main.cpp:60:54: warning: array subscript has type 'char' [-Wchar-subscripts]
   60 |     dp[k][i] = !sc[k][t[i][k]] || !win[k + 1][t[i][k]] || f;
      |                                                      ^
Main.cpp:62:24: warning: array subscript has type 'char' [-Wchar-subscripts]
   62 |      win[k][t[i][k - 1]] = win[k][t[i][k - 1]] || dp[k][i] || f;
      |                        ^
Main.cpp:62:46: warning: array subscript has type 'char' [-Wchar-subscripts]
   62 |      win[k][t[i][k - 1]] = win[k][t[i][k - 1]] || dp[k][i] || f;
      |                                              ^
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12880 KB Output is correct
2 Correct 9 ms 12848 KB Output is correct
3 Correct 7 ms 12880 KB Output is correct
4 Correct 6 ms 12880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 12852 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 12752 KB Output is correct
2 Correct 8 ms 12752 KB Output is correct
3 Correct 7 ms 12796 KB Output is correct
4 Correct 6 ms 12852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 12880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 13904 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 13648 KB Output is correct
2 Correct 16 ms 13648 KB Output is correct
3 Correct 16 ms 13696 KB Output is correct
4 Incorrect 15 ms 13648 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 13704 KB Output is correct
2 Incorrect 12 ms 13832 KB Output isn't correct
3 Halted 0 ms 0 KB -