QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#353002#4234. Tic Tac Toe CountingPetroTarnavskyi#RE 0ms0kbC++201.3kb2024-03-13 19:34:442024-03-13 19:34:45

Judging History

This is the latest submission verdict.

  • [2024-03-13 19:34:45]
  • Judged
  • Verdict: RE
  • Time: 0ms
  • Memory: 0kb
  • [2024-03-13 19:34:44]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int N = 1047;
const int K = 11;

int dp[N][N][K];
vector<PII> e[K];

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n, k, c;
	cin >> n >> k >> c;
	FOR (i, 0, c)
	{
		int a, b, d;
		cin >> a >> b >> d;
		a--, b--, d--;
		e[d].PB({a, b});
	}
	FOR (sick, 0, n)
	{
		FOR (koniara, 0, n)
		{
			if (sick == koniara)
				continue;
			dp[sick][koniara][0] = 1;
		}
	}
	
	FOR (d, 0, k - 1)
	{
		for (auto p : e[d])
		{
			FOR (koni, 0, n)
			{
				if (koni == p.F || koni == p.S)
					continue;
				if (dp[p.F][koni][d] && dp[p.F][p.S][d])
					dp[p.S][koni][d + 1] = 1;
				if (dp[p.S][koni][d] && dp[p.S][p.F][d])
					dp[p.F][koni][d + 1] = 1;
			}
		}
	}
	set<int> ans;
	for (auto p : e[k - 1])
	{
		if (dp[p.F][p.S][k - 1])
			ans.insert(p.S + 1);
		if (dp[p.S][p.F][k - 1])
			ans.insert(p.F + 1);
	}
	cout << SZ(ans) << '\n';
	for (auto a : ans)
		cout << a << '\n';
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

4
XX..O....
X...OX...
OOOX.X.X.
OOOXXX...

output:


result: