算法
(暴力枚举) $O(1000)$
由于 $N$ 最大只有 $3$,所以我们暴力枚举 $0 \sim 999$, 尝试其中所有的值即可。
C++ 代码
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using std::cin;
using std::cout;
using std::vector;
using P = std::pair<int, int>;
int main() {
int n, m;
cin >> n >> m;
vector<P> p(m);
rep(i, m) cin >> p[i].first >> p[i].second;
rep(x, 1000) {
int keta = 1; // 位数
int nx = x / 10;
vector<int> d(1, x%10);
while (nx) {
keta++;
d.push_back(nx%10);
nx /= 10;
}
if (keta != n) continue;
bool ok = true;
reverse(d.begin(), d.end());
rep(i, m) {
if (d[p[i].first-1] != p[i].second) ok = false;
}
if (ok) {
cout << x << '\n';
return 0;
}
}
puts("-1");
return 0;
}
### 太牛了 大佬 打call !!