Current work
This commit is contained in:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user