結果
問題 |
No.2623 Room Allocation
|
ユーザー |
![]() |
提出日時 | 2024-02-09 22:04:46 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 63 ms / 2,000 ms |
コード長 | 2,556 bytes |
コンパイル時間 | 1,389 ms |
コンパイル使用メモリ | 118,620 KB |
最終ジャッジ日時 | 2025-02-19 03:41:11 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
//#pragma GCC target("avx2") //#pragma GCC optimize("O3") //#pragma GCC optimize("unroll-loops") #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <vector> using namespace std; using ll = long long; using pii = pair<int,int>; using pll = pair<ll,ll>; using pli = pair<ll,int>; #define TEST cerr << "TEST" << endl #define AMARI 998244353 //#define AMARI 1000000007 #define el '\n' #define El '\n' template <typename T> vector<T> getvec(int n,T val){ vector<T> ans(n); for(int i = 0; i < n; i++){ cin >> ans[i]; ans[i] += val; } return ans; } template <typename T> void printvec(vector<T> const& a,T val){ int n = a.size(); for(int i = 0; i < n; i++){ cout << (a[i] + val); if(i != n - 1)cout << ' '; } cout << '\n'; } #define MULTI_TEST_CASE false void solve(void){ //問題を見たらまず「この問題設定から言えること」をいっぱい言う //一個回答に繋がりそうな解法が見えても、実装や細かい詰めに時間がかかりそうなら別の方針を考えてみる //添え字回りで面倒になりそうなときは楽になる言い換えを実装の前にじっくり考える //ある程度考察しても全然取っ掛かりが見えないときは実験をしてみる //よりシンプルな問題に言い換えられたら、言い換えた先の問題を自然言語ではっきりと書く int n,x,y; cin >> n >> x >> y; vector<ll> a(x + y),b(x + y); for(int i = 0; i < n; i++){ ll p; char c; cin >> p >> c; if(c == 'A')a[i % (x + y)] += p; if(c == 'B')b[i % (x + y)] += p; } vector<tuple<ll,ll,ll>> v(x + y); for(int i = 0; i < x + y; i++){ v[i] = tuple(a[i] - b[i],a[i],b[i]); } sort(v.rbegin(),v.rend()); ll ans = 0; for(int i = 0; i < x; i++){ ll temp,temp2,temp3; tie(temp,temp2,temp3) = v[i]; ans += temp2; } for(int i = x; i < x + y; i++){ ll temp,temp2,temp3; tie(temp,temp2,temp3) = v[i]; ans += temp3; } cout << ans << El; return; } void calc(void){ return; } signed main(void){ cin.tie(nullptr); ios::sync_with_stdio(false); calc(); int t = 1; if(MULTI_TEST_CASE)cin >> t; while(t--){ solve(); } return 0; }