QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#466036 | #8813. Records in Chichén Itzá | HKOI0# | WA | 0ms | 3532kb | C++17 | 4.3kb | 2024-07-07 15:04:57 | 2024-07-07 15:04:57 |
Judging History
answer
#include <bits/stdc++.h>
#define sz(v) (int)v.size()
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
struct HPA {
vector<int> a;
// HPA(int x=0) {
// for(;x;x/=10) a.emplace_back(x%10);
// }
HPA(string s) {
assert(false);
}
HPA& operator+=(const HPA& other) {
a.emplace_back(0);
for(int i=0;i<sz(a);i++) {
if(i<sz(other.a)) a[i]+=other.a[i];
a[i+1]+=a[i]/10;
a[i]%=10;
}
if(sz(a)>1&&a[sz(a)-1]==0) a.pop_back();
return *this;
}
bool operator<(const HPA& other) {
if(sz(a)!=sz(other.a)) return sz(a)<sz(other.a);
vector<int> x(a);
vector<int> y(other.a);
reverse(all(x));
reverse(all(y));
return x<y;
}
};
struct Cell {
array<array<char, 2>, 2> a;
array<int, 3> rowof;
array<int, 3> colof;
inline array<char, 2>& operator [] (int x) {
return a[x];
}
Cell() {
for (int i = 0; i < 3; i++)
rowof[i] = colof[i] = -1;
}
};
enum Position {
L = 0, R = 1
};
void solve() {
int n; cin >> n;
vector<Cell> cells(n);
{
vector<string> grid(2);
cin >> grid[0] >> grid[1];
cout << grid[0] << '\n' << grid[1] << '\n';
for (int i = 0; i < n; i++) {
for (int row = 0; row <= 1; row++) {
for (int col = 0; col <= 1; col++) {
cells[i][row][col] = grid[row][i * 2 + col];
}
}
}
};
// for (int i = 0; i < 2 * n; i++)
// cout << cells[i / 2][0][i % 2];
// cout << "\n";
// for (int i = 0; i < 2 * n; i++)
// cout << cells[i / 2][1][i % 2];
// cout << "\n";
for (int i = 0; i < n; i++) {
for (int row = 0; row <= 1; row++) {
for (int col = 0; col <= 1; col++) {
for (int num = 1; num <= 2; num++) {
if (cells[i][row][col] == '0' + num) {
cells[i].rowof[num] = row;
cells[i].colof[num] = col;
}
}
}
}
}
// index of the first RIGHT cell
vector<int> minPart(2, 0);
vector<int> maxPart(2, n - 1);
for (int i = 0; i < n; i++) {
for (int num = 1; num <= 2; num++) {
// cout << "CELL " << i << " NUM " << num << ' ' << cells[i].colof[num] << '\n';
if (cells[i].colof[num] == 0)
minPart[num] = max(minPart[num], i + 1);
if (cells[i].colof[num] == 1)
maxPart[num] = min(maxPart[num], i);
}
}
bool hasSolution = true;
for (int num = 1; num <= 2; num++) {
// cout << "MINMAX PARTS " << num << ' ' << minPart[num] << ' ' << maxPart[num] << '\n';
if (minPart[num] > maxPart[num])
hasSolution = false;
}
if (!hasSolution) {
cout << "impossible\n";
return;
}
auto construct = [&](array<int, 3> parts) {
string toprow(2 * n, '?');
for (int i = 0; i < n; i++) {
array<Position, 3> pos;
for (int num = 1; num <= 2; num++)
pos[num] = (i < parts[num] ? L : R);
if (pos[1] == pos[2]) {
const int p = pos[1];
if (cells[i].rowof[2] != 1)
toprow[i * 2 + p] = '2';
else
toprow[i * 2 + p] = '1';
}
else {
for (int num = 1; num <= 2; num++)
if (cells[i].rowof[num] != 1)
toprow[i * 2 + pos[num]] = '0' + num;
}
}
cout << parts[0] << ' ' << parts[1] << '\n';
cout << toprow << '\n';
};
for (int p1 : { minPart[1], maxPart[1] }) {
for (int p2 : { minPart[2], maxPart[2] }) {
array<int, 3> parts;
parts[1] = p1;
parts[2] = p2;
construct(parts);
}
}
}
signed main() {
#ifndef LOCAL
ios::sync_with_stdio(false);
cin.tie(nullptr);
#endif
int T = 1;
cin >> T;
while (T--) solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3532kb
input:
3 6 1 1 1 1 3 3 5 1 1 2 2 2 10 1 1 1 1 2 2 2 2 3 3
output:
1 1 0 1 ?2?2?2?2?2?2 0 1 ?2?2?2?2?2?2 0 5 ?212121212?2 0 5 ?212121212?2 1 3 impossible 5 1 0 1 ?2?2?2 0 1 ?2?2?2 0 2 ?212?2 0 2 ?212?2
result:
wrong answer 1st words differ - expected: 'No', found: '1'