跳到正文

题解

P9752 题解

Register_int约 2 分钟
原文
文章信息与版本

文章信息

发布
2023年10月22日
收录
2026年9月10日
更新
2026年11月8日
篇幅
约 2 分钟
获赞
32
题目
P9752

版本

  1. v1当前

容易发现序列是可逆的,所以可以暴力找出每个密码锁能拨成的状态,然后将每个集合求交即可。记得最后要把所有给出的状态去掉。时间复杂度为 O(knlog⁡kn)O(kn\log kn),其中 kk 为 8181。

所以这题完全能把密码锁长度开 10310^3 啊,强烈谴责 CCF 放了一车枚举原状态的过了。

AC 代码

C++
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

const int MAXN = 1e5 + 10;

set<array<int, 5>> s, t; vector<array<int, 5>> v;

int n; array<int, 5> a[8], x;

int main() {
	freopen("lock.in", "r", stdin);
	freopen("lock.out", "w", stdout);
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 5; j++) scanf("%d", &a[i][j]);
		for (int j = 0; j < 5; j++) {
			x = a[i];
			for (int k = 0; k < 9; k++) {
				x[j] = (x[j] + 1) % 10, s.insert(x);
			}
		}
		for (int j = 0; j < 4; j++) {
			x = a[i];
			for (int k = 0; k < 9; k++) {
				x[j] = (x[j] + 1) % 10, x[j + 1] = (x[j + 1] + 1) % 10;
				s.insert(x);
			}
		}
		if (!i) t = s;
		else {
			for (auto p : t) if (s.find(p) == s.end()) v.push_back(p);
			for (auto p : v) t.erase(p); v.clear();
		}
		s.clear();
	}
	for (int i = 0; i < n; i++) t.erase(a[i]);
	printf("%d", (int)t.size());
}
原文
存档评论13 条抓取于