Current work
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
*.out
|
||||||
+171
@@ -0,0 +1,171 @@
|
|||||||
|
#include <deque>
|
||||||
|
#include <iostream>
|
||||||
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <unordered_set>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
template <typename T1, typename T2>
|
||||||
|
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &pair);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::ostream &operator<<(std::ostream &out, const std::vector<T> &vec);
|
||||||
|
|
||||||
|
template <typename T, size_t SZ>
|
||||||
|
std::ostream &operator<<(std::ostream &out, const std::array<T, SZ> &arr);
|
||||||
|
|
||||||
|
template <typename T, typename C, typename A>
|
||||||
|
std::ostream &operator<<(std::ostream &out, const std::set<T, C, A> &set);
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::ostream &operator<<(std::ostream &out, const std::multiset<T> &set);
|
||||||
|
|
||||||
|
template <typename T1, typename T2>
|
||||||
|
std::ostream &operator<<(std::ostream &out, const std::map<T1, T2> &map);
|
||||||
|
|
||||||
|
template <typename T1, typename T2>
|
||||||
|
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &pair) {
|
||||||
|
return out << '(' << pair.first << ", " << pair.second << ')';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::ostream &operator<<(std::ostream &out, const std::vector<T> &vec) {
|
||||||
|
if (vec.empty()) {
|
||||||
|
out << "[]";
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
out << '[';
|
||||||
|
for (int i = 0; i < vec.size() - 1; i++) {
|
||||||
|
out << vec[i] << ", ";
|
||||||
|
}
|
||||||
|
return out << vec.back() << ']';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, size_t SZ>
|
||||||
|
std::ostream &operator<<(std::ostream &out, const std::array<T, SZ> &arr) {
|
||||||
|
if (SZ == 0) {
|
||||||
|
out << "[]";
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
out << '[';
|
||||||
|
for (int i = 0; i < SZ - 1; i++) {
|
||||||
|
out << arr[i] << ", ";
|
||||||
|
}
|
||||||
|
return out << arr.back() << ']';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::ostream &operator<<(std::ostream &out, const std::deque<T> &deq) {
|
||||||
|
if (deq.empty()) {
|
||||||
|
out << "[]";
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
out << '[';
|
||||||
|
for (int i = 0; i < deq.size() - 1; i++) {
|
||||||
|
out << deq[i] << ", ";
|
||||||
|
}
|
||||||
|
return out << deq.back() << ']';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1, typename T2>
|
||||||
|
std::ostream &operator<<(std::ostream &out,
|
||||||
|
const std::unordered_map<T1, T2> &map) {
|
||||||
|
out << '{';
|
||||||
|
for (auto it = map.begin(); it != map.end(); it++) {
|
||||||
|
std::pair<T1, T2> element = *it;
|
||||||
|
out << element.first << ": " << element.second;
|
||||||
|
if (std::next(it) != map.end()) {
|
||||||
|
out << ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out << '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T1, typename T2>
|
||||||
|
std::ostream &operator<<(std::ostream &out, const std::map<T1, T2> &map) {
|
||||||
|
out << '{';
|
||||||
|
for (auto it = map.begin(); it != map.end(); it++) {
|
||||||
|
std::pair<T1, T2> element = *it;
|
||||||
|
out << element.first << ": " << element.second;
|
||||||
|
if (std::next(it) != map.end()) {
|
||||||
|
out << ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out << '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::ostream &operator<<(std::ostream &out, const std::unordered_set<T> &set) {
|
||||||
|
out << '{';
|
||||||
|
for (auto it = set.begin(); it != set.end(); it++) {
|
||||||
|
T element = *it;
|
||||||
|
out << element;
|
||||||
|
if (std::next(it) != set.end()) {
|
||||||
|
out << ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out << '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::ostream &operator<<(std::ostream &out, const std::multiset<T> &set) {
|
||||||
|
out << '{';
|
||||||
|
for (auto it = set.begin(); it != set.end(); it++) {
|
||||||
|
T element = *it;
|
||||||
|
out << element;
|
||||||
|
if (std::next(it) != set.end()) {
|
||||||
|
out << ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out << '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::ostream &operator<<(std::ostream &out,
|
||||||
|
const std::unordered_multiset<T> &set) {
|
||||||
|
out << '{';
|
||||||
|
for (auto it = set.begin(); it != set.end(); it++) {
|
||||||
|
T element = *it;
|
||||||
|
out << element;
|
||||||
|
if (std::next(it) != set.end()) {
|
||||||
|
out << ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out << '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename C, typename A>
|
||||||
|
std::ostream &operator<<(std::ostream &out, const std::set<T, C, A> &set) {
|
||||||
|
out << '{';
|
||||||
|
for (auto it = set.begin(); it != set.end(); it++) {
|
||||||
|
T element = *it;
|
||||||
|
out << element;
|
||||||
|
if (std::next(it) != set.end()) {
|
||||||
|
out << ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out << '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Source: https://stackoverflow.com/a/31116392/12128483
|
||||||
|
template <typename Type, unsigned N, unsigned Last> struct TuplePrinter {
|
||||||
|
static void print(std::ostream &out, const Type &value) {
|
||||||
|
out << std::get<N>(value) << ", ";
|
||||||
|
TuplePrinter<Type, N + 1, Last>::print(out, value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename Type, unsigned N> struct TuplePrinter<Type, N, N> {
|
||||||
|
static void print(std::ostream &out, const Type &value) {
|
||||||
|
out << std::get<N>(value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename... Types>
|
||||||
|
std::ostream &operator<<(std::ostream &out, const std::tuple<Types...> &value) {
|
||||||
|
out << '(';
|
||||||
|
TuplePrinter<std::tuple<Types...>, 0, sizeof...(Types) - 1>::print(out,
|
||||||
|
value);
|
||||||
|
return out << ')';
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
3
|
||||||
|
fox box
|
||||||
|
dog cat
|
||||||
|
car bus
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// ----- FILE IO -----
|
||||||
|
#define STDIN(filename) freopen(filename, "r", stdin)
|
||||||
|
#define STDOUT(filename) freopen(filename, "w", stdout)
|
||||||
|
#define NL '\n'
|
||||||
|
|
||||||
|
// ----- 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 whileZ takeI(T); while(T--)
|
||||||
|
//
|
||||||
|
// ----- MAX MIN -----
|
||||||
|
#define REMAX(a,b) (a)=max((a),(b))
|
||||||
|
#define REMIN(a,b) (a)=min((a),(b))
|
||||||
|
|
||||||
|
// ----- DEBUG -----
|
||||||
|
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl
|
||||||
|
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
|
||||||
|
#define printV(a) printA(a,0,a.size()-1)
|
||||||
|
|
||||||
|
// ----- STL DS
|
||||||
|
#define ALL(c) (c).begin(),(c).end()
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
takeI(n);
|
||||||
|
F(i, 0, n) {
|
||||||
|
}
|
||||||
|
|
||||||
|
int blocksNeeded[26];
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
from collections import Counter
|
||||||
|
|
||||||
|
read = open("blocks.in")
|
||||||
|
n = int(read.readline())
|
||||||
|
blocksNeeded = [0] * 26
|
||||||
|
|
||||||
|
for _ in range(n):
|
||||||
|
a, b = read.readline().split()
|
||||||
|
a, b = Counter(a), Counter(b)
|
||||||
|
for key in a:
|
||||||
|
if key in b:
|
||||||
|
blocksNeeded[ord(key) - ord("a")] += max(a[key], b[key])
|
||||||
|
else:
|
||||||
|
blocksNeeded[ord(key) - ord("a")] += a[key]
|
||||||
|
|
||||||
|
for key in b:
|
||||||
|
if key in a:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
blocksNeeded[ord(key) - ord("a")] += b[key]
|
||||||
|
|
||||||
|
with open("blocks.out", "w") as out:
|
||||||
|
for block in blocksNeeded:
|
||||||
|
print(block, file=out)
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
3
|
||||||
|
001
|
||||||
|
111
|
||||||
|
111
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
with open("cowtip.in") as f:
|
||||||
|
n = int(f.readline())
|
||||||
|
grid = [[int(x) for x in line if x.isnumeric()] for line in f.readlines()]
|
||||||
|
|
||||||
|
|
||||||
|
def flip_grid(grid, coord):
|
||||||
|
x, y = coord
|
||||||
|
for i in range(y + 1):
|
||||||
|
for j in range(x + 1):
|
||||||
|
grid[i][j] = int(not grid[i][j])
|
||||||
|
|
||||||
|
|
||||||
|
res = 0
|
||||||
|
for i in range(n - 1, -1, -1):
|
||||||
|
for j in range(n - 1, -1, -1):
|
||||||
|
if grid[i][j] == 1:
|
||||||
|
flip_grid(grid, (j, i))
|
||||||
|
res += 1
|
||||||
|
|
||||||
|
print(res, file=open("cowtip.out", "w"))
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
int n;
|
||||||
|
cin >> n;
|
||||||
|
|
||||||
|
vector<int> ids(n);
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
int tmp;
|
||||||
|
cin >> tmp;
|
||||||
|
ids[i] = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
int even = 0;
|
||||||
|
int odd = 0;
|
||||||
|
|
||||||
|
for (int id : ids) {
|
||||||
|
if (id % 2 == 0) {
|
||||||
|
even++;
|
||||||
|
} else {
|
||||||
|
odd++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
while (even < odd or even > odd + 1) {
|
||||||
|
if (even < odd) {
|
||||||
|
odd -= 2;
|
||||||
|
even++;
|
||||||
|
} else {
|
||||||
|
even--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << even + odd;
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
freopen("paint.in", "r", stdin);
|
||||||
|
freopen("paint.out", "w", stdout);
|
||||||
|
|
||||||
|
int a, b, c, d;
|
||||||
|
cin >> a >> b >> c >> d;
|
||||||
|
|
||||||
|
if (d < a || b < c) {
|
||||||
|
cout << (b - a) + (d - c);
|
||||||
|
} else {
|
||||||
|
cout << abs(max(b, d) - min(a, c));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
7 10
|
||||||
|
4 8
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
7
|
||||||
|
GHHHGHH
|
||||||
|
HHGGGHH
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# Farmer John orders N cows, of two breeds
|
||||||
|
# H for Holstein or G for Guernsey
|
||||||
|
|
||||||
|
# A string is the breed identifiers John originally wanted
|
||||||
|
# B string is the string when the cows arrive
|
||||||
|
|
||||||
|
read = open("breedflip.in")
|
||||||
|
n = int(read.readline())
|
||||||
|
|
||||||
|
A = read.readline()
|
||||||
|
B = read.readline()
|
||||||
|
|
||||||
|
cnt = 0
|
||||||
|
res = 0
|
||||||
|
for i in range(n):
|
||||||
|
if A[i] != B[i]:
|
||||||
|
cnt += 1
|
||||||
|
elif cnt != 0:
|
||||||
|
cnt = 0
|
||||||
|
res += 1
|
||||||
|
|
||||||
|
print(res, file=open("breedflip.out", "w"))
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
n = int(input())
|
||||||
|
|
||||||
|
xs = [int(x) for x in input().split()]
|
||||||
|
ys = [int(y) for y in input().split()]
|
||||||
|
coords = list(zip(xs, ys))
|
||||||
|
|
||||||
|
maximum_distance = 0
|
||||||
|
for i in range(n - 1):
|
||||||
|
for j in range(i + 1, n):
|
||||||
|
x, y = coords[i]
|
||||||
|
xx, yy = coords[j]
|
||||||
|
distance = (x - xx) * (x - xx) + (y - yy) * (y - yy)
|
||||||
|
maximum_distance = max(distance, maximum_distance)
|
||||||
|
|
||||||
|
print(maximum_distance)
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
10 3
|
||||||
|
11 4
|
||||||
|
12 5
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
read = open("mixmilk.in")
|
||||||
|
|
||||||
|
capacity = [0] * 3
|
||||||
|
milk = [0] * 3
|
||||||
|
|
||||||
|
|
||||||
|
for i in range(3):
|
||||||
|
capacity[i], milk[i] = [int(i) for i in read.readline().split()]
|
||||||
|
|
||||||
|
for i in range(100):
|
||||||
|
curr = i % 3
|
||||||
|
next = (i + 1) % 3
|
||||||
|
if milk[next] + milk[curr] > capacity[next]:
|
||||||
|
milk[curr] = milk[curr] - capacity[next]
|
||||||
|
milk[next] = capacity[next]
|
||||||
|
else:
|
||||||
|
milk[next] = milk[next] + milk[curr]
|
||||||
|
milk[curr] = 0
|
||||||
|
|
||||||
|
print(milk, file=open("mixmilk.out", "w"))
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
freopen("outofplace.in", "r", stdin);
|
||||||
|
size_t n;
|
||||||
|
|
||||||
|
cin >> n;
|
||||||
|
|
||||||
|
vector<int> heights(n);
|
||||||
|
|
||||||
|
for (int &height : heights) {
|
||||||
|
cin >> height;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<int> sortedHeights(heights);
|
||||||
|
sort(sortedHeights.begin(), sortedHeights.end());
|
||||||
|
|
||||||
|
int bad = 0;
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
if (sortedHeights[i] != heights[i]) {
|
||||||
|
bad++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
freopen("outofplace.out", "w", stdout);
|
||||||
|
cout << bad - 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
6
|
||||||
|
3
|
||||||
|
2
|
||||||
|
4
|
||||||
|
7
|
||||||
|
7
|
||||||
|
9
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// ----- FILE IO -----
|
||||||
|
#define STDIN(filename) freopen(filename, "r", stdin)
|
||||||
|
#define STDOUT(filename) freopen(filename, "w", stdout)
|
||||||
|
#define NL '\n'
|
||||||
|
|
||||||
|
// ----- 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)
|
||||||
|
|
||||||
|
// ----- MAX MIN -----
|
||||||
|
#define REMAX(a,b) (a)=max((a),(b))
|
||||||
|
#define REMIN(a,b) (a)=min((a),(b))
|
||||||
|
|
||||||
|
// ----- DEBUG -----
|
||||||
|
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl
|
||||||
|
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
|
||||||
|
#define printV(a) printA(a,0,a.size()-1)
|
||||||
|
|
||||||
|
// ----- STL DS
|
||||||
|
#define ALL(c) (c).begin(),(c).end()
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
STDIN("promote.in");
|
||||||
|
STDOUT("promote.out");
|
||||||
|
|
||||||
|
int bronzeBefore, bronzeAfter, silverBefore, silverAfter, goldBefore, goldAfter, platinumBefore, platinumAfter;
|
||||||
|
cin >> bronzeBefore >> bronzeAfter >> silverBefore >> silverAfter >> goldBefore >> goldAfter >> platinumBefore >> platinumAfter;
|
||||||
|
|
||||||
|
int platinumPromotion, goldPromotion, silverPromotion;
|
||||||
|
|
||||||
|
platinumPromotion = platinumAfter - platinumBefore;
|
||||||
|
|
||||||
|
goldBefore -= platinumPromotion;
|
||||||
|
goldPromotion = goldAfter - goldBefore;
|
||||||
|
|
||||||
|
silverBefore -= goldPromotion;
|
||||||
|
silverPromotion = silverAfter - silverBefore;
|
||||||
|
|
||||||
|
cout << silverPromotion << NL << goldPromotion << NL << platinumPromotion << endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
1 2
|
||||||
|
1 1
|
||||||
|
1 1
|
||||||
|
1 2
|
||||||
|
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// ----- FILE IO -----
|
||||||
|
#define STDIN(filename) freopen(filename, "r", stdin)
|
||||||
|
#define STDOUT(filename) freopen(filename, "w", stdout)
|
||||||
|
#define NL '\n'
|
||||||
|
|
||||||
|
// ----- 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 whileZ takeI(T); while(T--)
|
||||||
|
|
||||||
|
// ----- MAX MIN -----
|
||||||
|
#define REMAX(a,b) (a)=max((a),(b))
|
||||||
|
#define REMIN(a,b) (a)=min((a),(b))
|
||||||
|
|
||||||
|
// ----- DEBUG -----
|
||||||
|
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl
|
||||||
|
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
|
||||||
|
#define printV(a) printA(a,0,a.size()-1)
|
||||||
|
|
||||||
|
// ----- STL DS
|
||||||
|
#define ALL(c) (c).begin(),(c).end()
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
STDIN("shell.in");
|
||||||
|
STDOUT("shell.out");
|
||||||
|
|
||||||
|
int guesses[4];
|
||||||
|
F(i,0,4) guesses[i] = 0;
|
||||||
|
|
||||||
|
whileZ {
|
||||||
|
takeIII(a,b,g);
|
||||||
|
swap(guesses[a], guesses[b]);
|
||||||
|
guesses[g]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << *max_element(guesses, guesses + 4) << NL;
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
3
|
||||||
|
1 2 1
|
||||||
|
3 2 1
|
||||||
|
1 3 1
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
4 7 9
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
freopen("herding.in", "r", stdin);
|
||||||
|
freopen("herding.out", "w", stdout);
|
||||||
|
|
||||||
|
uint pos[3];
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
cin >> pos[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
sort(pos, pos + 3);
|
||||||
|
uint x = pos[0], y = pos[1], z = pos[2];
|
||||||
|
|
||||||
|
uint minnn = 0;
|
||||||
|
if (z == x + 2) {
|
||||||
|
minnn = 0;
|
||||||
|
} else if (y == x + 2 or z == y + 2) {
|
||||||
|
minnn = 1;
|
||||||
|
} else {
|
||||||
|
minnn = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint maxxx = max(y - x - 1, z - y - 1);
|
||||||
|
|
||||||
|
cout << minnn << '\n' << maxxx << endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
freopen("speeding.in", "r", stdin);
|
||||||
|
freopen("speeding.out", "w", stdout);
|
||||||
|
|
||||||
|
int N, M;
|
||||||
|
cin >> N >> M;
|
||||||
|
|
||||||
|
vector<pair<int, int>> speedLimits(N);
|
||||||
|
for (int i = 0; i < N; i++) {
|
||||||
|
int len, speed;
|
||||||
|
cin >> len >> speed;
|
||||||
|
speedLimits[i] = pair<int, int>(len, speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<pair<int, int>> bessieSpeeds(M);
|
||||||
|
for (int i = 0; i < M; i++) {
|
||||||
|
int len, speed;
|
||||||
|
cin >> len >> speed;
|
||||||
|
bessieSpeeds[i] = pair<int, int>(len, speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
int remainingRoad = speedLimits[0].first;
|
||||||
|
int remainingJourney = bessieSpeeds[0].first;
|
||||||
|
int res = 0, j = 0, i = 0;
|
||||||
|
|
||||||
|
while (i < N && j < M) {
|
||||||
|
res = max(res, bessieSpeeds[j].second - speedLimits[i].second);
|
||||||
|
|
||||||
|
int chunk = min(remainingRoad, remainingJourney);
|
||||||
|
remainingRoad -= chunk;
|
||||||
|
remainingJourney -= chunk;
|
||||||
|
|
||||||
|
if (remainingRoad == 0 && ++i < N) {
|
||||||
|
remainingRoad = speedLimits[i].first;
|
||||||
|
}
|
||||||
|
if (remainingJourney == 0 && ++j < M) {
|
||||||
|
remainingJourney = bessieSpeeds[j].first;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << res;
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
3 3
|
||||||
|
40 75
|
||||||
|
50 35
|
||||||
|
10 45
|
||||||
|
40 76
|
||||||
|
20 30
|
||||||
|
40 40
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
#include <set>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// ----- FILE IO -----
|
||||||
|
#define STDIN(filename) freopen(filename, "r", stdin)
|
||||||
|
#define STDOUT(filename) freopen(filename, "w", stdout)
|
||||||
|
#define NL '\n'
|
||||||
|
|
||||||
|
// ----- 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 whileZ takeI(T); while(T--)
|
||||||
|
//
|
||||||
|
// ----- MAX MIN -----
|
||||||
|
#define REMAX(a,b) (a)=max((a),(b))
|
||||||
|
#define REMIN(a,b) (a)=min((a),(b))
|
||||||
|
|
||||||
|
// ----- DEBUG -----
|
||||||
|
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl
|
||||||
|
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
|
||||||
|
#define printV(a) printA(a,0,a.size()-1)
|
||||||
|
|
||||||
|
// ----- STL DS
|
||||||
|
#define ALL(c) (c).begin(),(c).end()
|
||||||
|
|
||||||
|
int oneWinner(char** board) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int twoWinner(char** board) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
STDIN("tttt.in");
|
||||||
|
STDOUT("tttt.out");
|
||||||
|
|
||||||
|
char board[3][3];
|
||||||
|
set<char> oneWinner;
|
||||||
|
set<pair<char,char>> twoWinner;
|
||||||
|
|
||||||
|
F(i, 0, 3) {
|
||||||
|
F(j, 0, 3) {
|
||||||
|
cin >> board[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int res1 = 0, res2 = 0;
|
||||||
|
// rows
|
||||||
|
F(i,0,3) {
|
||||||
|
set<char> s;
|
||||||
|
F(j,0,3) {
|
||||||
|
s.insert(board[i][j]);
|
||||||
|
}
|
||||||
|
if (s.size() == 1) {
|
||||||
|
oneWinner.insert(*s.begin());
|
||||||
|
}
|
||||||
|
if (s.size() == 2) {
|
||||||
|
char a = *s.begin(), b = *next(s.begin());
|
||||||
|
twoWinner.insert(pair(min(a,b), max(a,b)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// cols
|
||||||
|
F(j,0,3) {
|
||||||
|
set<char> s;
|
||||||
|
F(i,0,3) {
|
||||||
|
s.insert(board[i][j]);
|
||||||
|
}
|
||||||
|
if (s.size() == 1) {
|
||||||
|
oneWinner.insert(*s.begin());
|
||||||
|
}
|
||||||
|
if (s.size() == 2) {
|
||||||
|
char a = *s.begin(), b = *next(s.begin());
|
||||||
|
twoWinner.insert(pair(min(a,b), max(a,b)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// diags
|
||||||
|
{
|
||||||
|
set<char> s;
|
||||||
|
F(i,0,3) {
|
||||||
|
s.insert(board[i][i]);
|
||||||
|
}
|
||||||
|
if (s.size() == 1) {
|
||||||
|
oneWinner.insert(*s.begin());
|
||||||
|
}
|
||||||
|
if (s.size() == 2) {
|
||||||
|
char a = *s.begin(), b = *next(s.begin());
|
||||||
|
twoWinner.insert(pair(min(a,b), max(a,b)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
set<char> s;
|
||||||
|
F(i,0,3) {
|
||||||
|
s.insert(board[2-i][i]);
|
||||||
|
}
|
||||||
|
if (s.size() == 1) {
|
||||||
|
oneWinner.insert(*s.begin());
|
||||||
|
}
|
||||||
|
if (s.size() == 2) {
|
||||||
|
char a = *s.begin(), b = *next(s.begin());
|
||||||
|
twoWinner.insert(pair(min(a,b), max(a,b)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << oneWinner.size() << NL;
|
||||||
|
cout << twoWinner.size();
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
COW
|
||||||
|
XXO
|
||||||
|
ABC
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
freopen("shuffle.in", "r", stdin);
|
||||||
|
freopen("shuffle.out", "w", stdout);
|
||||||
|
|
||||||
|
int n;
|
||||||
|
cin >> n;
|
||||||
|
|
||||||
|
vector<int> unshuffle(n);
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
int tmp;
|
||||||
|
cin >> tmp;
|
||||||
|
unshuffle[i] = tmp - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<int> ids(n);
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
cin >> ids[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
vector<int> tmp(n);
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
for (int j = 0; j < n; j++) {
|
||||||
|
tmp[j] = ids[unshuffle[j]];
|
||||||
|
}
|
||||||
|
swap(tmp, ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
cout << ids[i] << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
5
|
||||||
|
1 3 4 5 2
|
||||||
|
1234567 2222222 3333333 4444444 5555555
|
||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
3
|
||||||
|
4 10 1
|
||||||
|
8 13 3
|
||||||
|
2 6 2
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
// #include "../../debugging.h"
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
freopen("blist.in", "r", stdin);
|
||||||
|
freopen("blist.out", "w", stdout);
|
||||||
|
|
||||||
|
int n, res = 0;
|
||||||
|
cin >> n;
|
||||||
|
|
||||||
|
vector<int> bucketsAtTimeT(1000);
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
int s, t, b;
|
||||||
|
cin >> s >> t >> b;
|
||||||
|
|
||||||
|
for (int j = s; j <= t; j++) {
|
||||||
|
bucketsAtTimeT[j] += b;
|
||||||
|
res = max(res, bucketsAtTimeT[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << res;
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
n, k = [int(x) for x in input().split()]
|
||||||
|
days = [int(x) - 1 for x in input().split()]
|
||||||
|
|
||||||
|
res = k + 1
|
||||||
|
prev = days[0]
|
||||||
|
|
||||||
|
for day in days[1:]:
|
||||||
|
res = min(res + 1 + k, res + (day - prev))
|
||||||
|
prev = day
|
||||||
|
|
||||||
|
print(res)
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int M;
|
||||||
|
cin >> M;
|
||||||
|
for (int u = 0; u < M; u++) {
|
||||||
|
int n, a, b;
|
||||||
|
cin >> n >> a >> b;
|
||||||
|
vector<vector<char>> grid(n, vector<char>(n));
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
for (int j = 0; j < n; j++) {
|
||||||
|
cin >> grid[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int res = 0;
|
||||||
|
|
||||||
|
for (int i = b; i < n; i++) {
|
||||||
|
for (int j = a; j < n; j++) {
|
||||||
|
char c = grid[i][j], pc = grid[i + b][j + a];
|
||||||
|
if (c == 'B') {
|
||||||
|
if (pc == 'W') {
|
||||||
|
res = -1;
|
||||||
|
goto fin;
|
||||||
|
} else {
|
||||||
|
res += 2;
|
||||||
|
}
|
||||||
|
} else if (c == 'W') {
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
res++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fin:
|
||||||
|
cout << res;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
5
|
||||||
|
4
|
||||||
|
7
|
||||||
|
8
|
||||||
|
6
|
||||||
|
4
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// ----- FILE IO -----
|
||||||
|
#define STDIN(filename) freopen(filename, "r", stdin)
|
||||||
|
#define STDOUT(filename) freopen(filename, "w", stdout)
|
||||||
|
#define NL '\n'
|
||||||
|
|
||||||
|
// ----- 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)
|
||||||
|
|
||||||
|
// ----- MAX MIN -----
|
||||||
|
#define REMAX(a,b) (a)=max((a),(b))
|
||||||
|
#define REMIN(a,b) (a)=min((a),(b))
|
||||||
|
|
||||||
|
// ----- DEBUG -----
|
||||||
|
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl
|
||||||
|
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
|
||||||
|
#define printV(a) printA(a,0,a.size()-1)
|
||||||
|
|
||||||
|
// ----- STL DS
|
||||||
|
#define ALL(c) (c).begin(),(c).end()
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
takeI(n);
|
||||||
|
|
||||||
|
vector<int> r(n);
|
||||||
|
F(i, 0, n) {
|
||||||
|
cin >> r[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
F(i, 0, n) {
|
||||||
|
// Make the door open at every point
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// ----- FILE IO -----
|
||||||
|
#define STDIN(filename) freopen(filename, "r", stdin)
|
||||||
|
#define STDOUT(filename) freopen(filename, "w", stdout)
|
||||||
|
|
||||||
|
// ----- 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)
|
||||||
|
|
||||||
|
// ----- MAX MIN -----
|
||||||
|
#define REMAX(a,b) (a)=max((a),(b))
|
||||||
|
#define REMIN(a,b) (a)=min((a),(b))
|
||||||
|
|
||||||
|
// ----- DEBUG -----
|
||||||
|
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl
|
||||||
|
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
|
||||||
|
#define printV(a) printA(a,0,a.size()-1)
|
||||||
|
|
||||||
|
// ----- STL DS
|
||||||
|
#define ALL(c) (c).begin(),(c).end()
|
||||||
|
|
||||||
|
const int LARGE = 1e9;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
STDIN("traffic.in");
|
||||||
|
STDOUT("traffic.out");
|
||||||
|
|
||||||
|
takeI(n);
|
||||||
|
DBG(n);
|
||||||
|
|
||||||
|
vector<tuple<string, int, int>> segments(n);
|
||||||
|
F(i, 0, n) {
|
||||||
|
string str;
|
||||||
|
cin >> str;
|
||||||
|
takeII(l, u);
|
||||||
|
segments[i] = {str, l, u};
|
||||||
|
}
|
||||||
|
|
||||||
|
int fl = 0, fu = LARGE;
|
||||||
|
FDE(i, n-1, 0) {
|
||||||
|
string str;
|
||||||
|
int l, u;
|
||||||
|
str = get<0>(segments[i]); l = get<1>(segments[i]); u = get<2>(segments[i]);
|
||||||
|
|
||||||
|
if (str == "none") {
|
||||||
|
fl = max(fl, l);
|
||||||
|
fu = min(fu, u);
|
||||||
|
} else if (str == "on") {
|
||||||
|
fl -= l;
|
||||||
|
fu -= u;
|
||||||
|
fl = max(0, fl);
|
||||||
|
} else {
|
||||||
|
fl += l;
|
||||||
|
fu += u;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << fl << ' ' << fu << endl;
|
||||||
|
|
||||||
|
fl = 0, fu = LARGE;
|
||||||
|
F(i, 0, n) {
|
||||||
|
string str;
|
||||||
|
int l, u;
|
||||||
|
str = get<0>(segments[i]); l = get<1>(segments[i]); u = get<2>(segments[i]);
|
||||||
|
|
||||||
|
if (str == "none") {
|
||||||
|
fl = max(fl, l);
|
||||||
|
fu = min(fu, u);
|
||||||
|
} else if (str == "on") {
|
||||||
|
fl -= l;
|
||||||
|
fu -= u;
|
||||||
|
fl = max(0, fl);
|
||||||
|
} else {
|
||||||
|
fl += l;
|
||||||
|
fu += u;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cout << fl << ' ' << fu << endl;
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
4
|
||||||
|
on 1 1
|
||||||
|
none 10 14
|
||||||
|
none 11 15
|
||||||
|
off 2 3
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <climits>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
#include "../../debugging.h"
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// ----- FILE IO -----
|
||||||
|
#define STDIN(filename) freopen(filename, "r", stdin)
|
||||||
|
#define STDOUT(filename) freopen(filename, "w", stdout)
|
||||||
|
#define NL '\n'
|
||||||
|
|
||||||
|
// ----- 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 whileZ takeI(T); while(T--)
|
||||||
|
//
|
||||||
|
// ----- MAX MIN -----
|
||||||
|
#define REMAX(a,b) (a)=max((a),(b))
|
||||||
|
#define REMIN(a,b) (a)=min((a),(b))
|
||||||
|
|
||||||
|
// ----- DEBUG -----
|
||||||
|
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl
|
||||||
|
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
|
||||||
|
#define printV(a) printA(a,0,a.size()-1)
|
||||||
|
|
||||||
|
// ----- STL DS
|
||||||
|
#define ALL(c) (c).begin(),(c).end()
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
STDIN("mowing.in");
|
||||||
|
STDOUT("mowing.out");
|
||||||
|
|
||||||
|
map<pair<int,int>, int> seen;
|
||||||
|
int x = 0, y = 0, t = 0;
|
||||||
|
seen.insert({{x, y}, t});
|
||||||
|
int maxRes = INT_MAX;
|
||||||
|
|
||||||
|
whileZ {
|
||||||
|
char dir;
|
||||||
|
int steps;
|
||||||
|
cin >> dir >> steps;
|
||||||
|
switch (dir) {
|
||||||
|
case 'N':
|
||||||
|
F(i, 0, steps) {
|
||||||
|
t++;
|
||||||
|
y++;
|
||||||
|
if (seen.count({x,y})) maxRes = min(maxRes, t - seen[{x,y}]);
|
||||||
|
seen.insert({{x, y}, t});
|
||||||
|
}
|
||||||
|
case 'S':
|
||||||
|
F(i, 0, steps) {
|
||||||
|
t++;
|
||||||
|
y--;
|
||||||
|
if (seen.count({x,y})) maxRes = min(maxRes, t - seen[{x,y}]);
|
||||||
|
seen.insert({{x, y}, t});
|
||||||
|
}
|
||||||
|
case 'E':
|
||||||
|
F(i, 0, steps) {
|
||||||
|
t++;
|
||||||
|
x++;
|
||||||
|
if (seen.count({x,y})) maxRes = min(maxRes, t - seen[{x,y}]);
|
||||||
|
seen.insert({{x, y}, t});
|
||||||
|
}
|
||||||
|
case 'W':
|
||||||
|
F(i, 0, steps) {
|
||||||
|
t++;
|
||||||
|
x--;
|
||||||
|
if (seen.count({x,y})) maxRes = min(maxRes, t - seen[{x,y}]);
|
||||||
|
seen.insert({{x, y}, t});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
cerr << seen ;
|
||||||
|
cout << maxRes << NL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
6
|
||||||
|
N 10
|
||||||
|
E 2
|
||||||
|
S 3
|
||||||
|
W 4
|
||||||
|
S 5
|
||||||
|
E 8
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
// #include "../../debugging.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void preprocessPrices(vector<long long> &prices) {
|
||||||
|
for (int i = 1; i < prices.size(); i++) {
|
||||||
|
prices[i] = min(2 * prices[i - 1], prices[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int cheapest(const vector<long long> &prices, long long query) {
|
||||||
|
long long sum = 0;
|
||||||
|
|
||||||
|
for (int j = 0; j < prices.size(); j++) {
|
||||||
|
if (query % 2 == 1) {
|
||||||
|
sum += prices[j];
|
||||||
|
}
|
||||||
|
query /= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
int over = 2;
|
||||||
|
while (query > 0) {
|
||||||
|
if (query % 2 == 1) {
|
||||||
|
sum += over * prices.back();
|
||||||
|
}
|
||||||
|
over *= 2;
|
||||||
|
query /= 2;
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int N, Q;
|
||||||
|
cin >> N >> Q;
|
||||||
|
|
||||||
|
vector<long long> prices(N);
|
||||||
|
for (int i = 0; i < N; i++) {
|
||||||
|
cin >> prices[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
preprocessPrices(prices);
|
||||||
|
|
||||||
|
vector<long long> queries(Q);
|
||||||
|
for (int i = 0; i < Q; i++) {
|
||||||
|
cin >> queries[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < Q; i++) {
|
||||||
|
cout << cheapest(prices, queries[i]) << '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// ----- FILE IO -----
|
||||||
|
#define STDIN(filename) freopen(filename, "r", stdin)
|
||||||
|
#define STDOUT(filename) freopen(filename, "w", stdout)
|
||||||
|
#define NL '\n'
|
||||||
|
|
||||||
|
// ----- 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 whileZ takeI(T); while(T--)
|
||||||
|
//
|
||||||
|
// ----- MAX MIN -----
|
||||||
|
#define REMAX(a,b) (a)=max((a),(b))
|
||||||
|
#define REMIN(a,b) (a)=min((a),(b))
|
||||||
|
|
||||||
|
// ----- DEBUG -----
|
||||||
|
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl
|
||||||
|
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
|
||||||
|
#define printV(a) printA(a,0,a.size()-1)
|
||||||
|
|
||||||
|
// ----- STL DS
|
||||||
|
#define ALL(c) (c).begin(),(c).end()
|
||||||
|
|
||||||
|
int changesNeeded(int groupVal) {
|
||||||
|
if (groupVal < 3) {
|
||||||
|
return groupVal;
|
||||||
|
}
|
||||||
|
return 4 - groupVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fold(int x, int n) {
|
||||||
|
return x >= n ? x - n : n - 1 - x;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
takeII(n, u);
|
||||||
|
int n2 = n / 2;
|
||||||
|
|
||||||
|
vector<vector<int>> group(n2, vector<int>(n2));
|
||||||
|
vector<vector<bool>> canvas(n, vector<bool>(n));
|
||||||
|
|
||||||
|
F(i, 0, n) {
|
||||||
|
F(j, 0, n) {
|
||||||
|
char ch;
|
||||||
|
cin >> ch;
|
||||||
|
canvas[i][j] = (ch == '#');
|
||||||
|
int xx = fold(i,n2), yy = fold(j, n2);
|
||||||
|
if (canvas[i][j]) group[xx][yy] += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int res = 0;
|
||||||
|
F(i, 0, n2) F(j, 0, n2) res += changesNeeded(group[i][j]);
|
||||||
|
cout << res << NL;
|
||||||
|
|
||||||
|
F(i, 0, u) {
|
||||||
|
takeII(x, y);
|
||||||
|
x--; y--;
|
||||||
|
int xx = fold(x,n2), yy = fold(y, n2);
|
||||||
|
|
||||||
|
res -= changesNeeded(group[xx][yy]);
|
||||||
|
if (canvas[x][y]) group[xx][yy]--;
|
||||||
|
else group[xx][yy]++;
|
||||||
|
canvas[x][y] = !canvas[x][y];
|
||||||
|
res += changesNeeded(group[xx][yy]);
|
||||||
|
cout << res << NL;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
3 6
|
||||||
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#include "../../debugging.h"
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
freopen("lostcow.in", "r", stdin);
|
||||||
|
freopen("lostcow.out", "w", stdout);
|
||||||
|
|
||||||
|
/**
|
||||||
|
John has lost his cow
|
||||||
|
Bessie is at some location on a number line
|
||||||
|
John at x, Bessie at y
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
int x, y;
|
||||||
|
cin >> x >> y;
|
||||||
|
|
||||||
|
int powTwo = 1, res = 0;
|
||||||
|
while (!((x + powTwo <= y && y <= x) || (x <= y && y <= x + powTwo))) {
|
||||||
|
powTwo *= -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << res;
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int x1, x2, x3, y1, y2, y3;
|
||||||
|
cin >> x1 >> y1;
|
||||||
|
cin >> x2 >> y2;
|
||||||
|
cin >> x3 >> y3;
|
||||||
|
|
||||||
|
if (y1 > x1) {
|
||||||
|
swap(&x1, &y1)
|
||||||
|
};
|
||||||
|
int square = -1;
|
||||||
|
|
||||||
|
if (x1 == x2 == x3) {
|
||||||
|
if (y1 + y2 + y3 == x1) {
|
||||||
|
square = x1;
|
||||||
|
}
|
||||||
|
} else if (y1 == y2 == y3) {
|
||||||
|
if (x1 + x2 + x3 == y1) {
|
||||||
|
square = y1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (x1 + x2 == x3) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (square < 0) {
|
||||||
|
cout << square;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << square;
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// ----- FILE IO -----
|
||||||
|
#define STDIN(filename) freopen(filename, "r", stdin)
|
||||||
|
#define STDOUT(filename) freopen(filename, "w", stdout)
|
||||||
|
#define NL '\n'
|
||||||
|
|
||||||
|
// ----- 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 whileZ takeI(T); while(T--)
|
||||||
|
//
|
||||||
|
// ----- MAX MIN -----
|
||||||
|
#define REMAX(a,b) (a)=max((a),(b))
|
||||||
|
#define REMIN(a,b) (a)=min((a),(b))
|
||||||
|
|
||||||
|
// ----- DEBUG -----
|
||||||
|
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl
|
||||||
|
#define printA(a,L,R) FE(i,L,R) cout << a[i] << (i==R?'\n':' ')
|
||||||
|
#define printV(a) printA(a,0,a.size()-1)
|
||||||
|
|
||||||
|
// ----- STL DS
|
||||||
|
#define ALL(c) (c).begin(),(c).end()
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
takeI(n);
|
||||||
|
DBG(n);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user