QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#129715 | #4374. What Really Happened on Mars? | Swarthmore# | RE | 1ms | 3576kb | C++17 | 4.8kb | 2023-07-22 22:34:55 | 2023-07-22 22:36:00 |
Judging History
answer
#include "bits/stdc++.h"
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef DEBUG
#define dbg(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
#else
#define dbg(x...)
#endif
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001;
void solve() {
int T, R; cin >> T >> R;
int S[T], B[T];
queue<pair<char, int>> tasks[T];
int ce[R]; F0R(i, R) ce[i] = 0;
F0R(i, T) {
cin >> S[i] >> B[i];
int A; cin >> A;
F0R(j, A) {
char C; int K; cin >> C >> K;
if (C != 'C') K--;
if (C == 'L') ckmax(ce[K], B[i]);
tasks[i].push({C, K});
}
}
int ct = 0;
int rem = T;
int ans[T]; F0R(i, T) ans[i] = -1;
int own[R]; F0R(i, R) own[i] = -1;
while (true) {
vpi run;
F0R(i, T) {
if (S[i] <= ct && ans[i] == -1) {
run.pb({B[i], i});
}
}
if (sz(run) == 0) {
ct++; continue;
}
sort(all(run)); reverse(all(run));
int prio[T]; F0R(i, T) prio[i] = B[i];
vi notBlocked;
trav(a, run) {
//dbg(ct, a.s, tasks[a.s].front());
if (tasks[a.s].front().f != 'L') {
notBlocked.pb(a.s); continue;
}
bool ok = true;
F0R(i, R) {
if (own[i] != -1 && own[i] != a.s && ce[i] >= ce[tasks[a.s].front().s]) {
ckmax(prio[own[i]], prio[a.s]);
ok = false;
}
}
if (ok) notBlocked.pb(a.s);
}
int bst = notBlocked[0];
trav(a, notBlocked) {
if (prio[a] > prio[bst]) bst = a;
}
if (tasks[bst].front().f == 'C') {
tasks[bst].front().s--;
if (tasks[bst].front().s == 0) tasks[bst].pop();
ct++;
} else if (tasks[bst].front().f == 'L') {
own[tasks[bst].front().s] = bst;
tasks[bst].pop();
} else {
own[tasks[bst].front().s] = -1;
tasks[bst].pop();
}
if (sz(tasks[bst]) == 0) {
ans[bst] = ct;
rem--;
if (rem == 0) break;
}
//dbg("TEST3");
}
F0R(i, T) {
cout << ans[i] << nl;
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int T = 1;
// cin >> T;
while(T--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3480kb
input:
3 1 50 2 5 C1 L1 C1 U1 C1 1 1 5 C1 L1 C100 U1 C1 70 3 1 C1
output:
106 107 71
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 3576kb
input:
3 3 5 3 5 C1 L1 C1 U1 C1 3 2 9 C1 L2 C1 L3 C1 U3 C1 U2 C1 1 1 9 C1 L3 C3 L2 C1 U2 C1 U3 C1
output:
8 15 16
result:
ok 3 lines
Test #3:
score: -100
Runtime Error
input:
19 8 7 7 23 L8 C5 C1 C1 L1 U1 L5 L3 U3 U5 U8 C1 C4 L3 L1 C2 U1 U3 L3 C2 C4 U3 C2 19 14 6 L7 L3 L4 U4 U3 U7 6 5 3 L1 U1 C5 35 2 18 L2 L5 L7 U7 C3 C3 C3 U5 U2 L4 L1 C2 C2 C5 U1 U4 L3 U3 45 6 3 C3 L6 U6 32 3 10 C4 C1 C3 L1 L6 L8 C2 U8 U6 U1 17 17 50 L4 L6 C4 L8 U8 U6 U4 L1 L5 L2 L8 L4 L3 L7 L6 U6 U7 U3...