QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#48878 | #1242. Broken line | ckiseki# | WA | 0ms | 3664kb | C++ | 4.7kb | 2022-09-16 19:35:20 | 2022-09-16 19:35:22 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int64_t INF = 1e18;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int T;
cin >> T;
while (T--) {
int A, B, C;
cin >> A >> B >> C;
int64_t tota = 0, totb = 0;
vector<vector<vector<int64_t>>> v(A, vector<vector<int64_t>>(B, vector<int64_t>(C)));
for (int it = 0; it < A; it++) {
for (int i = 0; i < B; i++) {
for (int j = 0; j < C; j++) {
int64_t a;
cin >> a;
v[it][i][j] += a;
tota += a;
}
}
}
for (int it = 0; it < A; it++) {
for (int i = 0; i < B; i++) {
for (int j = 0; j < C; j++) {
int64_t b;
cin >> b;
v[it][i][j] -= b;
totb += b;
}
}
}
for (int it = 1; it < A; it++) {
for (int i = 0; i < B; i++) {
for (int j = 0; j < C; j++) {
v[it][i][j] += v[it-1][i][j];
}
}
}
const auto print = [](vector<int> v) {
for (int i = 0; i < v.size(); i++) {
cerr << v[i] << ' ';
}
};
map<vector<int>, int> revmap;
vector<vector<int>> state;
vector<int> tmp(B);
const auto genstate = [&](auto self, int i, int prv) {
if (i == B) {
revmap[tmp] = state.size();
state.push_back(tmp);
return;
}
for (int j = 0; j <= prv; j++) {
tmp[i] = j;
self(self, i + 1, j);
}
};
genstate(genstate, 0, C);
for (auto s: state)
print(s), cerr << endl;
vector<vector<vector<pair<int,int>>>> trans(state.size(), vector<vector<pair<int,int>>>(B));
for (size_t sid = 0; sid < state.size(); sid++) {
const auto &s = state[sid];
for (int i = 0; i < B; i++) {
auto ns = s;
if (ns[i] == C) {
continue;
}
int j = ns[i];
ns[i] += 1;
if (!revmap.count(ns)) continue;
int nsid = revmap[ns];
cerr << endl;
print(s);
cerr << ", ";
print(ns);
cerr << "i,j = " << i << ',' << j;
cerr << endl;
trans[sid][i].emplace_back(nsid, j);
}
}
vector<int64_t> dp(state.size(), INF);
dp[0] = 0;
bool ok = true;
for (int it = 0; it < A; it++) {
for (int i = 0; i < B; i++) {
for (size_t t = 0; t < state.size(); t++) {
for (auto [nt, j]: trans[t][i]) {
dp[nt] = min(dp[nt], dp[t] + v[it][B-1-i][C-1-j]);
}
}
for (size_t t = 0; t < state.size(); t++) {
cerr << dp[t] << ' ';
}
cerr << endl;
}
if (dp.back() < 0) {
ok = false;
break;
}
}
if (ok) {
cout << "TAK\n";
} else {
cout << "NIE\n";
}
}
return 0;
}
/*
00000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000
0 0 0 1000000000000000000 0 0 1000000000000000000 1 1000000000000000000 1000000000000000000 0 0 1000000000000000000 1 1000000000000000000 1000000000000000000 0 999999999999999999 999999999999999999 1000000000000000000 1 1 1000000000000000000 2 1000000000000000000 1000000000000000000 1 999999999999999999 999999999999999999 1000000000000000000 1 999999999999999999 999999999999999999 1000000000000000000 1000000000000000000
0 0 0 1 0 0 1 1 2 1 0 0 1 1 2 1 0 1 0 0 1 1 2 2 3 2 1 2 1 1 1 2 1 1 3
0 -4 0 1 -4 0 1 1 2 1 -4 0 1 1 2 1 0 1 0 0 -3 1 2 2 3 2 1 2 1 1 1 2 1 1 3
0 -4 -4 1 -4 -4 1 -3 2 1 -4 -4 1 -3 2 1 -4 1 0 0 -3 -3 2 -2 3 2 -3 2 1 1 -2 2 1 1 3
0 -4 -4 -3 -4 -4 -3 -3 -2 -3 -4 -4 -3 -3 -2 -3 -4 -3 -4 -3 -3 -3 -2 -2 -1 -2 -3 -2 -3 -2 -2 -1 -2 -1 0
TAK
0 0
1 0
1 1
2 0
2 1
2 2
0 0 , 1 0 i,j = 0,0
1 0 , 2 0 i,j = 0,1
1 0 , 1 1 i,j = 1,0
1 1 , 2 1 i,j = 0,1
2 0 , 2 1 i,j = 1,0
2 1 , 2 2 i,j = 1,1
0 -1 1000000000000000000 0 1000000000000000000 1000000000000000000
0 -1 0 0 1 2
0 -2 0 -2 0 2
0 -2 -2 -2 -2 0
TAK
Press ENTER or type command to continue
Press ENTER or type command to continue
Press ENTER or type command to continue
*/
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3664kb
input:
banan
output:
result:
wrong output format Unexpected end of file - token expected