new problems
This commit is contained in:
@@ -0,0 +1,154 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
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 ", "
|
||||||
|
#define SP " "
|
||||||
|
|
||||||
|
// ----- 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;
|
||||||
|
int MOD = 998244353;
|
||||||
|
|
||||||
|
takeI(t);
|
||||||
|
while (t--) {
|
||||||
|
takeI(n);
|
||||||
|
takeS(s);
|
||||||
|
int res = 0;
|
||||||
|
|
||||||
|
// The current row is represented by a string s
|
||||||
|
// of length n. Each character of s is 0, 1, or ?.
|
||||||
|
// Replace every ? with either 0 or 1.
|
||||||
|
|
||||||
|
// After replacement, for every 1≤i<n
|
||||||
|
// the two neighboring tiles si and si+1 form a domino of weight (s_i + s_i+1)
|
||||||
|
|
||||||
|
// Note that two consecutive dominoes share exactly one tile.
|
||||||
|
// The completed row is valid if every two consecutive dominoes have different weights.
|
||||||
|
|
||||||
|
// Determine the number of different
|
||||||
|
// ways to replace all ? characters so that the completed row is valid.
|
||||||
|
// Output the answer modulo 998244353.
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
Example of valid n=2 tiles
|
||||||
|
Since n = 2, we only have one domino, therefor all consecutive dominoes aren't equal
|
||||||
|
|
||||||
|
Example of n=3 tiles
|
||||||
|
We have 2 dominos, we should be more cafeful
|
||||||
|
Proceeding:
|
||||||
|
11 -> [2, ] -> Must be 0, otherwise next domino will have score 2
|
||||||
|
01 -> [1, ] -> Must be 1, otherwise next domino has score 1
|
||||||
|
10 -> [1, ] -> Can be anything
|
||||||
|
00 -> [0, ] -> Must be 1
|
||||||
|
|
||||||
|
The logic follows for the next step
|
||||||
|
Consider 0?1
|
||||||
|
? = 1 -> 011 (OK)
|
||||||
|
? = 0 -> 001 (OK)
|
||||||
|
Consider 0?0
|
||||||
|
? = 0 -> 000 (NOT OK)
|
||||||
|
? = 1 -? 010 (NOT OK)
|
||||||
|
|
||||||
|
// We want s_i != s_(i+2)
|
||||||
|
// Therefor s_(i+2) = 1 - s_i
|
||||||
|
|
||||||
|
??? will be all possible tiles of length 3
|
||||||
|
2 * 2
|
||||||
|
How can we find all poss
|
||||||
|
|
||||||
|
* */
|
||||||
|
// First digit can only be 0 or 1
|
||||||
|
for (int s0 = 0; s0 < 2; s0++) {
|
||||||
|
// Second digit can only be 0 or 1
|
||||||
|
for (int s1 = 0; s1 < 2; s1++) {
|
||||||
|
bool ok = true;
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
// Expeced value follows the formula
|
||||||
|
// If i is even, we deal with s0, else we check against s1
|
||||||
|
// To find if we deal with s0 or !s1, we need to flip bit
|
||||||
|
// With XOR, if (a,1) then we get !a, (a,0) we get a
|
||||||
|
int v = ((i%2 == 0) ? s0 : s1) ^ ((i/2) & 1);
|
||||||
|
if (s[i] != '?' && s[i] - '0' != v) {ok = false; break;}
|
||||||
|
}
|
||||||
|
res += ok;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << res << NL;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
#include <bits/stdc++.h>
|
#include <bits/stdc++.h>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
// ----- TYPES -----
|
// ----- TYPES -----
|
||||||
typedef long long ll;
|
typedef long long ll;
|
||||||
typedef pair<int,int> pii;
|
typedef pair<int,int> pii;
|
||||||
|
|||||||
@@ -0,0 +1,115 @@
|
|||||||
|
#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
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
FASTIO;
|
||||||
|
takeI(t);
|
||||||
|
while (t--) {
|
||||||
|
takeI(n);
|
||||||
|
takeS(s);
|
||||||
|
|
||||||
|
// If prefix is 1, then only option is to convert all zeros to ones
|
||||||
|
int numZeros = 0;
|
||||||
|
for (auto x : s) if (x == '0') numZeros++;
|
||||||
|
|
||||||
|
if (s[0] == '1') {
|
||||||
|
cout << numZeros << '\n';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Skip leading 0s
|
||||||
|
// Index i is at position of first 1
|
||||||
|
int seenZeros = 0, seenOnes = 0;
|
||||||
|
int i = 0; while (i < n && s[i] == '0') {seenZeros++; i++;}
|
||||||
|
|
||||||
|
// Cost to flip remaining 0s to 1s
|
||||||
|
int min_cost = numZeros - seenZeros;
|
||||||
|
for (int j = i; j < n; j++) {
|
||||||
|
if (s[j] == '1') seenOnes++;
|
||||||
|
else seenZeros++;
|
||||||
|
|
||||||
|
int curr_cost = (numZeros - seenZeros) + seenOnes;
|
||||||
|
min_cost = min(min_cost, curr_cost);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << min_cost << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
6
|
||||||
|
4
|
||||||
|
0011
|
||||||
|
4
|
||||||
|
1000
|
||||||
|
5
|
||||||
|
01000
|
||||||
|
8
|
||||||
|
01001101
|
||||||
|
7
|
||||||
|
0101010
|
||||||
|
7
|
||||||
|
0111101
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
#include <map>
|
||||||
|
#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() {
|
||||||
|
takeI(t);
|
||||||
|
while (t--) {
|
||||||
|
takeII(n, m);
|
||||||
|
takeV(b, m);
|
||||||
|
|
||||||
|
// The last occurance of bi is at i
|
||||||
|
|
||||||
|
for (int i = 0; i < m; i++)
|
||||||
|
if (i <= n)
|
||||||
|
lastIndex[b[i]] = i;
|
||||||
|
|
||||||
|
if (lastIndex.size() != n) {
|
||||||
|
cout << -1 << '\n';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto [k, v] : lastIndex) cout << k << ' ' << v << '\n';
|
||||||
|
cout << 1 << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
https://codeforces.com/problemset/problem/2264/D
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
#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);
|
||||||
|
// 1010101
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
#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);
|
||||||
|
int res = 0;
|
||||||
|
|
||||||
|
// can move a[j] to a[i]
|
||||||
|
// [ai, ai+1, ai+2 ... aj]
|
||||||
|
// [aj - (j - i), ai+1, ai+2, ... aj-1 + 1]
|
||||||
|
|
||||||
|
cout << res << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
#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
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
FASTIO;
|
||||||
|
takeI(t);
|
||||||
|
while (t--) {
|
||||||
|
takeI(n);
|
||||||
|
takeIII(a1,a2,a3);
|
||||||
|
int res = 0;
|
||||||
|
|
||||||
|
res = max({n-a1, n-a2, n-a3});
|
||||||
|
|
||||||
|
cout << res << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
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 ", "
|
||||||
|
#define SP " "
|
||||||
|
|
||||||
|
// ----- 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 redTeamScore = 0, blueTeamScore = 0;
|
||||||
|
|
||||||
|
// Initially, some s[i] = 1
|
||||||
|
// The game then lasts for k rounds.
|
||||||
|
//
|
||||||
|
// For all s[i] == 1
|
||||||
|
// Keep s[i] == 1 or if (s[i+1 % (2n)] == 0) then s[i+1 % (2n)] = 1
|
||||||
|
// Find the scores of the Red Team and the Blue Team if both teams play optimally. It can be shown that the scores under optimal play are uniquely determined.
|
||||||
|
|
||||||
|
cout << redTeamScore << SP << blueTeamScore << NL;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
#include <map>
|
||||||
|
#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);
|
||||||
|
takeV(a, n);
|
||||||
|
|
||||||
|
// We don't care if x <= k
|
||||||
|
map<int, int> multiset;
|
||||||
|
for (auto x : a) if (x > k) multiset[x]++;
|
||||||
|
|
||||||
|
// Multiset contains all 'naughty elements'
|
||||||
|
// Fastest idea is to remove largest prime factor of x
|
||||||
|
//
|
||||||
|
|
||||||
|
int fk;
|
||||||
|
// Choose an integer x>1 from the multiset
|
||||||
|
// Choose prime divisor p of x.
|
||||||
|
//
|
||||||
|
// Then
|
||||||
|
//
|
||||||
|
// Remove one occurrence of x from the multiset
|
||||||
|
// add p copies of x / p.
|
||||||
|
|
||||||
|
// Let f(k) be the minimum number of operations required
|
||||||
|
// starting from the original multiset
|
||||||
|
// until every integer in the multiset is at most k.
|
||||||
|
|
||||||
|
cout << fk << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
https://codeforces.com/contest/2184/problem/A
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
#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);
|
||||||
|
int res;
|
||||||
|
|
||||||
|
/**
|
||||||
|
|
||||||
|
Keep putting 3, 3 in each civ
|
||||||
|
We will be left with n % 6
|
||||||
|
|
||||||
|
Keep putting 2, 2 in each civ
|
||||||
|
We are left with n % 4
|
||||||
|
|
||||||
|
2 -> 2
|
||||||
|
3 -> 3
|
||||||
|
4 -> 0
|
||||||
|
5 -> 1
|
||||||
|
6 -> 0
|
||||||
|
7 -> 1
|
||||||
|
8 -> 0
|
||||||
|
9 -> 1
|
||||||
|
10 -> 0
|
||||||
|
11 -> 1
|
||||||
|
12 -> 0
|
||||||
|
|
||||||
|
* */
|
||||||
|
|
||||||
|
cout << res << NL;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
#include <bits/stdc++.h>
|
||||||
|
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 ", "
|
||||||
|
#define SP " "
|
||||||
|
|
||||||
|
// ----- 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 maxDiff(int a, int b, int c) {
|
||||||
|
return max({abs(a-b), abs(a-c), abs(b-c)});
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
FASTIO;
|
||||||
|
takeI(t);
|
||||||
|
while (t--) {
|
||||||
|
takeIII(a,b,c);
|
||||||
|
int rng = min({maxDiff(a,b,c), maxDiff(a,b,a+b), maxDiff(a,a+c,c), maxDiff(b+c, b,c)});
|
||||||
|
|
||||||
|
// Choose one of the three current integers and replace it with the sum of the other two current integers. The other two integers remain unchanged.
|
||||||
|
// Do this any number of times
|
||||||
|
// Find minumum range of integers
|
||||||
|
// (a,b,c) -> (b+c, b, c)
|
||||||
|
|
||||||
|
|
||||||
|
cout << rng << NL;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
#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--) {
|
||||||
|
long long a, b, c;
|
||||||
|
cin >> a >> b >> c;
|
||||||
|
|
||||||
|
long long res = 0;
|
||||||
|
|
||||||
|
res = max(abs(a-b), abs(a+c) - b);
|
||||||
|
|
||||||
|
cout << res << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user