Submission #12897574


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int Q;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> Q;

	deque<pair<char, int>> deq;

	rep(_, 0, Q) {
		int t; cin >> t;
		if (t == 1) {
			char c; int x; cin >> c >> x;
			deq.push_back({ c, x });
		}
		else {
			int d; cin >> d;

			map<char, int> del;
			while (0 < d) {
				if (deq.size() == 0) break;

				auto p = deq.front(); deq.pop_front();

				int de = min(d, p.second);
				del[p.first] += de;
				p.second -= de;
				d -= de;

				if (0 < p.second) deq.push_front(p);
			}

			ll ans = 0;
			fore(p, del) ans += 1LL * p.second * p.second;
			printf("%lld\n", ans);
		}
	}
}





Submission Info

Submission Time
Task G - String Query
User hamayanhamayan
Language C++ (GCC 9.2.1)
Score 6
Code Size 1990 Byte
Status AC
Exec Time 25 ms
Memory 4480 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 6 / 6
Status
AC × 3
AC × 33
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 2 ms 3576 KB
02.txt AC 2 ms 3572 KB
03.txt AC 2 ms 3700 KB
04.txt AC 2 ms 3728 KB
05.txt AC 2 ms 3584 KB
06.txt AC 2 ms 3756 KB
07.txt AC 2 ms 3584 KB
08.txt AC 2 ms 3728 KB
09.txt AC 2 ms 3652 KB
10.txt AC 2 ms 3656 KB
11.txt AC 19 ms 3900 KB
12.txt AC 22 ms 3972 KB
13.txt AC 12 ms 3792 KB
14.txt AC 13 ms 3752 KB
15.txt AC 5 ms 3720 KB
16.txt AC 16 ms 3780 KB
17.txt AC 15 ms 3860 KB
18.txt AC 25 ms 3996 KB
19.txt AC 15 ms 3748 KB
20.txt AC 7 ms 3684 KB
21.txt AC 23 ms 4104 KB
22.txt AC 25 ms 4160 KB
23.txt AC 23 ms 4112 KB
24.txt AC 24 ms 4088 KB
25.txt AC 21 ms 4480 KB
26.txt AC 2 ms 3656 KB
27.txt AC 24 ms 3964 KB
28.txt AC 15 ms 3764 KB
29.txt AC 19 ms 3920 KB
30.txt AC 12 ms 3660 KB
s1.txt AC 2 ms 3696 KB
s2.txt AC 2 ms 3752 KB
s3.txt AC 2 ms 3760 KB