QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#181391#7226. The Impressive Pathucup-team288#TL 1ms3752kbC++201.7kb2023-09-16 18:15:462023-09-16 18:15:46

Judging History

你现在查看的是最新测评结果

  • [2023-09-16 18:15:46]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3752kb
  • [2023-09-16 18:15:46]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using i64 = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif

vector<int> dx{1, 2, 2, 1, -1, -2, -2, -1};
vector<int> dy{2, 1, -1, -2, -2, -1, 1, 2}; 

int main() {
	cin.tie(nullptr)->sync_with_stdio(false);

	int n, m, t;
	cin >> n >> m >> t;

	auto prune = [&](int cur, int x, int y) {
		int d = n - 1 - x + m - 1 - y;
		int left = t - cur;
		if (d > 3 * left) {
			return true;
		} else {
			return false;
		}
	};

	vector vis(n, vector<int>(m));
	vis[0][0] = true;
	vector<pair<int, int>> ans;
	auto rec = [&](auto rec, int cur, int x, int y) -> void {
		if (cur == t && x == n - 1 && y == m - 1) {
			for (int i = 0; i < t; i++) {
				cout << ans[i].first + 1 << ' ' << ans[i].second + 1 << '\n';
			}
			exit(0);
		}
		if (cur == t) {
			return;
		}
		for (int dir = 0; dir < 8; dir++) {
			int nx = x + dx[dir], ny = y + dy[dir];
			if (0 <= nx && nx < n && 0 <= ny && ny < m && !vis[nx][ny] && !prune(cur + 1, nx, ny)) {
				vis[nx][ny] = true;
				ans.emplace_back(nx, ny);
				rec(rec, cur + 1, nx, ny);
				vis[nx][ny] = false;
				ans.pop_back();
			}
		}
	};
	rec(rec, 0, 0, 0);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3752kb

input:

8 8 16

output:

2 3
3 5
4 7
6 8
8 7
7 5
8 3
7 1
5 2
6 4
7 6
8 4
6 3
5 5
6 7
8 8

result:

ok correct

Test #2:

score: -100
Time Limit Exceeded

input:

8 8 32

output:


result: