結果
問題 | No.953 席 |
ユーザー | 👑 emthrm |
提出日時 | 2019-12-16 10:41:29 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 94 ms / 2,000 ms |
コード長 | 3,855 bytes |
コンパイル時間 | 1,470 ms |
コンパイル使用メモリ | 136,064 KB |
実行使用メモリ | 8,704 KB |
最終ジャッジ日時 | 2024-07-02 19:36:06 |
合計ジャッジ時間 | 4,990 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 48 ms
5,376 KB |
testcase_03 | AC | 47 ms
5,376 KB |
testcase_04 | AC | 48 ms
5,376 KB |
testcase_05 | AC | 44 ms
5,376 KB |
testcase_06 | AC | 48 ms
5,376 KB |
testcase_07 | AC | 94 ms
8,192 KB |
testcase_08 | AC | 85 ms
6,992 KB |
testcase_09 | AC | 84 ms
8,704 KB |
testcase_10 | AC | 27 ms
5,376 KB |
testcase_11 | AC | 63 ms
5,888 KB |
testcase_12 | AC | 63 ms
5,632 KB |
testcase_13 | AC | 78 ms
6,888 KB |
testcase_14 | AC | 59 ms
5,376 KB |
testcase_15 | AC | 56 ms
5,376 KB |
testcase_16 | AC | 58 ms
5,376 KB |
testcase_17 | AC | 67 ms
5,504 KB |
testcase_18 | AC | 63 ms
5,376 KB |
testcase_19 | AC | 82 ms
6,716 KB |
testcase_20 | AC | 63 ms
5,376 KB |
testcase_21 | AC | 50 ms
5,376 KB |
testcase_22 | AC | 66 ms
5,776 KB |
testcase_23 | AC | 53 ms
5,376 KB |
testcase_24 | AC | 52 ms
5,376 KB |
testcase_25 | AC | 84 ms
7,008 KB |
testcase_26 | AC | 38 ms
5,376 KB |
ソースコード
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <chrono> #define _USE_MATH_DEFINES #include <cmath> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const double EPS = 1e-8; const int MOD = 1000000007; // const int MOD = 998244353; const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1}; // const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1}, // dx[] = {0, -1, -1, -1, 0, 1, 1, 1}; struct IOSetup { IOSetup() { cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); cerr << fixed << setprecision(10); } } iosetup; /*-------------------------------------------------*/ int main() { int n, k1, k2; cin >> n >> k1 >> k2; --k1; --k2; vector<int> idx(n), rev(n); int now = 0; idx[k1] = now; rev[now] = k1; ++now; for (int dist = 1; dist < n; ++dist) { if (k1 < k2) { if (k1 + dist < n) { idx[k1 + dist] = now; rev[now] = k1 + dist; ++now; } if (k1 - dist >= 0) { idx[k1 - dist] = now; rev[now] = k1 - dist; ++now; } } else { if (k1 - dist >= 0) { idx[k1 - dist] = now; rev[now] = k1 - dist; ++now; } if (k1 + dist < n) { idx[k1 + dist] = now; rev[now] = k1 + dist; ++now; } } } // REP(i, n) cout << rev[i] << ' '; // cout << '\n'; set<int> broad, emp; REP(i, n) broad.emplace(i); int q; cin >> q; using P = pair<long long, int>; priority_queue<P, vector<P>, greater<P> > que; long long cur = 0; while (q--) { long long a, b; cin >> a >> b; cur = max(cur, a); while (!que.empty() && (que.top().first <= cur || (broad.empty() && emp.empty()))) { int seat = rev[que.top().second]; cur = max(cur, que.top().first); que.pop(); bool br = true; if (seat - 1 >= 0) { int seat_l = seat - 1; if (emp.count(idx[seat_l]) == 1) { if (seat_l - 1 < 0 || (broad.count(idx[seat_l - 1]) == 1 || emp.count(idx[seat_l - 1]) == 1)) { emp.erase(idx[seat_l]); broad.emplace(idx[seat_l]); } } else { br = false; } } if (seat + 1 < n) { int seat_r = seat + 1; if (emp.count(idx[seat_r]) == 1) { if (seat_r + 1 >= n || (broad.count(idx[seat_r + 1]) == 1 || emp.count(idx[seat_r + 1]) == 1)) { emp.erase(idx[seat_r]); broad.emplace(idx[seat_r]); } } else { br = false; } } (br ? broad : emp).emplace(idx[seat]); } int seat; if (!broad.empty()) { seat = *broad.begin(); broad.erase(seat); } else { seat = *emp.begin(); emp.erase(seat); } cout << rev[seat] + 1 << '\n'; que.emplace(cur + b, seat); if (rev[seat] - 1 >= 0) { int seat_l = idx[rev[seat] - 1]; if (broad.count(seat_l) == 1) { broad.erase(seat_l); emp.emplace(seat_l); } } if (rev[seat] + 1 < n) { int seat_r = idx[rev[seat] + 1]; if (broad.count(seat_r) == 1) { broad.erase(seat_r); emp.emplace(seat_r); } } // cout << "broad: "; // for (int e : broad) cout << e << ' '; // cout << '\n'; // cout << "emp: "; // for (int e : emp) cout << e << ' '; // cout << '\n'; } return 0; }