More questions

This commit is contained in:
2026-09-24 13:32:35 +01:00
parent 218fd77c8c
commit ef9a67918e
15 changed files with 499 additions and 23 deletions
+1
View File
@@ -0,0 +1 @@
https://codeforces.com/contest/2259/problem/C
View File
+99
View File
@@ -0,0 +1,99 @@
#include <iostream>
#include <vector>
using namespace std;
// ----- TYPES -----
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
// ----- FILE IO -----
#define STDIN(filename) freopen(filename, "r", stdin)
#define STDOUT(filename) freopen(filename, "w", stdout)
#define FASTIO cin.tie(0)->sync_with_stdio(0)
#define STDIO(filename) \
FASTIO; \
string filenamee(filename); \
STDIN((filenamee + ".in").c_str()); \
STDOUT((filenamee + ".out").c_str())
#define NL '\n'
#define CM ", "
// ----- FOR LOOPS -----
#define F(i, L, R) for (int i = L; i < R; i++)
#define FE(i, L, R) for (int i = L; i <= R; i++)
#define FD(i, L, R) for (int i = L; i > R; i--)
#define FDE(i, L, R) for (int i = L; i >= R; i--)
// ----- WEZ -----
#define takeI(n) \
int n; \
cin >> n
#define takeII(n, m) \
int n, m; \
cin >> n >> m
#define takeIII(n, m, k) \
int n, m, k; \
cin >> n >> m >> k
#define takeL(n) \
ll n; \
cin >> n
#define takeS(s) \
string s; \
cin >> s
#define takeV(v, n) \
vi v(n); \
for (auto &x : v) \
cin >> x
#define takeVL(v, n) \
vector<ll> v(n); \
for (auto &x : v) \
cin >> x
#define whileZ \
takeI(T); \
while (T--)
//
// ----- MAX MIN -----
#define REMAX(a, b) (a) = max((a), (b))
#define REMIN(a, b) (a) = min((a), (b))
// ----- PAIRS -----
#define fi first
#define se second
// ----- OUTPUT -----
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
// ----- DEBUG -----
#define DBG(vari) cerr << #vari << " = " << (vari) << endl
#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ')
#define printV(a) printA(a, 0, SZ(a) - 1)
// ----- STL DS
#define ALL(c) (c).begin(), (c).end()
#define SZ(c) ((int)(c).size())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(ALL(c), greater<>())
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
#define pb push_back
int main() {
FASTIO;
whileZ {
takeI(n);
takeV(a, n);
int i = 0;
for (; i < n; i++) if (a[i] == -1 || a[i] == 1) break;
if (i != n) a[i] = 1;
int j = n-1;
for (; j >= 0; j--) if (a[j] == -1 || a[j] == 1) break;
if (j >= 0) a[j] = 1;
for (int i = 0; i < n; i++) if (a[i] == -1) a[i] = 0;
for (auto x : a) cout << x << ' ';
}
}
+1
View File
@@ -0,0 +1 @@
https://codeforces.com/contest/2259/problem/D
+132
View File
@@ -0,0 +1,132 @@
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
// ----- TYPES -----
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
// ----- FILE IO -----
#define STDIN(filename) freopen(filename, "r", stdin)
#define STDOUT(filename) freopen(filename, "w", stdout)
#define FASTIO cin.tie(0)->sync_with_stdio(0)
#define STDIO(filename) \
FASTIO; \
string filenamee(filename); \
STDIN((filenamee + ".in").c_str()); \
STDOUT((filenamee + ".out").c_str())
#define NL '\n'
#define CM ", "
// ----- FOR LOOPS -----
#define F(i, L, R) for (int i = L; i < R; i++)
#define FE(i, L, R) for (int i = L; i <= R; i++)
#define FD(i, L, R) for (int i = L; i > R; i--)
#define FDE(i, L, R) for (int i = L; i >= R; i--)
// ----- WEZ -----
#define takeI(n) \
int n; \
cin >> n
#define takeII(n, m) \
int n, m; \
cin >> n >> m
#define takeIII(n, m, k) \
int n, m, k; \
cin >> n >> m >> k
#define takeL(n) \
ll n; \
cin >> n
#define takeS(s) \
string s; \
cin >> s
#define takeV(v, n) \
vi v(n); \
for (auto &x : v) \
cin >> x
#define takeVL(v, n) \
vector<ll> v(n); \
for (auto &x : v) \
cin >> x
#define whileZ \
takeI(T); \
while (T--)
//
// ----- MAX MIN -----
#define REMAX(a, b) (a) = max((a), (b))
#define REMIN(a, b) (a) = min((a), (b))
// ----- PAIRS -----
#define fi first
#define se second
// ----- OUTPUT -----
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
// ----- DEBUG -----
#define DBG(vari) cerr << #vari << " = " << (vari) << endl
#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ')
#define printV(a) printA(a, 0, SZ(a) - 1)
// ----- STL DS
#define ALL(c) (c).begin(), (c).end()
#define SZ(c) ((int)(c).size())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(ALL(c), greater<>())
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
#define pb push_back
int main() {
FASTIO;
takeI(t);
while (t--) {
takeI(n);
takeV(a, n);
sort(a.begin(), a.end());
/**
* Suppose MEX(A) == MEX(B) == MEX(C)
* then we have 3*MEX(A) >= 2 * MEX(A)
* which is valid
*
* Let MEX(A) be maximal of A,B,C
* We get: MEX(B) + MEX(C) >= MEX(A)
* So if MEX(A) = 4, MEX(B) + MEX(C) >= 4
* If MEX(B) or MEX(C) == MEX(A) we're good
* It seems we just populate A,B,C accordingly
*/
// Track mexes
int mex[3];
// Track idx to place in mex
int i = 0;
// Track previous
int prev = a[0], sameCount = 1;
for (auto x : a) {
// Check similar to prev
if (x == prev) {
sameCount++;
continue;
}
// Remaining = 3 - sameCount
int remaining = 3 - sameCount;
// Insert into mexes
while (remaining > 0 && i < 3) {
mex[i++] = prev;
}
if (x != prev + 1) {
while (i < 3) mex[i++] = x;
break;
}
prev = x;
sameCount = 1;
}
}
}
+1
View File
@@ -0,0 +1 @@
https://codeforces.com/contest/2259/problem/B
+95
View File
@@ -0,0 +1,95 @@
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
// ----- TYPES -----
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
// ----- FILE IO -----
#define STDIN(filename) freopen(filename, "r", stdin)
#define STDOUT(filename) freopen(filename, "w", stdout)
#define FASTIO cin.tie(0)->sync_with_stdio(0)
#define STDIO(filename) \
FASTIO; \
string filenamee(filename); \
STDIN((filenamee + ".in").c_str()); \
STDOUT((filenamee + ".out").c_str())
#define NL '\n'
#define CM ", "
// ----- FOR LOOPS -----
#define F(i, L, R) for (int i = L; i < R; i++)
#define FE(i, L, R) for (int i = L; i <= R; i++)
#define FD(i, L, R) for (int i = L; i > R; i--)
#define FDE(i, L, R) for (int i = L; i >= R; i--)
// ----- WEZ -----
#define takeI(n) \
int n; \
cin >> n
#define takeII(n, m) \
int n, m; \
cin >> n >> m
#define takeIII(n, m, k) \
int n, m, k; \
cin >> n >> m >> k
#define takeL(n) \
ll n; \
cin >> n
#define takeS(s) \
string s; \
cin >> s
#define takeV(v, n) \
vi v(n); \
for (auto &x : v) \
cin >> x
#define takeVL(v, n) \
vector<ll> v(n); \
for (auto &x : v) \
cin >> x
#define whileZ \
takeI(T); \
while (T--)
//
// ----- MAX MIN -----
#define REMAX(a, b) (a) = max((a), (b))
#define REMIN(a, b) (a) = min((a), (b))
// ----- PAIRS -----
#define fi first
#define se second
// ----- OUTPUT -----
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
// ----- DEBUG -----
#define DBG(vari) cerr << #vari << " = " << (vari) << endl
#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ')
#define printV(a) printA(a, 0, SZ(a) - 1)
// ----- STL DS
#define ALL(c) (c).begin(), (c).end()
#define SZ(c) ((int)(c).size())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(ALL(c), greater<>())
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
#define pb push_back
// 0 -> 2 -> 0
// 1 -> 1
// 2 -> 0 -> 2
int main() {
FASTIO;
whileZ {
takeI(n);
takeV(a, n);
int buckets[4] = {};
for (auto x : a) buckets[x%4]++;
cout << max({buckets[0], buckets[2], buckets[1] + buckets[3]}) << '\n';
}
}
View File
+12
View File
@@ -0,0 +1,12 @@
5
2
1 3
4
1 1 1 2
3
6 7 8
4
2 2 2 2
5
1 10 100 1000 100000
+1
View File
@@ -0,0 +1 @@
https://codeforces.com/contest/2259/problem/A
+98
View File
@@ -0,0 +1,98 @@
#include <iostream>
#include <vector>
using namespace std;
// ----- TYPES -----
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
// ----- FILE IO -----
#define STDIN(filename) freopen(filename, "r", stdin)
#define STDOUT(filename) freopen(filename, "w", stdout)
#define FASTIO cin.tie(0)->sync_with_stdio(0)
#define STDIO(filename) \
FASTIO; \
string filenamee(filename); \
STDIN((filenamee + ".in").c_str()); \
STDOUT((filenamee + ".out").c_str())
#define NL '\n'
#define CM ", "
// ----- FOR LOOPS -----
#define F(i, L, R) for (int i = L; i < R; i++)
#define FE(i, L, R) for (int i = L; i <= R; i++)
#define FD(i, L, R) for (int i = L; i > R; i--)
#define FDE(i, L, R) for (int i = L; i >= R; i--)
// ----- WEZ -----
#define takeI(n) \
int n; \
cin >> n
#define takeII(n, m) \
int n, m; \
cin >> n >> m
#define takeIII(n, m, k) \
int n, m, k; \
cin >> n >> m >> k
#define takeL(n) \
ll n; \
cin >> n
#define takeS(s) \
string s; \
cin >> s
#define takeV(v, n) \
vi v(n); \
for (auto &x : v) \
cin >> x
#define takeVL(v, n) \
vector<ll> v(n); \
for (auto &x : v) \
cin >> x
#define whileZ \
takeI(T); \
while (T--)
//
// ----- MAX MIN -----
#define REMAX(a, b) (a) = max((a), (b))
#define REMIN(a, b) (a) = min((a), (b))
// ----- PAIRS -----
#define fi first
#define se second
// ----- OUTPUT -----
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
// ----- DEBUG -----
#define DBG(vari) cerr << #vari << " = " << (vari) << endl
#define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
#define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ')
#define printV(a) printA(a, 0, SZ(a) - 1)
// ----- STL DS
#define ALL(c) (c).begin(), (c).end()
#define SZ(c) ((int)(c).size())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(ALL(c), greater<>())
#define UNIQ(c) SORT(c), (c).erase(unique(ALL(c)), (c).end())
#define pb push_back
int main() {
FASTIO;
takeI(t);
while (t--) {
takeII(n, k);
takeS(s);
int res = 0;
for (int i = 0; i < n/k; i++) {
int offset = i*k;
bool seen = false;
for (int j = 0; j < k; j++) {
if (s[offset + j] == '0') {seen = true; break;};
}
if (!seen) res++;
}
cout << res << endl;
}
}
+14
View File
@@ -0,0 +1,14 @@
6
8 2
10011100
5 1
11111
8 4
01111110
5 1
00101
4 4
1101
4 4
1111
+45 -23
View File
@@ -4,37 +4,59 @@ using namespace std;
// ----- TYPES ----- // ----- TYPES -----
typedef long long ll; typedef long long ll;
typedef pair<int,int> pii; typedef pair<int, int> pii;
typedef vector<int> vi; typedef vector<int> vi;
// ----- FILE IO ----- // ----- FILE IO -----
#define STDIN(filename) freopen(filename, "r", stdin) #define STDIN(filename) freopen(filename, "r", stdin)
#define STDOUT(filename) freopen(filename, "w", stdout) #define STDOUT(filename) freopen(filename, "w", stdout)
#define FASTIO cin.tie(0)->sync_with_stdio(0) #define FASTIO cin.tie(0)->sync_with_stdio(0)
#define STDIO(filename) FASTIO; string filenamee(filename); STDIN((filenamee + ".in").c_str()); STDOUT((filenamee + ".out").c_str()) #define STDIO(filename) \
FASTIO; \
string filenamee(filename); \
STDIN((filenamee + ".in").c_str()); \
STDOUT((filenamee + ".out").c_str())
#define NL '\n' #define NL '\n'
#define CM ", " #define CM ", "
#define SP " " #define SP " "
// ----- FOR LOOPS ----- // ----- FOR LOOPS -----
#define F(i,L,R) for (int i = L; i < R; i++) #define F(i, L, R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++) #define FE(i, L, R) for (int i = L; i <= R; i++)
#define FD(i,L,R) for (int i = L; i > R; i--) #define FD(i, L, R) for (int i = L; i > R; i--)
#define FDE(i,L,R) for (int i = L; i >= R; i--) #define FDE(i, L, R) for (int i = L; i >= R; i--)
// ----- WEZ ----- // ----- WEZ -----
#define takeI(n) int n; cin >> n #define takeI(n) \
#define takeII(n,m) int n, m; cin >> n >> m int n; \
#define takeIII(n,m,k) int n, m, k; cin >> n >> m >> k cin >> n
#define takeL(n) ll n; cin >> n #define takeII(n, m) \
#define takeS(s) string s; cin >> s int n, m; \
#define takeV(v,n) vi v(n); for (auto &x : v) cin >> x cin >> n >> m
#define takeVL(v,n) vector<ll> v(n); for (auto &x : v) cin >> x #define takeIII(n, m, k) \
#define whileZ takeI(T); while(T--) int n, m, k; \
cin >> n >> m >> k
#define takeL(n) \
ll n; \
cin >> n
#define takeS(s) \
string s; \
cin >> s
#define takeV(v, n) \
vi v(n); \
for (auto &x : v) \
cin >> x
#define takeVL(v, n) \
vector<ll> v(n); \
for (auto &x : v) \
cin >> x
#define whileZ \
takeI(T); \
while (T--)
// //
// ----- MAX MIN ----- // ----- MAX MIN -----
#define REMAX(a,b) (a)=max((a),(b)) #define REMAX(a, b) (a) = max((a), (b))
#define REMIN(a,b) (a)=min((a),(b)) #define REMIN(a, b) (a) = min((a), (b))
// ----- PAIRS ----- // ----- PAIRS -----
#define fi first #define fi first
@@ -44,13 +66,13 @@ typedef vector<int> vi;
#define YESNO(b) cout << ((b) ? "YES" : "NO") << NL #define YESNO(b) cout << ((b) ? "YES" : "NO") << NL
// ----- DEBUG ----- // ----- DEBUG -----
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl #define DBG(vari) cerr << #vari << " = " << (vari) << endl
#define DBG2(a,b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl #define DBG2(a, b) cerr << #a "=" << (a) << CM << #b "=" << (b) << endl
#define printA(a,L,R) FE(i,L,R) cerr << a[i] << (i==R?'\n':' ') #define printA(a, L, R) FE(i, L, R) cerr << a[i] << (i == R ? '\n' : ' ')
#define printV(a) printA(a,0,SZ(a)-1) #define printV(a) printA(a, 0, SZ(a) - 1)
// ----- STL DS // ----- STL DS
#define ALL(c) (c).begin(),(c).end() #define ALL(c) (c).begin(), (c).end()
#define SZ(c) ((int)(c).size()) #define SZ(c) ((int)(c).size())
#define SORT(c) sort(ALL(c)) #define SORT(c) sort(ALL(c))
#define RSORT(c) sort(ALL(c), greater<>()) #define RSORT(c) sort(ALL(c), greater<>())