File tree Expand file tree Collapse file tree 5 files changed +279
-0
lines changed
Expand file tree Collapse file tree 5 files changed +279
-0
lines changed Original file line number Diff line number Diff line change 1+ /* *
2+ * @file 2104A.cpp
3+ * @author Macesuted ([email protected] ) 4+ * @date 2025-04-28
5+ *
6+ * @copyright Copyright (c) 2025
7+ *
8+ */
9+
10+ #include < bits/stdc++.h>
11+ using namespace std ;
12+
13+ #ifndef LOCAL
14+ #define endl ' \n '
15+ #endif
16+
17+ bool mem1;
18+
19+ void solve (void ) {
20+ int a, b, c;
21+ cin >> a >> b >> c;
22+ cout << (((a + b + c) % 3 == 0 && c - b >= b - a) ? " YES" : " NO" ) << endl;
23+ return ;
24+ }
25+
26+ bool mem2;
27+
28+ int main () {
29+ ios::sync_with_stdio (false ), cin.tie (nullptr );
30+ #ifdef LOCAL
31+ cerr << " Memory Cost: " << abs (&mem1 - &mem2) / 1024 . / 1024 . << " MB" << endl;
32+ #endif
33+
34+ int _ = 1 ;
35+ cin >> _;
36+ while (_--) solve ();
37+
38+ #ifdef LOCAL
39+ cerr << " Time Cost: " << clock () * 1000 . / CLOCKS_PER_SEC << " MS" << endl;
40+ #endif
41+ return 0 ;
42+ }
Original file line number Diff line number Diff line change 1+ /* *
2+ * @file 2104B.cpp
3+ * @author Macesuted ([email protected] ) 4+ * @date 2025-04-28
5+ *
6+ * @copyright Copyright (c) 2025
7+ *
8+ */
9+
10+ #include < bits/stdc++.h>
11+ using namespace std ;
12+
13+ #ifndef LOCAL
14+ #define endl ' \n '
15+ #endif
16+
17+ bool mem1;
18+
19+ #define maxn 200005
20+
21+ int a[maxn], mv[maxn];
22+
23+ void solve (void ) {
24+ int n;
25+ cin >> n;
26+ for (int i = 1 ; i <= n; i++) cin >> a[i], mv[i] = max (mv[i - 1 ], a[i]);
27+ int64_t sum = 0 ;
28+ for (int i = n; i; i--) {
29+ sum += a[i];
30+ cout << sum + max (0 , mv[i - 1 ] - a[i]) << ' ' ;
31+ }
32+ cout << endl;
33+ return ;
34+ }
35+
36+ bool mem2;
37+
38+ int main () {
39+ ios::sync_with_stdio (false ), cin.tie (nullptr );
40+ #ifdef LOCAL
41+ cerr << " Memory Cost: " << abs (&mem1 - &mem2) / 1024 . / 1024 . << " MB" << endl;
42+ #endif
43+
44+ int _ = 1 ;
45+ cin >> _;
46+ while (_--) solve ();
47+
48+ #ifdef LOCAL
49+ cerr << " Time Cost: " << clock () * 1000 . / CLOCKS_PER_SEC << " MS" << endl;
50+ #endif
51+ return 0 ;
52+ }
Original file line number Diff line number Diff line change 1+ /* *
2+ * @file 2104C.cpp
3+ * @author Macesuted ([email protected] ) 4+ * @date 2025-04-28
5+ *
6+ * @copyright Copyright (c) 2025
7+ *
8+ */
9+
10+ #include < bits/stdc++.h>
11+ using namespace std ;
12+
13+ #ifndef LOCAL
14+ #define endl ' \n '
15+ #endif
16+
17+ bool mem1;
18+
19+ void solve (void ) {
20+ int n;
21+ string s;
22+ cin >> n >> s, s = ' ' + s;
23+ if (s[n] == ' A' ) {
24+ if (s[1 ] == ' A' || s[n - 1 ] == ' A' )
25+ cout << " Alice" << endl;
26+ else
27+ cout << " Bob" << endl;
28+ } else {
29+ for (int i = 1 ; i < n; i++)
30+ if (s[i] == ' B' ) return cout << " Bob" << endl, void ();
31+ cout << " Alice" << endl;
32+ }
33+ return ;
34+ }
35+
36+ bool mem2;
37+
38+ int main () {
39+ ios::sync_with_stdio (false ), cin.tie (nullptr );
40+ #ifdef LOCAL
41+ cerr << " Memory Cost: " << abs (&mem1 - &mem2) / 1024 . / 1024 . << " MB" << endl;
42+ #endif
43+
44+ int _ = 1 ;
45+ cin >> _;
46+ while (_--) solve ();
47+
48+ #ifdef LOCAL
49+ cerr << " Time Cost: " << clock () * 1000 . / CLOCKS_PER_SEC << " MS" << endl;
50+ #endif
51+ return 0 ;
52+ }
Original file line number Diff line number Diff line change 1+ /* *
2+ * @file 2104D.cpp
3+ * @author Macesuted ([email protected] ) 4+ * @date 2025-04-28
5+ *
6+ * @copyright Copyright (c) 2025
7+ *
8+ */
9+
10+ #include < bits/stdc++.h>
11+ using namespace std ;
12+
13+ #ifndef LOCAL
14+ #define endl ' \n '
15+ #endif
16+
17+ bool mem1;
18+
19+ #define maxv 8000005
20+ #define maxn 400005
21+
22+ bool notp[maxv];
23+ vector<int > prime;
24+ int64_t sum[maxn];
25+ int a[maxn];
26+
27+ void solve (void ) {
28+ int n;
29+ cin >> n;
30+ int64_t tot = 0 ;
31+ for (int i = 1 ; i <= n; i++) cin >> a[i], tot += a[i];
32+ sort (a + 1 , a + n + 1 );
33+ int ans = 0 ;
34+ while (ans < n - 1 && tot < sum[n - ans]) tot -= a[++ans];
35+ cout << ans << endl;
36+ return ;
37+ }
38+
39+ bool mem2;
40+
41+ int main () {
42+ ios::sync_with_stdio (false ), cin.tie (nullptr );
43+ #ifdef LOCAL
44+ cerr << " Memory Cost: " << abs (&mem1 - &mem2) / 1024 . / 1024 . << " MB" << endl;
45+ #endif
46+
47+ for (int i = 2 ; i < maxv; i++) {
48+ if (!notp[i]) prime.push_back (i);
49+ for (auto j = prime.begin (); i * *j < maxv; j++) {
50+ notp[i * *j] = true ;
51+ if (i % *j == 0 ) break ;
52+ }
53+ }
54+
55+ for (int i = 1 ; i < maxn; i++) sum[i] = sum[i - 1 ] + prime[i - 1 ];
56+
57+ int _ = 1 ;
58+ cin >> _;
59+ while (_--) solve ();
60+
61+ #ifdef LOCAL
62+ cerr << " Time Cost: " << clock () * 1000 . / CLOCKS_PER_SEC << " MS" << endl;
63+ #endif
64+ return 0 ;
65+ }
Original file line number Diff line number Diff line change 1+ /* *
2+ * @file 2104E.cpp
3+ * @author Macesuted ([email protected] ) 4+ * @date 2025-04-28
5+ *
6+ * @copyright Copyright (c) 2025
7+ *
8+ */
9+
10+ #include < bits/stdc++.h>
11+ using namespace std ;
12+
13+ #ifndef LOCAL
14+ #define endl ' \n '
15+ #endif
16+
17+ bool mem1;
18+
19+ #define maxn 1000005
20+
21+ int nxt[maxn][26 ], f[maxn];
22+
23+ void solve (void ) {
24+ int n, k;
25+ cin >> n >> k;
26+ string s;
27+ cin >> s, s = ' ' + s;
28+
29+ f[n + 1 ] = 0 ;
30+ f[n] = 1 ;
31+ for (int i = 0 ; i < k; i++) nxt[n][i] = nxt[n + 1 ][i] = n + 1 ;
32+ for (int i = n - 1 ; ~i; i--) {
33+ for (int j = 0 ; j < k; j++) nxt[i][j] = nxt[i + 1 ][j];
34+ nxt[i][s[i + 1 ] - ' a' ] = i + 1 ;
35+
36+ f[i] = INT_MAX;
37+ for (int j = 0 ; j < k; j++) f[i] = min (f[i], f[nxt[i][j]] + 1 );
38+ }
39+
40+ int q;
41+ cin >> q;
42+ while (q--) {
43+ string t;
44+ cin >> t;
45+ int p = 0 ;
46+ for (char c : t) p = nxt[p][c - ' a' ];
47+ cout << f[p] << endl;
48+ }
49+
50+ return ;
51+ }
52+
53+ bool mem2;
54+
55+ int main () {
56+ ios::sync_with_stdio (false ), cin.tie (nullptr );
57+ #ifdef LOCAL
58+ cerr << " Memory Cost: " << abs (&mem1 - &mem2) / 1024 . / 1024 . << " MB" << endl;
59+ #endif
60+
61+ int _ = 1 ;
62+ while (_--) solve ();
63+
64+ #ifdef LOCAL
65+ cerr << " Time Cost: " << clock () * 1000 . / CLOCKS_PER_SEC << " MS" << endl;
66+ #endif
67+ return 0 ;
68+ }
You can’t perform that action at this time.
0 commit comments