QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#528096 | #5141. Identical Parity | syss | TL | 0ms | 0kb | C++20 | 3.5kb | 2024-08-23 08:18:35 | 2024-08-23 08:18:36 |
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
inline int read () {
int w = 1, s = 0; char ch = getchar ();
for (; ! isdigit (ch); ch = getchar ()) if (ch == '-') w = -1;
for (; isdigit (ch); ch = getchar ()) s = (s << 1) + (s << 3) + (ch ^ 48);
return s * w;
}
struct Info {
char op[2];
int x, y;
};
void solve () {
int n = read (), m = read ();
while (n --) {
int Solve = read (), Time = read ();
int sum = 0, sumtime = 0;
vector <int> p;
vector <Info> info (m);
int t = 0;
for (auto &[op, x, y] : info) {
scanf ("%s", op);
if (op[0] == '+') {
scanf ("%lld/%lld", &x, &y);
sum ++;
sumtime += (x - 1) * 20 + y;
} else if (op[0] == '-') {
x = read ();
} else if (op[0] == '?') {
p.push_back (t);
x = read (); y = read ();
}
t ++;
}
if (sumtime > Time || sum > Solve) {
printf ("No\n");
continue;
}
bool ok = false;
for (int i = 0; i < 1 << p.size (); i ++) {
int tot = 0;
for (int j = 0; j < p.size (); j ++) {
if (i >> j & 1) {
tot ++;
}
}
if (tot != Solve - sum) continue;
int now = sumtime;
int cnt = 0;
for (int j = 0; j < p.size (); j ++) {
if (i >> j & 1) {
auto [op, x, y] = info[p[j]];
now += 239 + (y - x) * 20;
cnt += x;
}
}
now += tot;
if (Time < now) {
continue;
}
if (Time > now + (cnt-tot) * 20 + 59 * tot) {
continue;
}
for (int j = 0; j < p.size (); j ++) {
auto &[op, x, y] = info[p[j]];
if (i >> j & 1) {
op[0] = '+';
int z = 0;
if (Time - now >= (x - 1) * 20) {
now += (x - 1) * 20;
x=y;
} else {
z = (Time - now) / 20;
now += z * 20;
x = (y - x) + z + 1;
}
if (Time - now >= 59) {
now += 59;
y = 299;
} else {
y = (Time - now) + 240;
now = Time;
}
} else {
op[0] = '-';
x = y;
}
}
ok = true;
break;
}
if (ok) {
printf ("Yes\n");
for (auto [op, x, y] : info) {
if (op[0] == '+') {
printf ("+ %lld/%lld\n", x, y);
} else if (op[0] == '-') {
printf ("- %lld\n", x);
} else {
printf (".\n");
}
}
} else {
printf ("No\n");
}
}
}
signed main () {
/* ios::sync_with_stdio(false);
cin.tie(nullptr);*/
int TT = 1;
// cin >> TT;
// TT = read ();
while (TT --) solve ();
return 0;
}
详细
Test #1:
score: 0
Time Limit Exceeded
input:
3 3 1 4 2 5 3