buggy_code
stringlengths 11
625k
| fixed_code
stringlengths 17
625k
| bug_type
stringlengths 2
4.45k
| language
int64 0
8
| token_count
int64 5
200k
| change_count
int64 0
100
|
|---|---|---|---|---|---|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), m[] = new int[n], l[] = new int[n], c = 0;
boolean[] t = new boolean[n];
for (int i = 0; i < n; i++) {
m[i] = sc.nextInt();
}
for (int i = 0; i < n; i++)
l[(i + m[i]) % n]++;
for (int i = 0; i < n; i++) {
int j = i;
while (!t[j] && l[j] == 0) {
t[j] = true;
j = (j + m[j]) % n;
l[j]--;
}
}
for (int i : m)
c += i > 0 ? 1 : 0;
System.out.println(c);
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), m[] = new int[n], l[] = new int[n], c = 0;
boolean[] t = new boolean[n];
for (int i = 0; i < n; i++) {
m[i] = sc.nextInt();
}
for (int i = 0; i < n; i++)
l[(i + m[i]) % n]++;
for (int i = 0; i < n; i++) {
int j = i;
while (!t[j] && l[j] == 0) {
t[j] = true;
j = (j + m[j]) % n;
l[j]--;
}
}
for (int i : l)
c += i > 0 ? 1 : 0;
System.out.println(c);
}
}
|
[["-", 8, 498, 0, 195, 8, 196, 0, 514, 51, 22], ["+", 8, 498, 0, 195, 8, 196, 0, 514, 51, 22]]
| 3
| 225
| 2
|
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
constexpr int MAX = 100000;
int res;
int num[MAX], visited[MAX];
void dfs(int v, int c, const vector<int> &a) {
visited[v] = 0;
num[v] = c;
int to = (v + a[v]) % a.size();
if (visited[to] == -1) {
dfs(to, c + 1, a);
} else if (visited[to] == 0) {
res += num[v] - num[to] + 1;
return;
}
visited[v] = 1;
}
int main() {
int N;
cin >> N;
vector<int> a(N);
for (int i = 0; i < N; i++) {
cin >> a[i];
}
memset(num, -1, sizeof(num));
memset(visited, -1, sizeof(visited));
res = 0;
for (int i = 0; i < N; i++) {
if (visited[i] == -1) {
dfs(i, 1, a);
}
}
cout << res << endl;
return 0;
}
|
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
constexpr int MAX = 100000;
int res;
int num[MAX], visited[MAX];
void dfs(int v, int c, const vector<int> &a) {
visited[v] = 0;
num[v] = c;
int to = (v + a[v]) % a.size();
if (visited[to] == -1) {
dfs(to, c + 1, a);
} else if (visited[to] == 0) {
res += num[v] - num[to] + 1;
}
visited[v] = 1;
}
int main() {
int N;
cin >> N;
vector<int> a(N);
for (int i = 0; i < N; i++) {
cin >> a[i];
}
memset(num, -1, sizeof(num));
memset(visited, -1, sizeof(visited));
res = 0;
for (int i = 0; i < N; i++) {
if (visited[i] == -1) {
dfs(i, 1, a);
}
}
cout << res << endl;
return 0;
}
|
[["-", 75, 76, 0, 57, 64, 9, 0, 37, 0, 38], ["-", 75, 76, 0, 57, 64, 9, 0, 37, 0, 35]]
| 1
| 256
| 2
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int n, a[100009];
bool cycle[100009], vis1[100009], vis2[100009];
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++) {
vector<int> w;
int p = i;
while (!vis1[p]) {
p = (p + a[p]) % n;
if (vis2[p]) {
int pos = find(w.begin(), w.end(), p) - w.begin();
for (int j = pos; j < w.size(); j++)
cycle[j] = true;
break;
}
w.push_back(p);
vis2[p] = true;
}
for (int j : w)
vis1[j] = true, vis2[j] = false;
}
int cnt = 0;
for (int i = 0; i < n; i++) {
if (cycle[i])
cnt++;
}
cout << cnt << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int n, a[100009];
bool cycle[100009], vis1[100009], vis2[100009];
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++) {
vector<int> w;
int p = i;
while (!vis1[p]) {
p = (p + a[p]) % n;
if (vis2[p]) {
int pos = find(w.begin(), w.end(), p) - w.begin();
for (int j = pos; j < w.size(); j++)
cycle[w[j]] = true;
break;
}
w.push_back(p);
vis2[p] = true;
}
for (int j : w)
vis1[j] = true, vis2[j] = false;
}
int cnt = 0;
for (int i = 0; i < n; i++) {
if (cycle[i])
cnt++;
}
cout << cnt << endl;
return 0;
}
|
[["+", 0, 11, 31, 69, 341, 342, 0, 69, 28, 22], ["+", 31, 69, 341, 342, 0, 69, 341, 342, 0, 70], ["+", 31, 69, 341, 342, 0, 69, 341, 342, 0, 73]]
| 1
| 252
| 3
|
#include <algorithm>
#include <array>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef string::const_iterator State;
const int MOD = 1000000007;
const int INF = 1000000000;
typedef long long ll;
typedef vector<int> vi;
const double eps = 1e-9;
const int inf = 1e9;
typedef pair<int, int> P;
ll p = 0;
ll q = 0;
bool zerodiv = false;
string t;
int Euclid(int a, int b) {
if (b > a)
swap(a, b);
if (b == 0)
return a;
else {
return Euclid(b, a % b);
}
}
ll ppow(ll x, ll num, ll mod) {
ll ret = 1;
while (num > 0) {
if (num & 1) {
ret = (ret * x) % mod;
}
x = (x * x) % mod;
num = num >> 1;
}
return ret % mod;
}
class Parser {
public:
ll number(State &begin) {
ll ret = 0;
while (isdigit(*begin)) {
ret *= 10;
ret += (*begin - '0');
begin++;
}
return ret;
}
ll expression(State &begin) {
ll ret = term(begin);
for (;;) {
if (*begin == '+') {
begin++;
ret = (ret + term(begin)) % p;
} else if (*begin == '-') {
begin++;
ret = (ret + (p - term(begin))) % p;
} else {
break;
}
}
return ret % p;
}
ll term(State &begin) {
ll ret = factor(begin);
for (;;) {
if (*begin == '*') {
begin++;
ret = (ret * factor(begin)) % p;
} else if (*begin == '/') {
begin++;
State tmp = begin;
if (factor(tmp) == 0) {
zerodiv = true;
return 0;
}
ret = (ret * (ppow(factor(begin), p - 2, p))) % p;
} else {
break;
}
}
return ret;
}
ll factor(State &begin) {
ll ret;
if (*begin == '(') {
begin++;
ret = expression(begin);
begin++;
return ret;
} else {
ret = number(begin) % p;
}
return ret;
}
};
int main(int argc, char const *argv[]) {
getline(cin, t);
zerodiv = false;
int pindex = 0;
int lindex = 0;
int rindex = 0;
p = 0;
q = 0;
bool pointspawn = false;
int check = 1;
for (int i = 0; i < t.size(); i++) {
if (t[i] == '(')
lindex = i;
else if (t[i] == ')')
rindex = i;
else if (t[i] == '.') {
pointspawn = true;
pindex = i;
} else if (pointspawn)
check *= 10;
}
for (int i = 0; i < t.size(); i++) {
if (t[i] == '.')
continue;
else if (t[i] == '(')
break;
else {
q *= 10;
q += int(t[i] - '0');
}
}
// Parser ps;
int large = 1;
int small = 1;
int rotation = rindex - pindex - 1;
int ptorota = lindex - pindex - 1;
for (int i = 1; i < ptorota; i++) {
small *= 10;
}
for (int i = 1; i < rotation; i++) {
large *= 10;
}
while (t.find('(') != string::npos)
t.erase(t.find('('), 1);
while (t.find(')') != string::npos)
t.erase(t.find(')'), 1);
while (t.find('.') != string::npos)
t.erase(t.find('.'), 1);
while (isdigit(t[0])) {
p *= 10;
p += int(t[0] - '0');
t.erase(0, 1);
}
int molecu;
if (p != q) {
molecu = p - q;
} else {
molecu = p;
}
int denomi = large - small;
if (denomi == 0) {
denomi = check;
}
// cout << molecu << ' ' << denomi << endl;
while (Euclid(molecu, denomi) != 1) {
int div = Euclid(molecu, denomi);
molecu /= div;
denomi /= div;
}
cout << molecu << '/' << denomi << endl;
return 0;
}
|
#include <algorithm>
#include <array>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef string::const_iterator State;
const int MOD = 1000000007;
const int INF = 1000000000;
typedef long long ll;
typedef vector<int> vi;
const double eps = 1e-9;
const int inf = 1e9;
typedef pair<int, int> P;
ll p = 0;
ll q = 0;
bool zerodiv = false;
string t;
int Euclid(int a, int b) {
if (b > a)
swap(a, b);
if (b == 0)
return a;
else {
return Euclid(b, a % b);
}
}
ll ppow(ll x, ll num, ll mod) {
ll ret = 1;
while (num > 0) {
if (num & 1) {
ret = (ret * x) % mod;
}
x = (x * x) % mod;
num = num >> 1;
}
return ret % mod;
}
class Parser {
public:
ll number(State &begin) {
ll ret = 0;
while (isdigit(*begin)) {
ret *= 10;
ret += (*begin - '0');
begin++;
}
return ret;
}
ll expression(State &begin) {
ll ret = term(begin);
for (;;) {
if (*begin == '+') {
begin++;
ret = (ret + term(begin)) % p;
} else if (*begin == '-') {
begin++;
ret = (ret + (p - term(begin))) % p;
} else {
break;
}
}
return ret % p;
}
ll term(State &begin) {
ll ret = factor(begin);
for (;;) {
if (*begin == '*') {
begin++;
ret = (ret * factor(begin)) % p;
} else if (*begin == '/') {
begin++;
State tmp = begin;
if (factor(tmp) == 0) {
zerodiv = true;
return 0;
}
ret = (ret * (ppow(factor(begin), p - 2, p))) % p;
} else {
break;
}
}
return ret;
}
ll factor(State &begin) {
ll ret;
if (*begin == '(') {
begin++;
ret = expression(begin);
begin++;
return ret;
} else {
ret = number(begin) % p;
}
return ret;
}
};
int main(int argc, char const *argv[]) {
getline(cin, t);
zerodiv = false;
int pindex = 0;
int lindex = 0;
int rindex = 0;
p = 0;
q = 0;
bool pointspawn = false;
int check = 1;
for (int i = 0; i < t.size(); i++) {
if (t[i] == '(')
lindex = i;
else if (t[i] == ')')
rindex = i;
else if (t[i] == '.') {
pointspawn = true;
pindex = i;
} else if (pointspawn)
check *= 10;
}
for (int i = 0; i < t.size(); i++) {
if (t[i] == '.')
continue;
else if (t[i] == '(')
break;
else {
q *= 10;
q += int(t[i] - '0');
}
}
// Parser ps;
int large = 1;
int small = 1;
int rotation = rindex - pindex - 1;
int ptorota = lindex - pindex - 1;
for (int i = 0; i < ptorota; i++) {
small *= 10;
}
for (int i = 1; i < rotation; i++) {
large *= 10;
}
while (t.find('(') != string::npos)
t.erase(t.find('('), 1);
while (t.find(')') != string::npos)
t.erase(t.find(')'), 1);
while (t.find('.') != string::npos)
t.erase(t.find('.'), 1);
while (isdigit(t[0])) {
p *= 10;
p += int(t[0] - '0');
t.erase(0, 1);
}
int molecu;
if (p != q) {
molecu = p - q;
} else {
molecu = p;
}
int denomi = large - small;
if (denomi == 0) {
denomi = check;
}
// cout << molecu << ' ' << denomi << endl;
while (Euclid(molecu, denomi) != 1) {
int div = Euclid(molecu, denomi);
molecu /= div;
denomi /= div;
}
cout << molecu << '/' << denomi << endl;
return 0;
}
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
| 1
| 1,037
| 2
|
#include <cstring>
#include <iostream>
using namespace std;
void yaku(int a, int b) {
for (int i = 2; i <= a && i <= b; i++) {
if (a % i == 0 && b % i == 0) {
a /= i;
b /= i;
}
}
cout << a << '/' << b << endl;
}
int main(void) {
char s[9];
cin >> s;
int k = 10, x = 0, l = strlen(s), i;
for (i = 0; s[i] != '.'; i++) {
x *= 10;
x += int(s[i] - '0');
}
int m = 1;
for (i++; s[i] != '('; i++, k *= 10, m *= 10) {
x *= 10;
x += int(s[i] - '0');
if (i == l - 1) {
yaku(x, k);
return 0;
}
}
int y = x;
for (i++; s[i] != ')'; i++, k *= 10) {
x *= 10;
x += int(s[i] - '0');
}
k /= 10;
yaku(x - y, k - m);
}
|
#include <cstring>
#include <iostream>
using namespace std;
void yaku(int a, int b) {
for (int i = 2; i <= a && i <= b; i++) {
if (a % i == 0 && b % i == 0) {
a /= i;
b /= i;
i = 2;
}
}
cout << a << '/' << b << endl;
}
int main(void) {
char s[9];
cin >> s;
int k = 10, x = 0, l = strlen(s), i;
for (i = 0; s[i] != '.'; i++) {
x *= 10;
x += int(s[i] - '0');
}
int m = 1;
for (i++; s[i] != '('; i++, k *= 10, m *= 10) {
x *= 10;
x += int(s[i] - '0');
if (i == l - 1) {
yaku(x, k);
return 0;
}
}
int y = x;
for (i++; s[i] != ')'; i++, k *= 10) {
x *= 10;
x += int(s[i] - '0');
}
k /= 10;
yaku(x - y, k - m);
}
|
[["+", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35]]
| 1
| 279
| 4
|
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>
typedef long long ll;
using namespace std;
#define debug(x) cerr << #x << " = " << x << endl;
#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 3100
/* Dijkstra O(NlogM)*/
struct Dijkstra {
typedef int Type;
int V;
vector<vector<pair<int, Type>>> G;
vector<int> cost;
Dijkstra(int n) : V(n), G(n, vector<pair<int, Type>>()) {}
void add_edge(int u, int v, Type c) { G[u].push_back({v, c}); }
Type solve(int s, int g = -1) {
cost.assign(V, -1);
priority_queue<pair<Type, int>> pq;
Type max_cost = 0;
pq.push({0, s});
while (pq.size()) {
Type now_cost = pq.top().first;
int now = pq.top().second;
pq.pop();
if (cost[now] >= 0)
continue;
cost[now] = -now_cost;
max_cost = max(max_cost, -now_cost);
if (now == g)
return -now_cost;
for (int i = 0; i < (int)G[now].size(); i++) {
pq.push({now_cost - G[now][i].second, G[now][i].first});
}
}
return max_cost;
}
};
int main() {
int n, r;
int s[SIZE], t[SIZE], d[SIZE];
bool ans[SIZE] = {};
scanf("%d%d", &n, &r);
Dijkstra dij(n);
for (int i = 0; i < r; i++) {
scanf("%d%d%d", s + i, t + i, d + i);
s[i]--;
t[i]--;
dij.add_edge(t[i], s[i], d[i]);
dij.add_edge(s[i], t[i], d[i]);
}
int ans_dis = 0;
for (int i = 0; i < n; i++) {
int max_dis = dij.solve(i);
if (max_dis > ans_dis) {
for (int j = 0; j < n; j++)
ans[i] = false;
ans_dis = max_dis;
}
if (max_dis < ans_dis)
continue;
queue<int> que;
bool visited[SIZE] = {};
for (int j = 0; j < n; j++) {
if (max_dis == dij.cost[j]) {
que.push(j);
}
}
while (que.size()) {
int p = que.front();
que.pop();
if (visited[p])
continue;
visited[p] = true;
ans[p] = true;
for (int j = 0; j < dij.G[p].size(); j++) {
if (dij.cost[p] - dij.G[p][j].second == dij.cost[dij.G[p][j].first]) {
que.push(dij.G[p][j].first);
}
}
}
}
int ans_count = 0;
for (int i = 0; i < n; i++)
ans_count += ans[i] == false;
printf("%d\n", ans_count);
for (int i = 0; i < n; i++) {
if (ans[i] == false) {
printf("%d\n", i + 1);
}
}
return 0;
}
|
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>
typedef long long ll;
using namespace std;
#define debug(x) cerr << #x << " = " << x << endl;
#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 3100
/* Dijkstra O(NlogM)*/
struct Dijkstra {
typedef int Type;
int V;
vector<vector<pair<int, Type>>> G;
vector<int> cost;
Dijkstra(int n) : V(n), G(n, vector<pair<int, Type>>()) {}
void add_edge(int u, int v, Type c) { G[u].push_back({v, c}); }
Type solve(int s, int g = -1) {
cost.assign(V, -1);
priority_queue<pair<Type, int>> pq;
Type max_cost = 0;
pq.push({0, s});
while (pq.size()) {
Type now_cost = pq.top().first;
int now = pq.top().second;
pq.pop();
if (cost[now] >= 0)
continue;
cost[now] = -now_cost;
max_cost = max(max_cost, -now_cost);
if (now == g)
return -now_cost;
for (int i = 0; i < (int)G[now].size(); i++) {
pq.push({now_cost - G[now][i].second, G[now][i].first});
}
}
return max_cost;
}
};
int main() {
int n, r;
int s[SIZE], t[SIZE], d[SIZE];
bool ans[SIZE] = {};
scanf("%d%d", &n, &r);
Dijkstra dij(n);
for (int i = 0; i < r; i++) {
scanf("%d%d%d", s + i, t + i, d + i);
s[i]--;
t[i]--;
dij.add_edge(t[i], s[i], d[i]);
dij.add_edge(s[i], t[i], d[i]);
}
int ans_dis = 0;
for (int i = 0; i < n; i++) {
int max_dis = dij.solve(i);
if (max_dis > ans_dis) {
for (int j = 0; j < n; j++)
ans[j] = false;
ans_dis = max_dis;
}
if (max_dis < ans_dis)
continue;
queue<int> que;
bool visited[SIZE] = {};
for (int j = 0; j < n; j++) {
if (max_dis == dij.cost[j]) {
que.push(j);
}
}
while (que.size()) {
int p = que.front();
que.pop();
if (visited[p])
continue;
visited[p] = true;
ans[p] = true;
for (int j = 0; j < dij.G[p].size(); j++) {
if (dij.cost[p] - dij.G[p][j].second == dij.cost[dij.G[p][j].first]) {
que.push(dij.G[p][j].first);
}
}
}
}
int ans_count = 0;
for (int i = 0; i < n; i++)
ans_count += ans[i] == false;
printf("%d\n", ans_count);
for (int i = 0; i < n; i++) {
if (ans[i] == false) {
printf("%d\n", i + 1);
}
}
return 0;
}
|
[["-", 8, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["+", 8, 1, 0, 11, 31, 69, 341, 342, 0, 22]]
| 1
| 804
| 2
|
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const LL INF = 1e18;
int W, H;
vector<vector<LL>> S;
LL score(int i, int j) {
auto L = S[i + 1][j] - S[i + 1][0];
auto R = S[i + 1][W] - S[i + 1][j];
return ((i + j) & 1) ? L - R : R - L;
}
LL dfs(int i, int j) {
static vector<vector<LL>> memo(H + 1, vector<LL>(W + 1, INF));
if (memo[i][j] != INF)
return memo[i][j];
if (i == H)
return memo[i][j] = 0;
if (j == W)
return memo[i][j] = score(i, j) - dfs(i + 1, j);
return memo[i][j] = max(-dfs(i, j + 1), score(i, j) - dfs(i + 1, j));
}
int main() {
cin >> W >> H;
S.assign(H + 1, vector<LL>(W + 1));
for (auto i = 1; i <= H; ++i)
for (auto j = 1; j <= W; ++j)
cin >> S[i][j], S[i][j] += S[i][j - 1];
cout << dfs(0, 0) << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const LL INF = 1e18;
int W, H;
vector<vector<LL>> S;
LL score(int i, int j) {
auto L = S[i + 1][j] - S[i + 1][0];
auto R = S[i + 1][W] - S[i + 1][j];
return ((i + j) & 1) ? L - R : R - L;
}
LL dfs(int i, int j) {
static vector<vector<LL>> memo(H + 1, vector<LL>(W + 1, INF));
if (memo[i][j] != INF)
return memo[i][j];
if (i == H)
return memo[i][j] = 0;
if (j == W)
return memo[i][j] = score(i, j) - dfs(i + 1, j);
return memo[i][j] = max(-dfs(i, j + 1), score(i, j) - dfs(i + 1, j));
}
int main() {
cin >> W >> H;
S.assign(H + 1, vector<LL>(W + 1));
for (auto i = 1; i <= H; ++i)
for (auto j = 1; j <= W; ++j)
cin >> S[i][j], S[i][j] += S[i][j - 1];
cout << abs(dfs(0, 0)) << endl;
}
|
[["+", 0, 1, 0, 16, 31, 16, 12, 2, 63, 22], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 24], ["+", 12, 2, 3, 4, 0, 2, 3, 4, 0, 25]]
| 1
| 351
| 3
|
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
typedef set<int> Group;
Group *make_group(int num) {
Group *new_group = new Group();
new_group->insert(num);
return new_group;
}
Group *merge(Group *left, Group *right) {
if (left->size() < right->size()) {
swap(left, right);
}
for (Group::iterator it = right->begin(); it != right->end(); it++)
left->insert(*it);
return left;
}
int main() {
int N;
scanf("%d", &N);
queue<Group *> Q;
vector<int> V, WORK;
int tmp;
map<int, int> MAP;
for (int i = 0; i < N; i++) {
scanf("%d", &tmp);
V.push_back(tmp);
WORK.push_back(tmp);
}
sort(WORK.begin(), WORK.end());
for (int i = 0; i < N; i++) {
MAP[WORK[i]] = i + 1;
}
for (int i = 0; i < N; i++) {
V[i] = MAP[V[i]];
}
for (int i = 0; i < N; i++) {
Q.push(make_group(V[i]));
}
ll ans = 0;
for (int num = 1; num <= N; num++) {
Group *group = Q.front();
Q.pop();
while (true) {
if (*(group->begin()) == num) {
group->erase(group->begin());
ans += group->size();
if (group->size() > 0) {
Q.push(group);
}
break;
}
Group *next_group = Q.front();
Q.pop();
merge(group, next_group);
}
}
printf("%lld\n", ans);
return 0;
}
|
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
typedef set<int> Group;
Group *make_group(int num) {
Group *new_group = new Group();
new_group->insert(num);
return new_group;
}
Group *merge(Group *left, Group *right) {
if (left->size() < right->size()) {
swap(left, right);
}
for (Group::iterator it = right->begin(); it != right->end(); it++)
left->insert(*it);
return left;
}
int main() {
int N;
scanf("%d", &N);
queue<Group *> Q;
vector<int> V, WORK;
int tmp;
map<int, int> MAP;
for (int i = 0; i < N; i++) {
scanf("%d", &tmp);
V.push_back(tmp);
WORK.push_back(tmp);
}
sort(WORK.begin(), WORK.end());
for (int i = 0; i < N; i++) {
MAP[WORK[i]] = i + 1;
}
for (int i = 0; i < N; i++) {
V[i] = MAP[V[i]];
}
for (int i = 0; i < N; i++) {
Q.push(make_group(V[i]));
}
ll ans = 0;
for (int num = 1; num <= N; num++) {
Group *group = Q.front();
Q.pop();
while (true) {
if (*(group->begin()) == num) {
group->erase(group->begin());
ans += group->size();
if (group->size() > 0) {
Q.push(group);
}
break;
}
Group *next_group = Q.front();
Q.pop();
group = merge(group, next_group);
}
}
printf("%lld\n", ans);
return 0;
}
|
[["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 17, 32]]
| 1
| 477
| 2
|
#include <bits/stdc++.h>
using namespace std;
typedef pair<string, string> P;
int N, F, ans = 0;
map<P, int> mp;
int main() {
cin >> N >> F;
for (int i = 0; i < N; i++) {
int K;
cin >> K;
vector<string> v(K);
for (int j = 0; j < K; j++) {
cin >> v[j];
for (int k = 0; k < j; k++) {
string a = v[j];
string b = v[k];
if (a > b)
swap(a, b);
mp[P(a, b)]++;
if (mp[P(a, b)] == 3)
ans++;
}
}
}
cout << ans << endl;
map<P, int>::iterator it;
for (it = mp.begin(); it != mp.end(); it++) {
if (it->second >= F) {
cout << it->first.first << ' ' << it->first.second << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef pair<string, string> P;
int N, F, ans = 0;
map<P, int> mp;
int main() {
cin >> N >> F;
for (int i = 0; i < N; i++) {
int K;
cin >> K;
vector<string> v(K);
for (int j = 0; j < K; j++) {
cin >> v[j];
for (int k = 0; k < j; k++) {
string a = v[j];
string b = v[k];
if (a > b)
swap(a, b);
mp[P(a, b)]++;
if (mp[P(a, b)] == F)
ans++;
}
}
}
cout << ans << endl;
map<P, int>::iterator it;
for (it = mp.begin(); it != mp.end(); it++) {
if (it->second >= F) {
cout << it->first.first << ' ' << it->first.second << endl;
}
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22]]
| 1
| 244
| 2
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second
using ps = pair<string, string>;
int main() {
int n, f;
cin >> n >> f;
vector<string> name;
map<ps, int> ct;
rep(i, n) {
int m;
cin >> m;
vector<string> s(m);
rep(j, m) {
cin >> s[j];
name.pb(s[j]);
}
sort(all(s));
rep(k, m) rep(j, k)++ ct[ps(s[j], s[k])];
}
sort(all(name));
name.erase(unique(all(name)), name.end());
int N = name.size();
vector<ps> ans;
rep(j, N) rep(i, j) {
ps p(name[i], name[j]);
if (ct[p] >= f)
ans.pb(p);
}
cout << ans.size() << endl;
for (const auto &p : ans)
cout << p.fi << " " << p.se << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second
using ps = pair<string, string>;
int main() {
int n, f;
cin >> n >> f;
vector<string> name;
map<ps, int> ct;
rep(i, n) {
int m;
cin >> m;
vector<string> s(m);
rep(j, m) {
cin >> s[j];
name.pb(s[j]);
}
sort(all(s));
rep(k, m) rep(j, k)++ ct[ps(s[j], s[k])];
}
sort(all(name));
name.erase(unique(all(name)), name.end());
int N = name.size();
set<ps> ans;
rep(j, N) rep(i, j) {
ps p(name[i], name[j]);
if (ct[p] >= f)
ans.insert(p);
}
cout << ans.size() << endl;
for (const auto &p : ans)
cout << p.fi << " " << p.se << endl;
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 43, 39, 344, 141, 78], ["+", 0, 14, 8, 9, 0, 43, 39, 344, 141, 78], ["-", 0, 57, 64, 1, 0, 2, 63, 118, 119, 120], ["+", 0, 57, 64, 1, 0, 2, 63, 118, 119, 120]]
| 1
| 289
| 4
|
#include <stdbool.h>
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
bool flag[4000000];
int main(void) {
int i, j, k, n;
scanf("%d", &n);
rep(i, 4000000) flag[i] = false;
rep(i, n) {
int a, b;
scanf("%d%d", &a, &b);
a += b;
if (!flag[a])
flag[a] = true;
else {
for (i = a; i < 4000000; ++i) {
if (flag[i])
flag[i] = false;
else {
flag[i] = true;
break;
}
}
}
}
rep(i, 4000000) if (flag[i]) printf("%d 0\n", i);
return 0;
}
|
#include <stdbool.h>
#include <stdio.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
bool flag[4000000];
int main(void) {
int i, j, k, n;
scanf("%d", &n);
rep(i, 4000000) flag[i] = false;
rep(i, n) {
int a, b;
scanf("%d%d", &a, &b);
a += b;
if (!flag[a])
flag[a] = true;
else {
for (j = a; i < 4000000; ++j) {
if (flag[j])
flag[j] = false;
else {
flag[j] = true;
break;
}
}
}
/*rep(j, 9) printf("%d ", flag[j] ? 1 : 0);
printf("\n");*/
}
rep(i, 4000000) if (flag[i]) printf("%d 0\n", i);
return 0;
}
|
[["-", 75, 76, 0, 9, 0, 7, 10, 11, 31, 22], ["+", 75, 76, 0, 9, 0, 7, 10, 11, 31, 22], ["-", 75, 76, 0, 9, 0, 7, 26, 27, 28, 22], ["+", 75, 76, 0, 9, 0, 7, 26, 27, 28, 22], ["-", 0, 57, 15, 339, 51, 69, 341, 342, 0, 22], ["+", 0, 57, 15, 339, 51, 69, 341, 342, 0, 22], ["-", 64, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["+", 64, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22]]
| 1
| 173
| 10
|
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double EPS = 1e-15;
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define mp make_pair
int main() {
ll n, sum = 0, ans = 0;
std::map<ll, ll> a;
a[0] = -1;
scanf("%lld", &n);
REP(i, n) {
int tmp;
scanf("%lld", &tmp);
sum += tmp;
auto it = a.find(sum);
if (it == a.end()) {
a[sum] = i;
} else {
ans = max(ans, i - it->second);
}
}
printf("%lld\n", ans);
}
|
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double EPS = 1e-15;
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;
const ll MOD1 = 998244353;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define mp make_pair
int main() {
ll n, sum = 0, ans = 0;
std::map<ll, ll> a;
a[0] = -1;
scanf("%lld", &n);
REP(i, n) {
ll tmp;
scanf("%lld", &tmp);
sum += tmp;
auto it = a.find(sum);
if (it == a.end())
a[sum] = i;
else
ans = max(ans, i - it->second);
}
printf("%lld\n", ans);
}
|
[["-", 8, 9, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 8, 9, 0, 14, 8, 9, 0, 43, 39, 78], ["-", 0, 14, 8, 9, 0, 57, 64, 9, 0, 45], ["-", 0, 14, 8, 9, 0, 57, 64, 9, 0, 46], ["-", 8, 9, 0, 57, 75, 76, 0, 9, 0, 45], ["-", 8, 9, 0, 57, 75, 76, 0, 9, 0, 46]]
| 1
| 219
| 6
|
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
typedef long long ll;
int main() {
int n;
cin >> n;
vector<ll> vec(n);
rep(i, n) cin >> vec[i];
ll sum = 0;
map<int, int> mp;
int maxi = 0;
mp[0] = 0;
rep(i, n) {
sum += vec[i];
if (!mp.count(sum))
mp[sum] = i;
maxi = max(maxi, i - mp[sum]);
}
cout << maxi << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
typedef long long ll;
int main() {
int n;
cin >> n;
vector<ll> vec(n);
rep(i, n) cin >> vec[i];
ll sum = 0;
map<ll, int> mp;
int maxi = 0;
mp[0] = -1;
rep(i, n) {
sum += vec[i];
if (!mp.count(sum))
mp[sum] = i;
maxi = max(maxi, i - mp[sum]);
}
cout << maxi << endl;
return 0;
}
|
[["-", 0, 43, 39, 344, 3, 347, 0, 77, 39, 40], ["+", 0, 43, 39, 344, 3, 347, 0, 77, 39, 78], ["-", 0, 14, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 12, 13]]
| 1
| 145
| 4
|
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
int d[1 << 18];
map<long, long> M;
main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> d[i];
}
long s = 0, ans = 0;
for (long i = 0; i < n; i++) {
s += d[i];
if (!s)
ans = max(ans, i + 1);
if (M[s])
ans = max(ans, i - M[s]);
else
M[s] = i;
}
cout << ans << endl;
}
|
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
int d[1 << 18];
map<long, long> M;
main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> d[i];
}
long s = 0, ans = 0;
for (long i = 0; i < n; i++) {
s += d[i];
if (!s)
ans = max(ans, i + 1);
if (M[s])
ans = max(ans, i - M[s] + 1);
else
M[s] = i + 1;
}
cout << ans << endl;
}
|
[["+", 0, 11, 12, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 12, 13], ["+", 75, 76, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 75, 76, 0, 1, 0, 11, 12, 16, 12, 13]]
| 1
| 144
| 4
|
#include "bits/stdc++.h"
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define RREP(i, n) for (ll i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define RFOR(i, m, n) for (ll i = n - 1; i >= m; --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define DUMP(v) \
REP(aa, (v).size()) { \
cout << v[aa]; \
if (aa != v.size() - 1) \
cout << " "; \
else \
cout << endl; \
}
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9
const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
map<ll, ll> mp;
int n;
cin >> n;
vl v(n);
ll sum = 0;
REP(i, n) cin >> v[i];
REP(i, n) {
sum += v[i];
mp[sum] = i;
}
sum = 0;
int ans = 0;
REP(i, n) {
ans = max(ans, mp[sum] - i + 1);
sum += v[i];
}
cout << ans << endl;
}
|
#include "bits/stdc++.h"
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define RREP(i, n) for (ll i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define RFOR(i, m, n) for (ll i = n - 1; i >= m; --i)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());
#define DUMP(v) \
REP(aa, (v).size()) { \
cout << v[aa]; \
if (aa != v.size() - 1) \
cout << " "; \
else \
cout << endl; \
}
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9
const int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
map<ll, ll> mp;
int n;
cin >> n;
vl v(n);
ll sum = 0;
REP(i, n) cin >> v[i];
REP(i, n) {
sum += v[i];
mp[sum] = i + 1;
}
sum = 0;
int ans = 0;
REP(i, n) {
ans = max(ans, mp[sum] - i);
sum += v[i];
}
cout << ans << endl;
}
|
[["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 12, 13], ["-", 0, 11, 12, 2, 3, 4, 0, 16, 17, 72], ["-", 0, 11, 12, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 390
| 4
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define pb push_back
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define dep(i, a, n) for (int i = (a); i >= (n); i--)
#define mod 1e9 + 7
__attribute__((constructor)) void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
int main() {
ll n, g;
cin >> n;
ll a[n] = {};
map<ll, ll> mp;
cin >> g;
mp[0] = -1;
mp[g] = 0;
ll ans = 0;
if (g == 0)
ans = 1, mp[g] = -1;
rep(i, 1, n) {
ll d;
cin >> d;
g += d;
if (mp.count(a[i])) {
ans = max(ans, i - mp[g]);
} else
mp[g] = i;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define pb push_back
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define dep(i, a, n) for (int i = (a); i >= (n); i--)
#define mod 1e9 + 7
__attribute__((constructor)) void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
int main() {
ll n, g;
cin >> n;
ll a[n] = {};
map<ll, ll> mp;
cin >> g;
mp[0] = -1;
mp[g] = 0;
ll ans = 0;
if (g == 0)
ans = 1, mp[g] = -1;
rep(i, 1, n) {
ll d;
cin >> d;
g += d;
if (mp.count(g)) {
ans = max(ans, i - mp[g]);
} else
mp[g] = i;
}
cout << ans << endl;
}
|
[["-", 15, 339, 51, 2, 3, 4, 0, 69, 28, 22], ["-", 51, 2, 3, 4, 0, 69, 341, 342, 0, 70], ["-", 51, 2, 3, 4, 0, 69, 341, 342, 0, 22], ["-", 51, 2, 3, 4, 0, 69, 341, 342, 0, 73], ["+", 0, 57, 15, 339, 51, 2, 3, 4, 0, 22]]
| 1
| 208
| 5
|
#include <map>
#include <stdio.h>
#include <utility>
using namespace std;
typedef pair<int, int> pi;
#define F first
#define S second
#define MP make_pair
int main() {
int n, ans = 0;
long long int now = 0, temp;
map<long long int, int> m;
scanf("%d", &n);
m.insert(MP(0, -1));
for (int i = 0; i < n; i++) {
scanf("%lld", &temp);
now += temp;
if (m.find(now) != m.end())
m.insert(MP(now, i));
else
ans = max(ans, i - m[now] + 1);
}
printf("%d\n", ans);
}
|
#include <map>
#include <stdio.h>
#include <utility>
using namespace std;
typedef pair<int, int> pi;
#define F first
#define S second
#define MP make_pair
int main() {
int n, ans = 0;
long long int now = 0, temp;
map<long long int, int> m;
scanf("%d", &n);
m.insert(MP(0, -1));
for (int i = 0; i < n; i++) {
scanf("%lld", &temp);
now += temp;
if (m.find(now) == m.end())
m.insert(MP(now, i));
else
ans = max(ans, i - m[now]);
}
printf("%d\n", ans);
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 79], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["-", 0, 11, 12, 2, 3, 4, 0, 16, 17, 72], ["-", 0, 11, 12, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 166
| 4
|
#include <bits/stdc++.h>
using namespace std;
#define MAX_V 1000
int V;
int n;
vector<int> G[MAX_V];
int match[MAX_V];
int Match[MAX_V];
int used[MAX_V];
int L[MAX_V], R[MAX_V];
int C = 0;
void add_edge(int u, int v) {
G[u].push_back(v);
G[v].push_back(u);
}
bool dfs(int v) {
used[v] = C;
for (int i = 0; i < (int)G[v].size(); i++) {
int u = G[v][i], w = match[u];
int a = min(u, v), b = max(u, v) % n;
if (b < L[a] || R[a] < b)
continue;
if (w < 0 || (used[w] != C && dfs(w))) {
match[v] = u;
match[u] = v;
return true;
}
}
return false;
}
int bipartite_matching() {
C++;
int res = 0;
memset(match, -1, sizeof(match));
for (int v = 0; v < n; v++) {
if (match[v] < 0) {
if (dfs(v))
res++;
else
return 0;
}
}
return res;
}
int t[500][500];
int main() {
cin >> n;
n--;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
scanf("%d", &t[i][j]);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (t[j][i] == 1)
add_edge(i, n + j);
V = n + n;
for (int i = 0; i < n; i++) {
L[i] = 0;
R[i] = n - 1;
}
int F = bipartite_matching();
// for(int i=0;i<V;i++)Match[i]=match[i];
if (F == n) {
cout << "YES" << endl;
for (int i = 0; i < n; i++) {
// cout<<i<<endl;
int l = 0, r = match[i] - n, m;
while (l < r) {
m = (l + r) / 2;
R[i] = m;
if (bipartite_matching() == n) {
r = m;
} else {
l = m + 1;
}
}
L[i] = R[i] = l;
bipartite_matching();
}
// cout<<bipartite_matching()<<endl;
for (int i = 0; i < n; i++) {
cout << match[i] + 1 - n << endl;
}
} else {
cout << "NO" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define MAX_V 1000
int V;
int n;
vector<int> G[MAX_V];
int match[MAX_V];
int Match[MAX_V];
int used[MAX_V];
int L[MAX_V], R[MAX_V];
int C = 0;
void add_edge(int u, int v) {
G[u].push_back(v);
G[v].push_back(u);
}
bool dfs(int v) {
used[v] = C;
for (int i = 0; i < (int)G[v].size(); i++) {
int u = G[v][i], w = match[u];
int a = min(u, v), b = max(u, v) % n;
if (b < L[a] || R[a] < b)
continue;
if (w < 0 || (used[w] != C && dfs(w))) {
match[v] = u;
match[u] = v;
return true;
}
}
return false;
}
int bipartite_matching() {
C++;
int res = 0;
memset(match, -1, sizeof(match));
for (int v = 0; v < n; v++) {
C++;
if (match[v] < 0) {
if (dfs(v))
res++;
else
return 0;
}
}
return res;
}
int t[500][500];
int main() {
cin >> n;
n--;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
scanf("%d", &t[i][j]);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (t[j][i] == 1)
add_edge(i, n + j);
V = n + n;
for (int i = 0; i < n; i++) {
L[i] = 0;
R[i] = n - 1;
}
int F = bipartite_matching();
// for(int i=0;i<V;i++)Match[i]=match[i];
if (F == n) {
cout << "yes" << endl;
for (int i = 0; i < n; i++) {
// cout<<i<<endl;
int l = 0, r = match[i] - n, m;
while (l < r) {
m = (l + r) / 2;
R[i] = m;
if (bipartite_matching() == n) {
r = m;
} else {
l = m + 1;
}
}
L[i] = R[i] = l;
bipartite_matching();
}
// cout<<bipartite_matching()<<endl;
for (int i = 0; i < n; i++) {
cout << match[i] + 1 - n << endl;
}
} else {
cout << "no" << endl;
}
return 0;
}
|
[["+", 0, 7, 8, 9, 0, 1, 0, 27, 28, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 27, 17, 29], ["+", 8, 9, 0, 7, 8, 9, 0, 1, 0, 35], ["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 617
| 7
|
#include <bits/stdc++.h>
using namespace std;
#define MAX_V 1000
int N, a, cc = 1;
vector<int> G[MAX_V];
int match[MAX_V];
bool used[MAX_V];
bool dfs(int v) {
used[v] = cc;
for (int i = 0; i < (int)G[v].size(); i++) {
int u = G[v][i], w = match[u];
if (w < 0 || (used[w] != cc && dfs(w))) {
match[u] = v;
match[v] = u;
return true;
}
}
return false;
}
int bipartite_matching() {
int res = 0;
memset(match, -1, sizeof(match));
for (int v = 0; v < N; v++) {
if (match[v] < 0) {
cc++;
if (dfs(v))
res++;
}
}
return res;
}
int main() {
scanf("%d", &N);
N--;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
scanf("%d", &a);
if (a == 1)
G[j].push_back(N + i);
}
}
for (int i = 0; i < N; i++)
sort(G[i].begin(), G[i].end());
int f = bipartite_matching();
printf(f == N ? "yes\n" : "no\n");
for (int i = 0; i < N && f == N; i++) {
match[match[i]] = -1;
match[i] = -1;
cc++;
dfs(i);
G[i].clear();
G[i].push_back(match[i]);
printf("%d\n", match[i] - N + 1);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define MAX_V 1000
int N, a, cc = 1;
vector<int> G[MAX_V];
int match[MAX_V];
int used[MAX_V];
bool dfs(int v) {
used[v] = cc;
for (int i = 0; i < (int)G[v].size(); i++) {
int u = G[v][i], w = match[u];
if (w < 0 || (used[w] != cc && dfs(w))) {
match[u] = v;
match[v] = u;
return true;
}
}
return false;
}
int bipartite_matching() {
int res = 0;
memset(match, -1, sizeof(match));
for (int v = 0; v < N; v++) {
if (match[v] < 0) {
cc++;
if (dfs(v))
res++;
}
}
return res;
}
int main() {
scanf("%d", &N);
N--;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
scanf("%d", &a);
if (a == 1)
G[j].push_back(N + i);
}
}
for (int i = 0; i < N; i++)
sort(G[i].begin(), G[i].end());
int f = bipartite_matching();
printf(f == N ? "yes\n" : "no\n");
for (int i = 0; i < N && f == N; i++) {
match[match[i]] = -1;
match[i] = -1;
cc++;
dfs(i);
G[i].clear();
G[i].push_back(match[i]);
printf("%d\n", match[i] - N + 1);
}
return 0;
}
|
[["-", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40], ["+", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40]]
| 1
| 431
| 2
|
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
System.out.println(num * 4);
}
}
|
import java.util.*;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
System.out.println(num * 32);
}
}
|
[["-", 0, 1, 0, 492, 3, 4, 0, 16, 12, 499], ["+", 0, 1, 0, 492, 3, 4, 0, 16, 12, 499]]
| 3
| 54
| 2
|
#include <bits/stdc++.h>
using namespace std;
const unsigned mod = 1e9 + 7;
unsigned power[234567], lad[26][234567];
struct SegmentTree {
vector<unsigned> hashed;
vector<int> lazy;
int sz;
SegmentTree(int n) {
sz = 1;
while (sz < n)
sz <<= 1;
hashed.assign(2 * sz - 1, 0);
lazy.assign(2 * sz - 1, -1);
}
void push(int k, int l, int r) {
if (~lazy[k]) {
hashed[k] = lad[lazy[k]][r - l];
if (k < sz - 1) {
lazy[2 * k + 1] = lazy[k];
lazy[2 * k + 2] = lazy[k];
}
lazy[k] = -1;
}
}
void add(int a, int b, int x, int k, int l, int r) {
push(k, l, r);
if (a >= r || b <= l)
return;
if (a <= l && r <= b) {
lazy[k] = x;
push(k, l, r);
} else {
add(a, b, x, 2 * k + 1, l, (l + r) >> 1);
add(a, b, x, 2 * k + 2, (l + r) >> 1, r);
hashed[k] = hashed[2 * k + 1] * power[(r - l) >> 1] + hashed[2 * k + 2];
}
}
void add(int a, int b, int x) { add(a, b, x, 0, 0, sz); }
pair<unsigned, int> get(int a, int b, int k, int l, int r) {
push(k, l, r);
if (a >= r || b <= l)
return {0, 0};
if (a <= l & r <= b)
return {hashed[k], r - l};
auto ll = get(a, b, 2 * k + 1, l, (l + r) >> 1);
auto rr = get(a, b, 2 * k + 2, (l + r) >> 1, r);
return {ll.first * power[rr.second] + rr.first, ll.second + rr.second};
}
unsigned get(int a, int b) { return (get(a, b, 0, 0, sz).first); };
void set(int k, int x) { hashed[k + sz - 1] = x; }
void build(int k, int l, int r) {
if (l + 1 == r)
return;
build(2 * k + 1, l, (l + r) >> 1);
build(2 * k + 2, (l + r) >> 1, r);
hashed[k] = hashed[2 * k + 1] * power[(r - l) >> 1] + hashed[2 * k + 2];
}
void build() { build(0, 0, sz); }
char idx(int k) { return (hashed[k + sz - 1]); }
};
int main() {
power[0] = 1;
for (int i = 0; i < 234566; i++)
power[i + 1] = power[i] * mod;
for (int i = 0; i < 26; i++) {
const char cc = 'a' + i;
for (int j = 0; j < 234566; j++)
lad[i][j + 1] = lad[i][j] * mod + cc;
}
int N, Q;
char U[234567];
scanf("%d", &N);
getchar();
scanf("%s", U);
SegmentTree tree(N);
for (int i = 0; i < N; i++)
tree.set(i, U[i] - 'a');
tree.build();
scanf("%d", &Q);
while (Q--) {
getchar();
scanf("%s", U);
if (*U == 's') {
int x, y;
char z;
scanf("%d %d %c", &x, &y, &z);
tree.add(--x, y, z - 'a');
} else {
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
--a, --c;
int ok = 0, ng = min(d - c, b - a) + 1;
while (ng - ok > 1) {
int mid = (ok + ng) >> 1;
if (tree.get(a, a + mid) == tree.get(c, c + mid))
ok = mid;
else
ng = mid;
}
if (ok == d - c && ok == b - a) {
puts("e");
} else if (b - a == ok ||
(d - c != ok && tree.idx(a + ok) < tree.idx(c + ok))) {
puts("s");
} else {
puts("t");
}
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const unsigned mod = 1e9 + 7;
unsigned power[234567], lad[26][234567];
struct SegmentTree {
vector<unsigned> hashed;
vector<int> lazy;
int sz;
SegmentTree(int n) {
sz = 1;
while (sz < n)
sz <<= 1;
hashed.assign(2 * sz - 1, 0);
lazy.assign(2 * sz - 1, -1);
}
void push(int k, int l, int r) {
if (~lazy[k]) {
hashed[k] = lad[lazy[k]][r - l];
if (k < sz - 1) {
lazy[2 * k + 1] = lazy[k];
lazy[2 * k + 2] = lazy[k];
}
lazy[k] = -1;
}
}
void add(int a, int b, int x, int k, int l, int r) {
push(k, l, r);
if (a >= r || b <= l)
return;
if (a <= l && r <= b) {
lazy[k] = x;
push(k, l, r);
} else {
add(a, b, x, 2 * k + 1, l, (l + r) >> 1);
add(a, b, x, 2 * k + 2, (l + r) >> 1, r);
hashed[k] = hashed[2 * k + 1] * power[(r - l) >> 1] + hashed[2 * k + 2];
}
}
void add(int a, int b, int x) { add(a, b, x, 0, 0, sz); }
pair<unsigned, int> get(int a, int b, int k, int l, int r) {
push(k, l, r);
if (a >= r || b <= l)
return {0, 0};
if (a <= l & r <= b)
return {hashed[k], r - l};
auto ll = get(a, b, 2 * k + 1, l, (l + r) >> 1);
auto rr = get(a, b, 2 * k + 2, (l + r) >> 1, r);
return {ll.first * power[rr.second] + rr.first, ll.second + rr.second};
}
unsigned get(int a, int b) { return (get(a, b, 0, 0, sz).first); };
void set(int k, int x) { hashed[k + sz - 1] = lad[x][1]; }
void build(int k, int l, int r) {
if (l + 1 == r)
return;
build(2 * k + 1, l, (l + r) >> 1);
build(2 * k + 2, (l + r) >> 1, r);
hashed[k] = hashed[2 * k + 1] * power[(r - l) >> 1] + hashed[2 * k + 2];
}
void build() { build(0, 0, sz); }
char idx(int k) { return (hashed[k + sz - 1]); }
};
int main() {
power[0] = 1;
for (int i = 0; i < 234566; i++)
power[i + 1] = power[i] * mod;
for (int i = 0; i < 26; i++) {
const char cc = 'a' + i;
for (int j = 0; j < 234566; j++)
lad[i][j + 1] = lad[i][j] * mod + cc;
}
int N, Q;
char U[234567];
scanf("%d", &N);
getchar();
scanf("%s", U);
SegmentTree tree(N);
for (int i = 0; i < N; i++)
tree.set(i, U[i] - 'a');
tree.build();
scanf("%d", &Q);
while (Q--) {
getchar();
scanf("%s", U);
if (*U == 's') {
int x, y;
char z;
scanf("%d %d %c", &x, &y, &z);
tree.add(--x, y, z - 'a');
} else {
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
--a, --c;
int ok = 0, ng = min(d - c, b - a) + 1;
while (ng - ok > 1) {
int mid = (ok + ng) >> 1;
if (tree.get(a, a + mid) == tree.get(c, c + mid))
ok = mid;
else
ng = mid;
}
if (ok == d - c && ok == b - a) {
puts("e");
} else if (b - a == ok ||
(d - c != ok && tree.idx(a + ok) < tree.idx(c + ok))) {
puts("s");
} else {
puts("t");
}
}
}
}
|
[["+", 0, 1, 0, 11, 12, 69, 28, 69, 28, 22], ["+", 0, 11, 12, 69, 28, 69, 341, 342, 0, 70], ["+", 0, 11, 12, 69, 28, 69, 341, 342, 0, 73], ["+", 0, 1, 0, 11, 12, 69, 341, 342, 0, 70], ["+", 0, 1, 0, 11, 12, 69, 341, 342, 0, 13], ["+", 0, 1, 0, 11, 12, 69, 341, 342, 0, 73]]
| 1
| 1,152
| 6
|
#include <algorithm>
#include <array>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define dme \
cout << -1 << endl; \
return 0
// ios::sync_with_stdio(false);
// std::cin.tie(0);
//<< setprecision(20)
const int mod = 1e9 + 7;
const llint big = 1e16 + 100;
const long double pai = 3.141592653589793238462643383279502884197;
const long double ena = 2.71828182845904523536;
const long double eps = 1e-7;
template <class T, class U> void mineq(T &a, U b) {
if (a > b) {
a = b;
}
}
template <class T, class U> void maxeq(T &a, U b) {
if (a < b) {
a = b;
}
}
llint gcd(llint a, llint b) {
if (a % b == 0) {
return b;
} else
return gcd(b, a % b);
}
llint lcm(llint a, llint b) { return a / gcd(a, b) * b; }
lldo gethan(lldo r, lldo hi, lldo mg) { // 0<=hi<mg
if (r < mg) {
mg = r;
}
lldo ans = 0;
ans += mg * sqrt(r * r - mg * mg) / 2;
ans += r * r * (acos(hi / r) - acos(mg / r)) / 2;
ans -= hi * sqrt(r * r - hi * hi) / 2;
return ans;
}
lldo getsol(lldo r, lldo hi, lldo mg, lldo ta) {
lldo hit = sqrt(r * r - hi * hi);
if (ta <= -hit) {
return gethan(r, hi, mg) * 2;
}
if (ta >= hit) {
return 0;
}
lldo mgt = sqrt(r * r - mg * mg);
if (-hit <= ta && ta <= -mgt) {
lldo tar = sqrt(r * r - ta * ta); // ta???x??§?¨?
return gethan(r, hi, mg) * 2 - gethan(r, hi, tar) + ta * (hi - tar);
}
if (mgt <= ta && ta <= hit) {
lldo tar = sqrt(r * r - ta * ta); // ta???x??§?¨?
return gethan(r, hi, tar) - ta * (hi - tar);
}
return gethan(r, hi, mg) - ta;
}
int main(void) {
int i, j, n, r;
cin >> n >> r;
int taka[200] = {0}; //??????????????????0 ??§?\????????????¢??????
for (i = 0; i < n; i++) {
int x, w, h;
cin >> x >> w >> h;
for (int j = x + 100; j < min(200, 100 + x + w); j++) {
// 99,100????¢?????????????
taka[j] = h;
}
}
lldo bmax = 101, bmin = 0;
for (int h = 0; h < 42; h++) {
lldo gen = (bmax + bmin) / 2;
lldo solars = 0;
for (i = 100 - r; i < 100 + r; i++) {
lldo hi = min(abs(100 - i), abs(99 - i));
lldo mg = max(abs(100 - i), abs(99 - i));
solars += getsol(r, hi, mg, taka[i] - gen);
}
if (solars > (r * r * pai / 2)) {
bmax = gen;
} else {
bmin = gen;
}
}
cout << fixed << setprecision(20) << (bmax + bmin) / 2 << endl;
return 0;
}
|
#include <algorithm>
#include <array>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define dme \
cout << -1 << endl; \
return 0
// ios::sync_with_stdio(false);
// std::cin.tie(0);
//<< setprecision(20)
const int mod = 1e9 + 7;
const llint big = 1e16 + 100;
const long double pai = 3.141592653589793238462643383279502884197;
const long double ena = 2.71828182845904523536;
const long double eps = 1e-7;
template <class T, class U> void mineq(T &a, U b) {
if (a > b) {
a = b;
}
}
template <class T, class U> void maxeq(T &a, U b) {
if (a < b) {
a = b;
}
}
llint gcd(llint a, llint b) {
if (a % b == 0) {
return b;
} else
return gcd(b, a % b);
}
llint lcm(llint a, llint b) { return a / gcd(a, b) * b; }
lldo gethan(lldo r, lldo hi, lldo mg) { // 0<=hi<mg
if (r < mg) {
mg = r;
}
lldo ans = 0;
ans += mg * sqrt(r * r - mg * mg) / 2;
ans += r * r * (acos(hi / r) - acos(mg / r)) / 2;
ans -= hi * sqrt(r * r - hi * hi) / 2;
return ans;
}
lldo getsol(lldo r, lldo hi, lldo mg, lldo ta) {
lldo hit = sqrt(r * r - hi * hi);
if (ta <= -hit) {
return gethan(r, hi, mg) * 2;
}
if (ta >= hit) {
return 0;
}
lldo mgt = sqrt(r * r - mg * mg);
if (-hit <= ta && ta <= -mgt) {
// cerr<<"de"<<__LINE__<<endl;
lldo tar = sqrt(r * r - ta * ta); // ta???x??§?¨?
return gethan(r, hi, mg) * 2 - gethan(r, hi, tar) + ta * (hi - tar);
}
if (mgt <= ta && ta <= hit) {
// cerr<<"de"<<__LINE__<<endl;
lldo tar = sqrt(r * r - ta * ta); // ta???x??§?¨?
return gethan(r, hi, tar) + ta * (hi - tar);
}
// cerr<<"de"<<__LINE__<<endl;
return gethan(r, hi, mg) - ta;
}
int main(void) {
int i, j, n, r;
cin >> n >> r;
int taka[200] = {0}; //??????????????????0 ??§?\????????????¢??????
for (i = 0; i < n; i++) {
int x, w, h;
cin >> x >> w >> h;
for (int j = x + 100; j < min(200, 100 + x + w); j++) {
// 99,100????¢?????????????
taka[j] = h;
}
}
lldo bmax = 101, bmin = 0;
for (int h = 0; h < 42; h++) {
lldo gen = (bmax + bmin) / 2;
lldo solars = 0;
for (i = 100 - r; i < 100 + r; i++) {
lldo hi = min(abs(100 - i), abs(99 - i));
lldo mg = max(abs(100 - i), abs(99 - i));
solars += getsol(r, hi, mg, taka[i] - gen);
}
// cerr<<"de gen="<<gen<<"solars="<<solars<<endl;
if (solars > (r * r * pai / 2)) {
bmax = gen;
} else {
bmin = gen;
}
}
cout << fixed << setprecision(20) << (bmax + bmin) / 2 << endl;
return 0;
}
|
[["-", 0, 57, 64, 9, 0, 37, 0, 16, 17, 33], ["+", 0, 57, 64, 9, 0, 37, 0, 16, 17, 72]]
| 1
| 800
| 2
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int ans = sc.nextInt() / sc.nextInt();
System.out.println(ans);
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int ans = sc.nextInt() + sc.nextInt();
System.out.println(ans / 2);
}
}
|
[["-", 8, 196, 0, 503, 49, 200, 51, 16, 17, 85], ["+", 8, 196, 0, 503, 49, 200, 51, 16, 17, 72], ["+", 0, 1, 0, 492, 3, 4, 0, 16, 17, 85], ["+", 0, 1, 0, 492, 3, 4, 0, 16, 12, 499]]
| 3
| 59
| 4
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] input = sc.nextLine().split(" ");
int a = Integer.parseInt(input[0]);
int b = Integer.parseInt(input[1]);
System.out.println(a + b / 2);
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] input = sc.nextLine().split(" ");
int a = Integer.parseInt(input[0]);
int b = Integer.parseInt(input[1]);
System.out.println((a + b) / 2);
}
}
|
[["+", 0, 492, 3, 4, 0, 16, 31, 23, 0, 24], ["+", 0, 492, 3, 4, 0, 16, 31, 23, 0, 25]]
| 3
| 92
| 2
|
#include <stdio.h>
int main(void) {
int a, b;
int ans;
scanf("%d %d", &a, &b);
ans = a + b / 2;
printf("%d\n", ans);
return 0;
}
|
#include <stdio.h>
int main(void) {
int a, b;
int ans;
scanf("%d %d", &a, &b);
ans = (a + b) / 2;
printf("%d\n", ans);
return 0;
}
|
[["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25]]
| 1
| 51
| 2
|
#include <iostream>
using namespace std;
main() {
int a, b;
cin >> a >> b;
cout << (a + b) << endl;
}
|
#include <iostream>
using namespace std;
main() {
int a, b;
cin >> a >> b;
cout << (a + b) / 2 << endl;
}
|
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 85], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
| 1
| 32
| 2
|
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << a + b / 2 << endl;
}
|
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << (a + b) / 2 << endl;
}
|
[["+", 0, 16, 31, 16, 12, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 16, 12, 16, 31, 23, 0, 25]]
| 1
| 33
| 2
|
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << a + b / 2 << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << (a + b) / 2 << endl;
return 0;
}
|
[["+", 0, 16, 31, 16, 12, 16, 31, 23, 0, 24], ["+", 0, 16, 31, 16, 12, 16, 31, 23, 0, 25]]
| 1
| 36
| 2
|
#include <iostream>
using namespace std;
int main() {
int b = 0;
int a = 0;
int c = 0;
cin >> a;
cin >> b;
c = a + b / 2;
cout << c << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int b = 0;
int a = 0;
int c = 0;
cin >> a;
cin >> b;
c = a + b;
c = c / 2;
cout << c << endl;
return 0;
}
|
[["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 31, 22]]
| 1
| 52
| 4
|
#include <stdio.h>
int main(void) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (a >= c) {
printf("0\n");
} else if ((a + b) <= c) {
printf("NA\n");
} else {
printf("%d\n", c - a);
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (a >= c) {
printf("0\n");
} else if ((a + b) < c) {
printf("NA\n");
} else {
printf("%d\n", c - a);
}
return 0;
}
|
[["-", 75, 76, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 17, 18]]
| 1
| 87
| 2
|
#include <iostream>
using namespace std;
int main() {
int m, f, b;
cin >> m >> f >> b;
int x = b - m;
if (x < 0)
cout << '0' << endl;
else if (f > x)
cout << x << endl;
else if (m + f < b)
cout << "NA" << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int m, f, b;
cin >> m >> f >> b;
int x = b - m;
if (x < 0)
cout << '0' << endl;
else if (f >= x)
cout << x << endl;
else if (m + f < b)
cout << "NA" << endl;
return 0;
}
|
[["-", 75, 76, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 17, 20]]
| 1
| 81
| 2
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = b - 1; i >= a; i--)
using namespace std;
//
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
//
struct poi {
int X;
int Y;
int Z;
bool operator<(const poi &R) const {
return X == R.X ? Y == R.Y ? Z < R.Z : Y < R.Y : X < R.X;
}
};
//
ll GCD(ll a, ll b) { return (b == 0) ? (a) : (GCD(b, a % b)); }
ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
//
int main() {
int M, F, B;
cin >> M >> F >> B;
if (M >= B) {
cout << 0 << endl;
} else if (B - M >= F) {
cout << (B - M) << endl;
} else {
cout << "NA" << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = b - 1; i >= a; i--)
using namespace std;
//
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
//
struct poi {
int X;
int Y;
int Z;
bool operator<(const poi &R) const {
return X == R.X ? Y == R.Y ? Z < R.Z : Y < R.Y : X < R.X;
}
};
//
ll GCD(ll a, ll b) { return (b == 0) ? (a) : (GCD(b, a % b)); }
ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
//
int main() {
int M, F, B;
cin >> M >> F >> B;
if (M >= B) {
cout << 0 << endl;
} else if (B - M <= F) {
cout << (B - M) << endl;
} else {
cout << "NA" << endl;
}
return 0;
}
|
[["-", 75, 76, 0, 57, 15, 339, 51, 16, 17, 20], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 17, 19]]
| 1
| 246
| 2
|
#include <iostream>
using namespace std;
int m, f, b;
int main() {
cin >> m >> f >> b;
if (m >= b)
cout << 0 << endl;
else if (m + f <= b)
cout << b - m << endl;
else
cout << "NA" << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int m, f, b;
int main() {
cin >> m >> f >> b;
if (m >= b)
cout << 0 << endl;
else if (m + f >= b)
cout << b - m << endl;
else
cout << "NA" << endl;
return 0;
}
|
[["-", 75, 76, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 17, 20]]
| 1
| 68
| 2
|
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main(void) {
int m, f, b;
cin >> m >> f >> b;
if (m + f < b)
cout << "NA" << endl;
else {
if (m >= b)
cout << 0 << endl;
else
cout << f - m << endl;
}
}
|
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main(void) {
int m, f, b;
cin >> m >> f >> b;
if (m + f < b)
cout << "NA" << endl;
else {
if (m >= b)
cout << 0 << endl;
else
cout << b - m << endl;
}
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 31, 22]]
| 1
| 72
| 2
|
#include <iostream>
using namespace std;
int main() {
int m, f, b;
cin >> m >> f >> b;
if (b < m + f)
if (b <= m)
cout << 0 << endl;
else
cout << b - m << endl;
else
cout << "NA" << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int m, f, b;
cin >> m >> f >> b;
if (b <= m + f)
if (b <= m)
cout << 0 << endl;
else
cout << b - m << endl;
else
cout << "NA" << endl;
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19]]
| 1
| 68
| 2
|
#include <iostream>
using namespace std;
int m, f, b, k, n;
int main() {
cin >> m >> f >> b;
k = m - b;
n = (m + f) - b;
if (k > 0) {
cout << 0 << endl;
} else if (n > 0) {
cout << b - m << endl;
} else {
cout << "NA" << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int m, f, b, k, n;
int main() {
cin >> m >> f >> b;
k = m - b;
n = (m + f) - b;
if (k > 0) {
cout << 0 << endl;
} else if (n >= 0) {
cout << b - m << endl;
} else {
cout << "NA" << endl;
}
return 0;
}
|
[["-", 75, 76, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 17, 20]]
| 1
| 92
| 2
|
#include <iostream>
using namespace std;
int main() {
int m, f, b;
cin >> m >> f >> b;
if (m > b)
cout << 0 << endl;
else if ((m + f) > b)
cout << b - m << endl;
else
cout << "NA" << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int m, f, b;
cin >> m >> f >> b;
if (m >= b)
cout << 0 << endl;
else if ((m + f) >= b)
cout << b - m << endl;
else
cout << "NA" << endl;
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["-", 75, 76, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 17, 20]]
| 1
| 70
| 4
|
#include <iostream>
using namespace std;
int main() {
int m, f, b;
cin >> m >> f >> b;
// 本を購入できないとき
if (b > m + f)
cout << "NA" << endl;
// 本を購入できるとき
else if (b <= m)
cout << 0 << endl; // 自分で購入するとき
else
cout << f - m << endl; // 友達から借りたとき
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int m, f, b;
cin >> m >> f >> b;
// 本を購入できないとき
if (b > m + f)
cout << "NA" << endl;
// 本を購入できるとき
else if (b <= m)
cout << 0 << endl; // 自分で購入するとき
else
cout << b - m << endl; // 友達から借りたとき
return 0;
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 31, 22]]
| 1
| 72
| 11
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (b > a + c)
cout << "NA" << endl;
else
cout << max(b - a, 0) << endl;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (c > a + b)
cout << "NA" << endl;
else
cout << max(c - a, 0) << endl;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22], ["-", 31, 16, 12, 2, 3, 4, 0, 16, 31, 22], ["+", 31, 16, 12, 2, 3, 4, 0, 16, 31, 22]]
| 1
| 59
| 6
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int m, f, b;
cin >> m >> f >> b;
if (m >= b)
cout << "0\n";
else if (m + f >= b)
cout << m + f - b << endl;
else
cout << "NA\n";
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int m, f, b;
cin >> m >> f >> b;
if (m >= b)
cout << "0\n";
else if (m + f >= b)
cout << b - m << endl;
else
cout << "NA\n";
}
|
[["-", 0, 16, 31, 16, 12, 16, 31, 16, 31, 22], ["-", 0, 16, 31, 16, 12, 16, 31, 16, 17, 72], ["-", 0, 16, 31, 16, 12, 16, 31, 16, 12, 22], ["-", 64, 1, 0, 16, 31, 16, 12, 16, 17, 33], ["+", 64, 1, 0, 16, 31, 16, 12, 16, 17, 33], ["+", 64, 1, 0, 16, 31, 16, 12, 16, 12, 22]]
| 1
| 69
| 6
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a >= c) {
cout << 0;
} else if (a + b >= c) {
cout << a + b - c;
} else {
cout << "NA";
}
cout << endl;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a >= c) {
cout << 0;
} else if (a + b >= c) {
cout << c - a;
} else {
cout << "NA";
}
cout << endl;
}
|
[["-", 0, 1, 0, 16, 12, 16, 31, 16, 31, 22], ["-", 0, 1, 0, 16, 12, 16, 31, 16, 17, 72], ["-", 0, 1, 0, 16, 12, 16, 31, 16, 12, 22], ["-", 64, 9, 0, 1, 0, 16, 12, 16, 17, 33], ["+", 64, 9, 0, 1, 0, 16, 12, 16, 17, 33], ["+", 64, 9, 0, 1, 0, 16, 12, 16, 12, 22]]
| 1
| 73
| 6
|
#include <cstdio>
using namespace std;
int main() {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (b >= c)
printf("0\n");
else if (a + b >= c)
printf("%d\n", c - b);
else
printf("NA");
return 0;
}
|
#include <cstdio>
using namespace std;
int main() {
int a, b, c;
scanf("%d %d %d", &b, &a, &c);
if (b >= c)
printf("0\n");
else if (a + b >= c)
printf("%d\n", c - b);
else
printf("NA\n");
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 66, 28, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 66, 28, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
| 1
| 81
| 5
|
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a >= c)
cout << 0 << endl;
else if (a + b < c)
cout << "NA" << endl;
else
cout << a - c << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a >= c)
cout << 0 << endl;
else if (a + b < c)
cout << "NA" << endl;
else
cout << c - a << endl;
return 0;
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 16, 31, 22], ["-", 0, 1, 0, 16, 31, 16, 12, 16, 17, 33], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 33], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 22]]
| 1
| 68
| 4
|
#include <iostream>
#include <stdio.h>
using namespace std;
#include <math.h>
int main() {
int m, f, b;
cin >> m >> f >> b;
if (m >= f)
cout << "0" << endl;
else {
if (m + f >= b)
cout << b - m << endl;
else
cout << "NA" << endl;
}
return 0;
}
|
#include <iostream>
#include <stdio.h>
using namespace std;
#include <math.h>
int main() {
int m, f, b;
cin >> m >> f >> b;
if (m >= b)
cout << "0" << endl;
else {
if (m + f >= b)
cout << b - m << endl;
else
cout << "NA" << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22]]
| 1
| 76
| 2
|
#include <iostream>
using namespace std;
int main() {
int m, f, b;
cin >> m >> f >> b;
if (b - m > f) {
cout << "NO" << endl;
} else {
cout << max(b - m, 0) << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int m, f, b;
cin >> m >> f >> b;
if (b - m > f) {
cout << "NA" << endl;
} else {
cout << max(b - m, 0) << endl;
}
return 0;
}
|
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
| 1
| 64
| 2
|
#include <iostream>
using namespace std;
int main() {
int m, f, b;
cin >> m >> f >> b;
if (m + f > b) {
if (m > b) {
cout << "0" << endl;
} else
cout << (b - m) << endl;
}
if (m + f < b) {
cout << "NA" << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int m, f, b;
cin >> m >> f >> b;
if (m + f >= b) {
if (m > b) {
cout << "0" << endl;
} else
cout << (b - m) << endl;
}
if (m + f < b) {
cout << "NA" << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
| 1
| 85
| 2
|
#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P, int> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
int A, B, C;
int main() {
cin >> A >> B >> C;
if (A + B > C)
cout << "NA" << endl;
else
cout << max(0, C - A) << endl;
}
|
#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P, int> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const ll mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
int A, B, C;
int main() {
cin >> A >> B >> C;
if (A + B < C)
cout << "NA" << endl;
else
cout << max(0, C - A) << endl;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
| 1
| 258
| 2
|
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a >= c)
cout << 0 << endl;
else {
if (b + a >= c)
cout << b - a << endl;
else
cout << "NA" << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a >= c)
cout << 0 << endl;
else {
if (b + a >= c)
cout << c - a << endl;
else
cout << "NA" << endl;
}
return 0;
}
|
[["-", 64, 1, 0, 16, 31, 16, 12, 16, 31, 22], ["+", 64, 1, 0, 16, 31, 16, 12, 16, 31, 22]]
| 1
| 78
| 2
|
#include <iostream>
using namespace std;
int main() {
int a, f, b;
cin >> a >> f >> b;
if (a + b < f) {
cout << "NA" << endl;
} else if (a = b | a > b) {
cout << "0" << endl;
} else {
cout << b - a << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a, f, b;
cin >> a >> f >> b;
if (a + f < b) {
cout << "NA" << endl;
} else if (a == b | a > b) {
cout << "0" << endl;
} else {
cout << b - a << endl;
}
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22], ["-", 75, 76, 0, 57, 15, 339, 51, 11, 17, 32], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 60]]
| 1
| 80
| 6
|
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a >= b) {
cout << 0 << endl;
} else {
if (a + b >= c) {
cout << c - a << endl;
} else {
cout << "NA" << endl;
}
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a >= c) {
cout << 0 << endl;
} else {
if (a + b >= c) {
cout << c - a << endl;
} else {
cout << "NA" << endl;
}
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22]]
| 1
| 76
| 2
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int a, b, c;
cin >> a >> b >> c;
if (a >= c)
cout << 0 << endl;
else if (a + b >= c)
cout << b - c + a << endl;
else
cout << "NA" << endl;
}
|
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
#define FOR(I, A, B) for (int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int a, b, c;
cin >> a >> b >> c;
if (a >= c)
cout << 0 << endl;
else if (a + b >= c)
cout << c - a << endl;
else
cout << "NA" << endl;
}
|
[["-", 0, 16, 31, 16, 12, 16, 31, 16, 31, 22], ["-", 0, 16, 31, 16, 12, 16, 31, 16, 17, 33], ["-", 64, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 64, 1, 0, 16, 31, 16, 12, 16, 17, 33]]
| 1
| 138
| 4
|
#include <iostream>
using namespace std;
int main() {
int m, f, b;
cin >> m >> f >> b;
if (m >= f)
cout << "0" << endl;
else {
if (m + f < b)
cout << "NA" << endl;
else
cout << abs(m - f) << endl;
}
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int m, f, b;
cin >> m >> f >> b;
if (m >= b)
cout << "0" << endl;
else {
if (m + f < b)
cout << "NA" << endl;
else
cout << abs(m - b) << endl;
}
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22], ["-", 31, 16, 12, 2, 3, 4, 0, 16, 12, 22], ["+", 31, 16, 12, 2, 3, 4, 0, 16, 12, 22]]
| 1
| 75
| 4
|
a, b, c = gets.split.map(&:to_i)
puts a >= c ? 0 : a + b >= c ? a + b - c : 'NA'
|
a, b, c = gets.split.map(&:to_i)
puts a >= c ? 0 : a + b >= c ? c - a : 'NA'
|
[["-", 0, 754, 75, 754, 64, 738, 31, 738, 31, 22], ["-", 0, 754, 75, 754, 64, 738, 31, 738, 17, 72], ["-", 0, 754, 75, 754, 64, 738, 31, 738, 12, 22], ["-", 3, 4, 0, 754, 75, 754, 64, 738, 17, 33], ["+", 3, 4, 0, 754, 75, 754, 64, 738, 17, 33], ["+", 3, 4, 0, 754, 75, 754, 64, 738, 12, 22]]
| 4
| 37
| 6
|
a=int(input())
print((a-30)/2)
|
a=int(input())
print((a-30)//2)
|
[["-", 0, 1, 0, 652, 3, 4, 0, 657, 17, 85], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 676]]
| 5
| 18
| 2
|
print((int(input())-30)/2)
|
print(int((int(input())-30)/2))
|
[["+", 0, 1, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 657, 31, 23, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
| 5
| 15
| 3
|
import java.util.Scanner;
public class Main {
public static void main(String... args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println(b - a);
}
}
|
import java.util.Scanner;
public class Main {
public static void main(String... args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println(Math.abs(b - a));
}
}
|
[["+", 0, 1, 0, 492, 3, 4, 0, 492, 500, 22], ["+", 0, 1, 0, 492, 3, 4, 0, 492, 0, 131], ["+", 0, 1, 0, 492, 3, 4, 0, 492, 141, 22], ["+", 0, 492, 3, 4, 0, 492, 3, 4, 0, 24], ["+", 0, 492, 3, 4, 0, 492, 3, 4, 0, 25]]
| 3
| 63
| 5
|
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b;
c = a - b;
if (c < 0)
cout << c * -1 << endl;
cout << c << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b;
c = a - b;
if (c < 0)
cout << c * -1 << endl;
else
cout << c << endl;
return 0;
}
|
[["+", 0, 14, 8, 9, 0, 57, 75, 76, 0, 95]]
| 1
| 54
| 1
|
a,b=map(int,split())
print(abs(a-b))
|
a,b=map(int,input().split())
print(abs(a-b))
|
[["+", 3, 4, 0, 652, 63, 319, 500, 652, 63, 22], ["+", 0, 652, 63, 319, 500, 652, 3, 4, 0, 24], ["+", 0, 652, 63, 319, 500, 652, 3, 4, 0, 25], ["+", 12, 652, 3, 4, 0, 652, 63, 319, 0, 131]]
| 5
| 21
| 4
|
#include <iostream>
using namespace std;
int main() {
int n, c;
cin >> n >> c;
int sum = 0, p;
for (int i = 0; i < c; i++) {
cin >> p;
sum += p;
}
cout << (sum + n - 1) / n << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int n, c;
cin >> n >> c;
int sum = 0, p;
for (int i = 0; i < c; i++) {
cin >> p;
sum += p;
}
cout << (sum + n) / (n + 1) << endl;
return 0;
}
|
[["-", 31, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["-", 31, 16, 12, 16, 31, 23, 0, 16, 12, 13], ["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 24], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 17, 72], ["+", 31, 16, 12, 16, 12, 23, 0, 16, 12, 13], ["+", 0, 16, 31, 16, 12, 16, 12, 23, 0, 25]]
| 1
| 71
| 6
|
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
int N, C;
int sum = 0;
int cake;
cin >> N >> C;
for (int i = 0; i < C; i++) {
int a;
cin >> a;
sum += a;
}
cake = sum / (N + 1);
if (sum % N != 0) {
cake += 1;
}
cout << cake << "\n";
}
|
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
int N, C;
int sum = 0;
int cake;
cin >> N >> C;
for (int i = 0; i < C; i++) {
int a;
cin >> a;
sum += a;
}
cake = sum / (N + 1);
if (sum % (N + 1) != 0) {
cake += 1;
}
cout << cake << "\n";
}
|
[["+", 15, 339, 51, 16, 31, 16, 12, 23, 0, 24], ["+", 51, 16, 31, 16, 12, 23, 0, 16, 17, 72], ["+", 51, 16, 31, 16, 12, 23, 0, 16, 12, 13], ["+", 15, 339, 51, 16, 31, 16, 12, 23, 0, 25]]
| 1
| 96
| 4
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = b - 1; i >= a; i--)
using namespace std;
//
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
//
struct poi {
int X;
int Y;
int Z;
bool operator<(const poi &R) const {
return X == R.X ? Y == R.Y ? Z < R.Z : Y < R.Y : X < R.X;
}
};
//
ll GCD(ll a, ll b) { return (b == 0) ? (a) : (GCD(b, a % b)); }
ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
//
int main() {
int A, B;
int N;
cin >> A >> B >> N;
FOR(i, 0, N) {
int S, F;
cin >> S >> F;
if (F < A || B < S) {
continue;
} else {
cout << 1 << endl;
return 0;
}
}
cout << 0 << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ROF(i, a, b) for (int i = b - 1; i >= a; i--)
using namespace std;
//
const int inf = 1e9 + 7;
const int mod = 1e9 + 7;
//
struct poi {
int X;
int Y;
int Z;
bool operator<(const poi &R) const {
return X == R.X ? Y == R.Y ? Z < R.Z : Y < R.Y : X < R.X;
}
};
//
ll GCD(ll a, ll b) { return (b == 0) ? (a) : (GCD(b, a % b)); }
ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
//
int main() {
int A, B;
int N;
cin >> A >> B >> N;
FOR(i, 0, N) {
int S, F;
cin >> S >> F;
if (F <= A || B <= S) {
continue;
} else {
cout << 1 << endl;
return 0;
}
}
cout << 0 << endl;
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 18], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 19], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 18], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 19]]
| 1
| 255
| 4
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, n;
cin >> a >> b >> n;
while (n--) {
int q, w;
cin >> q >> w;
if (!(q > b || w < a)) {
cout << 1 << endl;
return 0;
}
}
cout << 0 << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, n;
cin >> a >> b >> n;
while (n--) {
int q, w;
cin >> q >> w;
if (!(q >= b || w <= a)) {
cout << 1 << endl;
return 0;
}
}
cout << 0 << endl;
}
|
[["-", 51, 91, 28, 23, 0, 16, 31, 16, 17, 47], ["+", 51, 91, 28, 23, 0, 16, 31, 16, 17, 20], ["-", 51, 91, 28, 23, 0, 16, 12, 16, 17, 18], ["+", 51, 91, 28, 23, 0, 16, 12, 16, 17, 19]]
| 1
| 75
| 4
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, n;
cin >> a >> b >> n;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
if (x <= b && a <= y) {
cout << 1 << endl;
return 0;
}
}
cout << 0 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, n;
cin >> a >> b >> n;
for (int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
if (x < b && a < y) {
cout << 1 << endl;
return 0;
}
}
cout << 0 << endl;
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 19], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 18], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 19], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 18]]
| 1
| 84
| 4
|
#include <iostream>
using namespace std;
int main() {
int a, b, N, s, f;
int flag = 0;
cin >> a >> b >> N;
for (int i = 0; i < N; i++) {
cin >> s >> f;
if (!flag && a < f && a + b > s)
flag = 1;
}
cout << flag;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a, b, N, s, f;
int flag = 0;
cin >> a >> b >> N;
for (int i = 0; i < N; i++) {
cin >> s >> f;
if (!flag && a < f && b > s)
flag = 1;
}
cout << flag << endl;
return 0;
}
|
[["-", 15, 339, 51, 16, 12, 16, 31, 16, 31, 22], ["-", 15, 339, 51, 16, 12, 16, 31, 16, 17, 72], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22]]
| 1
| 84
| 4
|
#include <iostream>
using namespace std;
int main() {
int a, b, n, k[102], l[102], x = 0;
cin >> a >> b >> n;
for (int i = 0; i <= n; i++) {
cin >> k[i] >> l[i];
if (b <= k[i] || l[i] <= a) {
x = 0;
} else {
x = 1;
break;
}
}
cout << x << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a, b, n, k[102], l[102], x = 0;
cin >> a >> b >> n;
for (int i = 1; i <= n; i++) {
cin >> k[i] >> l[i];
if (b <= k[i] || l[i] <= a) {
x = 0;
} else {
x = 1;
break;
}
}
cout << x << endl;
return 0;
}
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
| 1
| 109
| 2
|
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
const int32_t inf = 1001001001;
const int64_t infll = 1001001001001001001ll;
const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1},
dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
template <typename T> using vector2d = vector<vector<T>>;
// clang-format off
template <typename T> void sort(vector<T> &v) { sort(all(v)); }
ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }
struct IoSetup { IoSetup(){ std::cin.tie(0); std::ios::sync_with_stdio(0); std::cout << std::setprecision(10); std::cerr << std::setprecision(10); } } iosetup;
inline int64_t in(){int64_t x=0,m=0,k;for(;;){k=getchar_unlocked();if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){x=k-'0';break;}}for(;;){k=getchar_unlocked();if(k<'0'||'9'<k)break;x=x*10+k-'0';}if(m)x=-x;return x;}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on
signed main(int argc, char *argv[]) {
int h, w;
char c;
cin >> h >> w >> c;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
bool ud = i == 0 || i + 1 == h;
bool lr = j == 0 || j + 1 == w;
if (ud && lr) {
cout << "+";
} else if (ud) {
cout << "-";
} else if (lr) {
cout << "|";
} else if (i == h / 2 && j == w / 2) {
cout << c;
} else {
cout << ".";
}
}
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
const int32_t inf = 1001001001;
const int64_t infll = 1001001001001001001ll;
const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1},
dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
template <typename T> using vector2d = vector<vector<T>>;
// clang-format off
template <typename T> void sort(vector<T> &v) { sort(all(v)); }
ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }
struct IoSetup { IoSetup(){ std::cin.tie(0); std::ios::sync_with_stdio(0); std::cout << std::setprecision(10); std::cerr << std::setprecision(10); } } iosetup;
inline int64_t in(){int64_t x=0,m=0,k;for(;;){k=getchar_unlocked();if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){x=k-'0';break;}}for(;;){k=getchar_unlocked();if(k<'0'||'9'<k)break;x=x*10+k-'0';}if(m)x=-x;return x;}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on
signed main(int argc, char *argv[]) {
int h, w;
char c;
cin >> w >> h >> c;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
bool ud = i == 0 || i + 1 == h;
bool lr = j == 0 || j + 1 == w;
if (ud && lr) {
cout << "+";
} else if (ud) {
cout << "-";
} else if (lr) {
cout << "|";
} else if (i == h / 2 && j == w / 2) {
cout << c;
} else {
cout << ".";
}
}
cout << endl;
}
}
|
[["-", 0, 1, 0, 16, 31, 16, 31, 16, 12, 22], ["-", 8, 9, 0, 1, 0, 16, 31, 16, 17, 152], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 17, 152], ["+", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22]]
| 1
| 1,125
| 4
|
#include <stdio.h>
int main(void) {
int w, h, i, b;
scanf("%d,%d", &w, &h);
char c = getchar();
for (i = 1; i <= h; i++) {
if (i == 1 || i == h) {
printf("+");
for (int a = 0; a < (w - 2) / 2; a++) {
printf("--");
}
printf("-+\n");
} else {
if (i == h / 2 + 1) {
printf("|");
for (b = 2; b < w; b++) {
if (b == w / 2 + 1) {
printf("%c", c);
} else {
printf(".");
}
}
printf("|\n");
} else {
printf("|");
for (int d = 0; d < (w - 2) / 2; d++) {
printf("..");
}
printf(".|\n");
}
}
}
return 0;
}
|
#include <stdio.h>
int main(void) {
int w, h, i, b;
scanf("%d %d ", &w, &h);
char c = getchar();
for (i = 1; i <= h; i++) {
if (i == 1 || i == h) {
printf("+");
for (int a = 0; a < (w - 2) / 2; a++) {
printf("--");
}
printf("-+\n");
} else {
if (i == h / 2 + 1) {
printf("|");
for (b = 2; b < w; b++) {
if (b == w / 2 + 1) {
printf("%c", c);
} else {
printf(".");
}
}
printf("|\n");
} else {
printf("|");
for (int d = 0; d < (w - 2) / 2; d++) {
printf("..");
}
printf(".|\n");
}
}
}
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
| 1
| 235
| 2
|
w, h, a = input().split()
w, h= int(w), int(h)
for i in range(h):
if i in {0, h -1}:print("+" + "-" * (w - 2) + "+")
else:print("|" + "-" * ((w - 2) // 2) + a + "-" * ((w - 2) // 2) + "|" if i == h // 2 else "|" + "-" * (w - 2) + "|")
|
w, h, a = input().split()
w, h= int(w), int(h)
for i in range(h):
if i in {0, h -1}:print("+" + "-" * (w - 2) + "+")
else:print("|" + "." * ((w - 2) // 2) + a + "." * ((w - 2) // 2) + "|" if i == h // 2 else "|" + "." * (w - 2) + "|")
|
[["-", 31, 657, 31, 657, 12, 657, 31, 557, 0, 6], ["+", 31, 657, 31, 657, 12, 657, 31, 557, 0, 6], ["-", 0, 657, 31, 657, 12, 657, 31, 557, 0, 6], ["+", 0, 657, 31, 657, 12, 657, 31, 557, 0, 6]]
| 5
| 131
| 6
|
// AOJ Vol3-0383 Heat Strokes
// 2018.12.22
//#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main() {
int A, B, X;
int c, ans;
scanf("%d%d%d", &A, &B, &X);
if (A >= 2 * B)
ans = ((X - 1) / 500 + 1) * B;
else {
ans = X / 1000 * A;
c = A % 1000;
if (c) {
if (c <= 500 && B < A)
ans += B;
else
ans += A;
}
}
printf("%d\n", ans);
return 0;
}
|
// AOJ Vol3-0383 Heat Strokes
// 2018.12.22
//#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main() {
int A, B, X;
int c, ans;
scanf("%d%d%d", &A, &B, &X);
if (A >= 2 * B)
ans = ((X - 1) / 500 + 1) * B;
else {
ans = X / 1000 * A;
c = X % 1000;
if (c) {
if (c <= 500 && B < A)
ans += B;
else
ans += A;
}
}
printf("%d\n", ans);
return 0;
}
|
[["-", 0, 9, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 0, 9, 0, 1, 0, 11, 12, 16, 31, 22]]
| 0
| 118
| 2
|
#include <iostream>
using namespace std;
int main() {
int a, b, x;
cin >> a >> b >> x;
int ans = 0;
if (a <= b) {
ans = (x + 999) / 1000 * a;
} else if (2 * b < a) {
ans = (x + 499) / 500 * b;
} else {
ans = x / 1000 * a;
x %= 1000;
ans += (x + 499) / 500 * b;
}
cout << ans << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
int a, b, x;
cin >> a >> b >> x;
int ans = 0;
if (a <= b) {
ans = (x + 999) / 1000 * a;
} else if (2 * b < a) {
ans = (x + 499) / 500 * b;
} else {
ans = x / 1000 * a;
x %= 1000;
ans += min(a, (x + 499) / 500 * b);
}
cout << ans << endl;
return 0;
}
|
[["+", 0, 9, 0, 1, 0, 11, 12, 2, 63, 22], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 22], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 21], ["+", 3, 4, 0, 16, 31, 16, 31, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 25]]
| 1
| 111
| 5
|
#include <bits/stdc++.h>
using namespace std;
int H, W;
int t[1000][1000];
int total = 0;
int main() {
scanf("%d %d", &H, &W);
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
scanf("%d", &t[i][j]);
total += t[i][j];
}
}
for (int i = 0; i < H; i++) {
int sum = 0;
for (int j = 0; j < W; j++) {
sum += t[i][j];
}
if (abs(sum - (W - sum)) > 1) {
printf("no\n");
return 0;
}
}
for (int j = 0; j < W; j++) {
int sum = 0;
for (int i = 0; i < H; i++) {
sum += t[i][j];
}
if (abs(sum - (H - sum)) > 1) {
printf("no\n");
return 0;
}
}
for (int i = 0; i + 1 < H; i++) {
for (int j = 0; j + 1 < W; j++) {
int f = t[i][j] + t[i + 1][j] + t[i][j + 1] + t[i + 1][j + 1];
if (f % 2 == 1) {
printf("no\n");
return 0;
}
}
}
if (abs(total - (H * W - total)) > 1) {
printf("no\n");
return 0;
}
printf("yes\n");
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int H, W;
int t[1000][1000];
int total = 0;
int main() {
scanf("%d %d", &W, &H);
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
scanf("%d", &t[i][j]);
total += t[i][j];
}
}
for (int i = 0; i < H; i++) {
int sum = 0;
for (int j = 0; j < W; j++) {
sum += t[i][j];
}
if (abs(sum - (W - sum)) > 1) {
printf("no\n");
return 0;
}
}
for (int j = 0; j < W; j++) {
int sum = 0;
for (int i = 0; i < H; i++) {
sum += t[i][j];
}
if (abs(sum - (H - sum)) > 1) {
printf("no\n");
return 0;
}
}
for (int i = 0; i + 1 < H; i++) {
for (int j = 0; j + 1 < W; j++) {
int f = t[i][j] + t[i + 1][j] + t[i][j + 1] + t[i + 1][j + 1];
if (f % 2 == 1) {
printf("no\n");
return 0;
}
}
}
if (abs(total - (H * W - total)) > 1) {
printf("no\n");
return 0;
}
printf("yes\n");
return 0;
}
|
[["-", 0, 1, 0, 2, 3, 4, 0, 66, 28, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 66, 28, 22]]
| 1
| 393
| 4
|
// Heat Strokes 2018/12/28
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int A, B, X;
int max_A, X_B, price;
cin >> A >> B >> X;
if (X > 1000)
max_A = 1;
else {
max_A = X / 1000;
if (X % 1000)
max_A++;
}
price = B * (X / 500 + 1); // 最大値(or + B)
for (int num_a = 0; num_a <= max_A; num_a++) {
int num_b = 0, tmp_price;
X_B = X - num_a * 1000; // 残りの必要な量
if (X_B > 0) {
num_b = X_B / 500;
if (X_B % 500)
num_b++;
}
tmp_price = A * num_a + B * num_b;
// cout << "A: " << A << ", num_a: " << num_a;
// cout << ", B: " << B << ", num_b: " << num_b;
// cout << "price: " << tmp_price << endl;
price = min(price, tmp_price);
}
cout << price << endl;
return 0;
}
|
// Heat Strokes 2018/12/28
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int A, B, X;
int max_A, X_B, price;
cin >> A >> B >> X;
if (X < 1000)
max_A = 1;
else {
max_A = X / 1000;
if (X % 1000)
max_A++;
}
// cout << "max_A: " << max_A << endl;
price = B * (X / 500 + 1); // 最大値(or + B)
for (int num_a = 0; num_a <= max_A; num_a++) {
int num_b = 0, tmp_price;
X_B = X - num_a * 1000; // 残りの必要な量
if (X_B > 0) {
num_b = X_B / 500;
if (X_B % 500)
num_b++;
}
tmp_price = A * num_a + B * num_b;
/* cout << "A: " << A << ", num_a: " << num_a;
cout << ", B: " << B << ", num_b: " << num_b;
cout << ", price: " << tmp_price << endl; */
price = min(price, tmp_price);
}
cout << price << endl;
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
| 1
| 164
| 2
|
#include <iostream>
using namespace std;
int main() {
int A, B, X;
cin >> A >> B >> X;
int P = 0;
if (A >= 2 * B) {
P = (X / 500) * B;
if (X / 500 != 0) {
P += B;
}
} else {
P = (X / 1000) * A;
if (X % 1000 != 0) {
if (X % 1000 <= 500 && A > B) {
P += B;
} else {
P += A;
}
}
}
cout << P << endl;
}
|
#include <iostream>
using namespace std;
int main() {
int A, B, X;
cin >> A >> B >> X;
int P = 0;
if (A >= 2 * B) {
P = (X / 500) * B;
if (X % 500 != 0) {
P += B;
}
} else {
P = (X / 1000) * A;
if (X % 1000 != 0) {
if (X % 1000 <= 500 && A > B) {
P += B;
} else {
P += A;
}
}
}
cout << P << endl;
}
|
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 85], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 109]]
| 1
| 120
| 2
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
int main() {
string S;
cin >> S;
int ret = *max_element(begin(S), end(S)) - *min_element(begin(S), end(S));
for (int i = 2; i < S.size(); i++) {
if (S.size() % i)
continue;
string small, large;
for (int j = 0; j < S.size(); j += i) {
string v;
for (int k = 0; k < i; k++)
v += S[j + k];
if (small.empty())
small = v, large = v;
else
small = min(small, v), large = max(large, v);
}
int latte = (*prev(large.end(), 2) - '0') * 10 + large.back() - '0';
int malta = (*prev(small.end(), 2) - '0') * 10 + small.back() - '0';
large.pop_back(), large.pop_back();
small.pop_back(), small.pop_back();
if (large == small)
ret = min(ret, latte - malta);
}
int small = INF, large = -INF;
for (int i = 0; i < S.size(); i++) {
if (S[i] == '1') {
if (i + 1 >= S.size()) {
small = INF, large = -INF;
} else {
large = max(large, S[i] - '0' + 10);
++i;
}
} else {
small = min(small, S[i] - '0');
}
}
if (small != INF && large != -INF)
ret = min(ret, large - small);
cout << ret << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
int main() {
string S;
cin >> S;
int ret = *max_element(begin(S), end(S)) - *min_element(begin(S), end(S));
for (int i = 2; i < S.size(); i++) {
if (S.size() % i)
continue;
string small, large;
for (int j = 0; j < S.size(); j += i) {
string v;
for (int k = 0; k < i; k++)
v += S[j + k];
if (small.empty())
small = v, large = v;
else
small = min(small, v), large = max(large, v);
}
int latte = (*prev(large.end(), 2) - '0') * 10 + large.back() - '0';
int malta = (*prev(small.end(), 2) - '0') * 10 + small.back() - '0';
large.pop_back(), large.pop_back();
small.pop_back(), small.pop_back();
if (large == small)
ret = min(ret, latte - malta);
}
int small = INF, large = -INF;
for (int i = 0; i < S.size(); i++) {
if (S[i] == '1') {
if (i + 1 >= S.size()) {
small = INF, large = -INF;
} else {
large = max(large, S[i + 1] - '0' + 10);
++i;
}
} else {
small = min(small, S[i] - '0');
}
}
if (small != INF && large != -INF)
ret = min(ret, large - small);
cout << ret << endl;
}
|
[["+", 31, 16, 31, 69, 341, 342, 0, 16, 17, 72], ["+", 31, 16, 31, 69, 341, 342, 0, 16, 12, 13]]
| 1
| 421
| 2
|
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <utility>
#include <vector>
using namespace std;
typedef pair<int, int> pi;
#define F first
#define S second
#define PB push_back
bool check(pi a, pi b) { return a.F * b.S - a.S * b.F >= 0; }
template <class _T> _T line(_T a, _T b) { return {b.F - a.F, b.S - a.S}; }
template <class _T> double dis(_T a, _T b) {
a = line(a, b);
return sqrt(a.F * a.F + a.S * a.S);
}
double min(double a, double b) { return a > b ? b : a; }
pair<double, double> from, to;
double ans(pi x, pi y) {
pair<double, double> a, b, l, r;
a = {x.F, x.S};
b = {y.F, y.S};
while (dis(a, b) > 0.0001) {
l = {(a.F * 2 + b.F) / 3, (a.S * 2 + b.S) / 3};
r = {(a.F + b.F * 2) / 3, (a.S + b.S * 2) / 3};
if (dis(from, l) + dis(l, to) > dis(from, r) + dis(r, to))
a = l;
else
b = r;
}
return min(dis(from, a) + dis(a, to), dis(from, b) + dis(b, to));
}
int main() {
int n, now = 0, cnt = 2;
vector<pair<pi, int>> v, ch;
pi temp;
double l = 0, r = 0;
bool f = false;
scanf("%d%d", &temp.F, &temp.S);
from = temp;
v.PB({temp, -2});
scanf("%d%d", &temp.F, &temp.S);
v.PB({temp, -1});
to = temp;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d%d", &temp.F, &temp.S);
v.PB({temp, i});
}
sort(v.begin(), v.end());
ch.PB(v[0]);
ch.PB(v[1]);
for (int i = 2; i < v.size(); i++) {
while (ch.size() > 1) {
if (!check(line(ch[ch.size() - 2].F, ch.back().F),
line(ch.back().F, v[i].F)))
ch.pop_back();
else
break;
}
ch.PB(v[i]);
}
for (int i = (int)v.size() - 2; i >= 0; i--) {
while (ch.size() > 1) {
if (!check(line(ch[ch.size() - 2].F, ch.back().F),
line(ch.back().F, v[i].F)))
ch.pop_back();
else
break;
}
ch.PB(v[i]);
}
for (int i = 1; i < ch.size(); i++) {
if (f)
l += dis(ch[i].F, ch[i - 1].F);
else
r += dis(ch[i].F, ch[i - 1].F);
if (ch[i].S == -2 || ch[i].S == -1)
f = !f;
}
l = min(l, r);
if (l == dis(from, to)) {
ch.clear();
while (cnt) {
while (v[now].S == -1 || v[now].S == -2)
now++;
ch.PB(v[now]);
cnt--;
now++;
}
while (now < v.size()) {
while (v[now].S == -1 || v[now].S == -2) {
now++;
if (now >= v.size())
break;
}
if (now >= v.size())
break;
while (ch.size() > 1) {
if (!check(line(ch[ch.size() - 2].F, ch.back().F),
line(ch.back().F, v[now].F)))
ch.pop_back();
else
break;
}
ch.PB(v[now]);
now++;
}
now = (int)v.size() - 2;
while (now >= 0) {
while (v[now].S == -1 || v[now].S == -2) {
now--;
if (now < 0)
break;
}
if (now < 0)
break;
while (ch.size() > 1) {
if (!check(line(ch[ch.size() - 2].F, ch.back().F),
line(ch.back().F, v[now].F)))
ch.pop_back();
else
break;
}
ch.PB(v[now]);
now--;
}
l = ans(ch.front().F, ch.back().F);
for (int i = 1; i < ch.size(); i++)
l = min(l, ans(ch[i].F, ch[i - 1].F));
}
printf("%.20lf\n", l);
}
|
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <utility>
#include <vector>
using namespace std;
typedef pair<int, int> pi;
#define F first
#define S second
#define PB push_back
bool check(pi a, pi b) { return a.F * b.S - a.S * b.F >= 0; }
template <class _T> _T line(_T a, _T b) { return {b.F - a.F, b.S - a.S}; }
template <class _T> double dis(_T a, _T b) {
a = line(a, b);
return sqrt(a.F * a.F + a.S * a.S);
}
double min(double a, double b) { return a > b ? b : a; }
pair<double, double> from, to;
double ans(pi x, pi y) {
pair<double, double> a, b, l, r;
a = {x.F, x.S};
b = {y.F, y.S};
while (dis(a, b) > 0.0001) {
l = {(a.F * 2 + b.F) / 3, (a.S * 2 + b.S) / 3};
r = {(a.F + b.F * 2) / 3, (a.S + b.S * 2) / 3};
if (dis(from, l) + dis(l, to) > dis(from, r) + dis(r, to))
a = l;
else
b = r;
}
return min(dis(from, a) + dis(a, to), dis(from, b) + dis(b, to));
}
int main() {
int n, now = 0, cnt = 2;
vector<pair<pi, int>> v, ch;
pi temp;
double l = 0, r = 0;
bool f = false;
scanf("%d%d", &temp.F, &temp.S);
from = temp;
v.PB({temp, -2});
scanf("%d%d", &temp.F, &temp.S);
v.PB({temp, -1});
to = temp;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d%d", &temp.F, &temp.S);
v.PB({temp, i});
}
sort(v.begin(), v.end());
ch.PB(v[0]);
ch.PB(v[1]);
for (int i = 2; i < v.size(); i++) {
while (ch.size() > 1) {
if (!check(line(ch[ch.size() - 2].F, ch.back().F),
line(ch.back().F, v[i].F)))
ch.pop_back();
else
break;
}
ch.PB(v[i]);
}
for (int i = (int)v.size() - 2; i >= 0; i--) {
while (ch.size() > 1) {
if (!check(line(ch[ch.size() - 2].F, ch.back().F),
line(ch.back().F, v[i].F)))
ch.pop_back();
else
break;
}
ch.PB(v[i]);
}
for (int i = 1; i < ch.size(); i++) {
if (f)
l += dis(ch[i].F, ch[i - 1].F);
else
r += dis(ch[i].F, ch[i - 1].F);
if (ch[i].S == -2 || ch[i].S == -1)
f = !f;
}
l = min(l, r);
if (l == dis(from, to) || f) {
ch.clear();
while (cnt) {
while (v[now].S == -1 || v[now].S == -2)
now++;
ch.PB(v[now]);
cnt--;
now++;
}
while (now < v.size()) {
while (v[now].S == -1 || v[now].S == -2) {
now++;
if (now >= v.size())
break;
}
if (now >= v.size())
break;
while (ch.size() > 1) {
if (!check(line(ch[ch.size() - 2].F, ch.back().F),
line(ch.back().F, v[now].F)))
ch.pop_back();
else
break;
}
ch.PB(v[now]);
now++;
}
now = (int)v.size() - 2;
while (now >= 0) {
while (v[now].S == -1 || v[now].S == -2) {
now--;
if (now < 0)
break;
}
if (now < 0)
break;
while (ch.size() > 1) {
if (!check(line(ch[ch.size() - 2].F, ch.back().F),
line(ch.back().F, v[now].F)))
ch.pop_back();
else
break;
}
ch.PB(v[now]);
now--;
}
l = ans(ch.front().F, ch.back().F);
for (int i = 1; i < ch.size(); i++)
l = min(l, ans(ch[i].F, ch[i - 1].F));
}
printf("%.20lf\n", l);
}
|
[["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 106], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22]]
| 1
| 1,299
| 2
|
#include <cmath>
#include <iostream>
using namespace std;
int sum(int x) {
int a = 0;
while (x) {
a += x % 10;
x /= 10;
}
return a;
}
int main() {
int a, n, m;
cin >> a >> n >> m;
int ans = 0;
for (int i = 2; pow(i, n) <= m; i++) {
int x = pow(i, n);
if (i == sum(x) + a)
ans++;
}
cout << ans << endl;
return 0;
}
|
#include <cmath>
#include <iostream>
using namespace std;
int sum(int x) {
int a = 0;
while (x) {
a += x % 10;
x /= 10;
}
return a;
}
int main() {
int a, n, m;
cin >> a >> n >> m;
int ans = 0;
for (int i = 1; pow(i, n) <= m; i++) {
int x = pow(i, n);
if (i == sum(x) + a)
ans++;
}
cout << ans << endl;
return 0;
}
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
| 1
| 120
| 2
|
#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
vector<int> data;
UnionFind(int sz) { data.assign(sz, -1); }
bool unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return (false);
if (data[x] > data[y])
swap(x, y);
data[x] += data[y];
data[y] = x;
return (true);
}
int find(int k) {
if (data[k] < 0)
return (k);
return (data[k] = find(data[k]));
}
int size(int k) { return (-data[find(k)]); }
};
struct LowLink {
UnionFind uf;
vector<vector<int>> g;
vector<int> used, ord, low, parent;
LowLink(size_t v) : g(v), used(v, 0), ord(v), low(v), uf(v), parent(v, -1) {}
virtual void add_edge(int x, int y) {
g[x].push_back(y);
g[y].push_back(x);
}
void dfs(int idx, int &k, int par = -1) {
used[idx] = true;
ord[idx] = k++;
low[idx] = ord[idx];
for (auto &to : g[idx]) {
if (!used[to]) {
dfs(to, k, idx);
low[idx] = min(low[idx], low[to]);
parent[to] = idx;
if (ord[idx] >= low[to])
uf.unite(idx, to);
} else if (to != par) {
low[idx] = min(low[idx], ord[to]);
}
}
}
void dfs() {
int k = 0;
for (int i = 0; i < g.size(); i++) {
if (used[i])
continue;
dfs(i, k);
}
}
};
struct BiConnectedComponents : LowLink {
vector<pair<int, int>> edges;
vector<int> comp;
BiConnectedComponents(size_t v) : LowLink(v), comp(v) {}
void add_edge(int x, int y) {
LowLink::add_edge(x, y);
edges.push_back(minmax(x, y));
}
int operator[](int k) { return (comp[k]); }
vector<pair<int, int>> build(vector<vector<int>> &t) {
LowLink::dfs();
int ptr = 0;
vector<int> cc(g.size());
for (int i = 0; i < g.size(); i++) {
if (i == uf.find(i))
cc[i] = ptr++;
}
t.resize(ptr);
for (int i = 0; i < g.size(); i++) {
comp[i] = cc[uf.find(i)];
}
vector<pair<int, int>> vs;
for (auto &e : edges) {
int x = comp[e.first], y = comp[e.second];
if (x == y)
continue;
vs.emplace_back(e.first, e.second);
t[x].push_back(y);
t[y].push_back(x);
}
sort(begin(vs), end(vs));
return (vs);
}
};
vector<vector<int>> g;
int sz[100000];
int dp[2][100000];
void dfs(int idx, int par) {
dp[0][idx] = 0;
dp[1][idx] = sz[idx];
for (auto &to : g[idx]) {
if (to == par)
continue;
dfs(to, idx);
dp[0][idx] += max(dp[0][to], dp[1][to]);
dp[1][idx] += dp[0][to];
}
}
int main() {
int N, M;
scanf("%d %d", &N, &M);
BiConnectedComponents graph(N);
for (int i = 0; i < M; i++) {
int a, b;
scanf("%d %d", &a, &b);
graph.add_edge(a, b);
}
graph.build(g);
for (int i = 0; i < N; i++)
++sz[graph[i]];
int ret = 0;
memset(dp, -1, sizeof(dp));
for (int i = 0; i < g.size(); i++) {
if (~dp[i][0])
continue;
dfs(i, -1);
ret += max(dp[0][i], dp[1][i]);
}
printf("%d\n", ret);
}
|
#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
vector<int> data;
UnionFind(int sz) { data.assign(sz, -1); }
bool unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return (false);
if (data[x] > data[y])
swap(x, y);
data[x] += data[y];
data[y] = x;
return (true);
}
int find(int k) {
if (data[k] < 0)
return (k);
return (data[k] = find(data[k]));
}
int size(int k) { return (-data[find(k)]); }
};
struct LowLink {
UnionFind uf;
vector<vector<int>> g;
vector<int> used, ord, low, parent;
LowLink(size_t v) : g(v), used(v, 0), ord(v), low(v), uf(v), parent(v, -1) {}
virtual void add_edge(int x, int y) {
g[x].push_back(y);
g[y].push_back(x);
}
void dfs(int idx, int &k, int par = -1) {
used[idx] = true;
ord[idx] = k++;
low[idx] = ord[idx];
for (auto &to : g[idx]) {
if (!used[to]) {
dfs(to, k, idx);
low[idx] = min(low[idx], low[to]);
parent[to] = idx;
if (ord[idx] >= low[to])
uf.unite(idx, to);
} else if (to != par) {
low[idx] = min(low[idx], ord[to]);
}
}
}
void dfs() {
int k = 0;
for (int i = 0; i < g.size(); i++) {
if (used[i])
continue;
dfs(i, k);
}
}
};
struct BiConnectedComponents : LowLink {
vector<pair<int, int>> edges;
vector<int> comp;
BiConnectedComponents(size_t v) : LowLink(v), comp(v) {}
void add_edge(int x, int y) {
LowLink::add_edge(x, y);
edges.push_back(minmax(x, y));
}
int operator[](int k) { return (comp[k]); }
vector<pair<int, int>> build(vector<vector<int>> &t) {
LowLink::dfs();
int ptr = 0;
vector<int> cc(g.size());
for (int i = 0; i < g.size(); i++) {
if (i == uf.find(i))
cc[i] = ptr++;
}
t.resize(ptr);
for (int i = 0; i < g.size(); i++) {
comp[i] = cc[uf.find(i)];
}
vector<pair<int, int>> vs;
for (auto &e : edges) {
int x = comp[e.first], y = comp[e.second];
if (x == y)
continue;
vs.emplace_back(e.first, e.second);
t[x].push_back(y);
t[y].push_back(x);
}
sort(begin(vs), end(vs));
return (vs);
}
};
vector<vector<int>> g;
int sz[100000];
int dp[2][100000];
void dfs(int idx, int par) {
dp[0][idx] = 0;
dp[1][idx] = sz[idx];
for (auto &to : g[idx]) {
if (to == par)
continue;
dfs(to, idx);
dp[0][idx] += max(dp[0][to], dp[1][to]);
dp[1][idx] += dp[0][to];
}
}
int main() {
int N, M;
scanf("%d %d", &N, &M);
BiConnectedComponents graph(N);
for (int i = 0; i < M; i++) {
int a, b;
scanf("%d %d", &a, &b);
graph.add_edge(a, b);
}
graph.build(g);
for (int i = 0; i < N; i++)
++sz[graph[i]];
int ret = 0;
memset(dp, -1, sizeof(dp));
for (int i = 0; i < g.size(); i++) {
if (~dp[0][i])
continue;
dfs(i, -1);
ret += max(dp[0][i], dp[1][i]);
}
printf("%d\n", ret);
}
|
[["-", 51, 91, 28, 69, 28, 69, 341, 342, 0, 22], ["+", 51, 91, 28, 69, 28, 69, 341, 342, 0, 13], ["-", 15, 339, 51, 91, 28, 69, 341, 342, 0, 13], ["+", 15, 339, 51, 91, 28, 69, 341, 342, 0, 22]]
| 1
| 1,101
| 4
|
#include <bits/stdc++.h>
using namespace std;
#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define all(x) x.begin(), x.end()
#define fs first
#define sc second
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const double eps = 1e-10;
template <typename A, typename B> inline void chmin(A &a, B b) {
if (a > b)
a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
if (a < b)
a = b;
}
const int DIRECTED = 0;
const int UNDIRECTED = 1;
template <int isUNDIRECTED = 0> class Graph {
protected:
struct Edge {
int u, v, id; // from, to, 何番目の辺か
ll c; // cost
Edge(int u, int v, ll c = 0, int id = 0) : u(u), v(v), c(c), id(id) {}
};
int V, E; // 頂点数、辺数
vector<vector<Edge>> G;
vector<Edge> Es;
public:
Graph() {}
Graph(int V) : V(V) { G.resize(V); }
Graph(const Graph<isUNDIRECTED> &g) : V(g.V), E(g.E), G(g.G), Es(g.Es) {}
void add_edge(int u, int v, ll c = 0, int id = 0) {
G[u].emplace_back(u, v, c, id);
if (isUNDIRECTED)
G[v].emplace_back(v, u, c, id);
Es.emplace_back(u, v, c, id);
E++;
}
const vector<Edge> &operator[](int k) { return G[k]; }
unsigned long long size() { return V; }
};
template <int isUNDIRECTED> class Lowlink : public Graph<isUNDIRECTED> {
vector<int> ord, low;
vector<int> articulation;
vector<pair<int, int>> bridge;
public:
Lowlink() {}
Lowlink(int V) : Graph<isUNDIRECTED>(V) {}
Lowlink(const Graph<isUNDIRECTED> &g) : Graph<isUNDIRECTED>(g) {}
void build() {
ord.resize(this->V, -1);
low.resize(this->V, -1);
int k = 0;
function<void(int, int)> dfs = [&, this](int v, int p) {
ord[v] = k++;
low[v] = ord[v];
bool isArt = 0; // 関節点か
int cnt = 0;
for (auto e : this->G[v]) {
if (e.v == p)
continue;
if (ord[e.v] == -1) {
cnt++;
dfs(e.v, v);
low[v] = min(low[v], low[e.v]);
if (ord[v] < low[e.v])
bridge.emplace_back(e.u, e.v);
if (~p && ord[v] <= low[e.v])
isArt = 1;
} else {
low[v] = min(low[v], ord[e.v]);
}
}
if (p == -1 && cnt > 1)
isArt = 1;
if (isArt)
articulation.push_back(v);
};
for (int i = 0; i < this->V; i++)
if (ord[i] == -1)
dfs(i, -1);
}
const vector<pair<int, int>> &getBridge() { return bridge; }
const vector<int> &getArticulation() { return articulation; }
bool isBridge(int u, int v) const {
if (ord[u] > ord[v])
swap(u, v);
return ord[u] < low[v];
}
};
template <int isUNDIRECTED> class BECC {
private:
Lowlink<isUNDIRECTED> orgG;
Graph<isUNDIRECTED> G;
vector<int> belongs;
vector<vector<int>> comps;
public:
BECC() {}
BECC(const Graph<isUNDIRECTED> &g) : orgG(g) {
orgG.build();
belongs.resize(orgG.size(), -1);
}
void build() {
vector<bool> used(orgG.size(), 0);
int k = 0;
function<void(int, int)> dfs = [&](int v, int p) {
belongs[v] = k;
if (p == -1)
comps.push_back(vector<int>());
comps[k].push_back(v);
for (auto e : orgG[v]) {
if (e.v == p)
continue;
if (orgG.isBridge(e.u, e.v))
continue;
if (belongs[e.v] >= 0)
continue;
dfs(e.v, v);
}
};
for (int i = 0; i < orgG.size(); i++) {
if (belongs[i] >= 0)
continue;
dfs(i, -1);
k++;
}
G = Graph<isUNDIRECTED>(k);
for (auto e : orgG.getBridge()) {
G.add_edge(belongs[e.first], belongs[e.second]);
}
}
int belong(int v) { return belongs[v]; }
int size(int v) { return comps[v].size(); }
const Graph<isUNDIRECTED> &getGraph() { return G; }
};
int N, M;
Graph<UNDIRECTED> orgG;
Graph<UNDIRECTED> tree;
int main(void) {
cin >> N >> M;
orgG = Graph<UNDIRECTED>(N);
REP(i, M) {
int s, t;
cin >> s >> t;
orgG.add_edge(s, t);
}
BECC<UNDIRECTED> becc(orgG);
becc.build();
tree = becc.getGraph();
vector<vector<int>> dp(tree.size(), vector<int>(2, 0));
function<void(int, int)> dfs = [&](int v, int p) {
int sum[2] = {};
for (auto e : tree[v]) {
if (e.v == p)
continue;
dfs(e.v, v);
sum[0] += max(dp[e.v][0], dp[e.v][1]);
sum[1] += dp[e.v][0];
}
dp[v][0] = sum[0];
dp[v][1] = sum[1] + becc.size(v);
};
int res = 0;
REP(i, tree.size()) {
if (dp[i][1] == 0) {
dfs(i, -1);
res += max(dp[0][0], dp[0][1]);
}
}
cout << res << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define all(x) x.begin(), x.end()
#define fs first
#define sc second
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const double eps = 1e-10;
template <typename A, typename B> inline void chmin(A &a, B b) {
if (a > b)
a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
if (a < b)
a = b;
}
const int DIRECTED = 0;
const int UNDIRECTED = 1;
template <int isUNDIRECTED = 0> class Graph {
protected:
struct Edge {
int u, v, id; // from, to, 何番目の辺か
ll c; // cost
Edge(int u, int v, ll c = 0, int id = 0) : u(u), v(v), c(c), id(id) {}
};
int V, E; // 頂点数、辺数
vector<vector<Edge>> G;
vector<Edge> Es;
public:
Graph() {}
Graph(int V) : V(V) { G.resize(V); }
Graph(const Graph<isUNDIRECTED> &g) : V(g.V), E(g.E), G(g.G), Es(g.Es) {}
void add_edge(int u, int v, ll c = 0, int id = 0) {
G[u].emplace_back(u, v, c, id);
if (isUNDIRECTED)
G[v].emplace_back(v, u, c, id);
Es.emplace_back(u, v, c, id);
E++;
}
const vector<Edge> &operator[](int k) { return G[k]; }
unsigned long long size() { return V; }
};
template <int isUNDIRECTED> class Lowlink : public Graph<isUNDIRECTED> {
vector<int> ord, low;
vector<int> articulation;
vector<pair<int, int>> bridge;
public:
Lowlink() {}
Lowlink(int V) : Graph<isUNDIRECTED>(V) {}
Lowlink(const Graph<isUNDIRECTED> &g) : Graph<isUNDIRECTED>(g) {}
void build() {
ord.resize(this->V, -1);
low.resize(this->V, -1);
int k = 0;
function<void(int, int)> dfs = [&, this](int v, int p) {
ord[v] = k++;
low[v] = ord[v];
bool isArt = 0; // 関節点か
int cnt = 0;
for (auto e : this->G[v]) {
if (e.v == p)
continue;
if (ord[e.v] == -1) {
cnt++;
dfs(e.v, v);
low[v] = min(low[v], low[e.v]);
if (ord[v] < low[e.v])
bridge.emplace_back(e.u, e.v);
if (~p && ord[v] <= low[e.v])
isArt = 1;
} else {
low[v] = min(low[v], ord[e.v]);
}
}
if (p == -1 && cnt > 1)
isArt = 1;
if (isArt)
articulation.push_back(v);
};
for (int i = 0; i < this->V; i++)
if (ord[i] == -1)
dfs(i, -1);
}
const vector<pair<int, int>> &getBridge() { return bridge; }
const vector<int> &getArticulation() { return articulation; }
bool isBridge(int u, int v) const {
if (ord[u] > ord[v])
swap(u, v);
return ord[u] < low[v];
}
};
template <int isUNDIRECTED> class BECC {
private:
Lowlink<isUNDIRECTED> orgG;
Graph<isUNDIRECTED> G;
vector<int> belongs;
vector<vector<int>> comps;
public:
BECC() {}
BECC(const Graph<isUNDIRECTED> &g) : orgG(g) {
orgG.build();
belongs.resize(orgG.size(), -1);
}
void build() {
vector<bool> used(orgG.size(), 0);
int k = 0;
function<void(int, int)> dfs = [&](int v, int p) {
belongs[v] = k;
if (p == -1)
comps.push_back(vector<int>());
comps[k].push_back(v);
for (auto e : orgG[v]) {
if (e.v == p)
continue;
if (orgG.isBridge(e.u, e.v))
continue;
if (belongs[e.v] >= 0)
continue;
dfs(e.v, v);
}
};
for (int i = 0; i < orgG.size(); i++) {
if (belongs[i] >= 0)
continue;
dfs(i, -1);
k++;
}
G = Graph<isUNDIRECTED>(k);
for (auto e : orgG.getBridge()) {
G.add_edge(belongs[e.first], belongs[e.second]);
}
}
int belong(int v) { return belongs[v]; }
int size(int v) { return comps[v].size(); }
const Graph<isUNDIRECTED> &getGraph() { return G; }
};
int N, M;
Graph<UNDIRECTED> orgG;
Graph<UNDIRECTED> tree;
int main(void) {
cin >> N >> M;
orgG = Graph<UNDIRECTED>(N);
REP(i, M) {
int s, t;
cin >> s >> t;
orgG.add_edge(s, t);
}
BECC<UNDIRECTED> becc(orgG);
becc.build();
tree = becc.getGraph();
vector<vector<int>> dp(tree.size(), vector<int>(2, 0));
function<void(int, int)> dfs = [&](int v, int p) {
int sum[2] = {};
for (auto e : tree[v]) {
if (e.v == p)
continue;
dfs(e.v, v);
sum[0] += max(dp[e.v][0], dp[e.v][1]);
sum[1] += dp[e.v][0];
}
dp[v][0] = sum[0];
dp[v][1] = sum[1] + becc.size(v);
};
int res = 0;
REP(i, tree.size()) {
if (dp[i][1] == 0) {
dfs(i, -1);
res += max(dp[i][0], dp[i][1]);
}
}
cout << res << endl;
}
|
[["-", 3, 4, 0, 69, 28, 69, 341, 342, 0, 13], ["+", 3, 4, 0, 69, 28, 69, 341, 342, 0, 22]]
| 1
| 1,533
| 4
|
<?php
//??????????????¬???????????????????????°????????\????????¨????????°
$rightCard = 0;
$leftCard = 0;
//?????????????¨??????\???????????°
$rightAns = 0;
$leftAns = 0;
while(true){
//??\?????????????????????
$stdin=trim(fgets(STDIN));
//??????????????°???0??????break
if($sidin == 0){
break;
}
//??????????????°???10000??\????????????????????????
if($sidin <= 10000){
//??\????????°???????????????????????????
for($i = 0;$i<stdin;$i++){
//??\??????????????§??????
$cardin=trim(fgets(STDIN));
$cards = explode(" ", $cardin);
//??????????????°????????\???
$leftCard = $cards[0];
$rightCard = $cards[1];
//??????????¨????
if($leftCard > $rightCard){
$leftAns += $leftCard + $rightCard;
}
else if($leftCard < $rightCard){
$rightAns += $leftCard + $rightCard;
}
else if($leftCard == $rightCard){
$leftAns += $leftCard;
$rightAns += $rightCard;
}
}
//????????????
echo $leftAns." ".$rightAns."\n";
//??????????????????
$rightAns = 0;
$leftAns = 0;
}
}
|
<?php
//??????????????¬???????????????????????°????????\????????¨????????°
$rightCard = 0;
$leftCard = 0;
//?????????????¨??????\???????????°
$rightAns = 0;
$leftAns = 0;
while(true){
//??\?????????????????????
$stdin=trim(fgets(STDIN));
//??????????????°???0??????break
if($stdin == 0){
break;
}
//??????????????°???10000??\????????????????????????
if($stdin <= 10000){
//??\????????°???????????????????????????
for($i = 0;$i<$stdin;$i++){
//??\??????????????§??????
$cardin=trim(fgets(STDIN));
$cards = explode(" ", $cardin);
//??????????????°????????\???
$leftCard = $cards[0];
$rightCard = $cards[1];
//??????????¨????
if($leftCard > $rightCard){
$leftAns += $leftCard + $rightCard;
}
else if($leftCard < $rightCard){
$rightAns += $leftCard + $rightCard;
}
else if($leftCard == $rightCard){
$leftAns += $leftCard;
$rightAns += $rightCard;
}
}
//????????????
echo $leftAns." ".$rightAns."\n";
//??????????????????
$rightAns = 0;
$leftAns = 0;
}
}
|
[["-", 0, 57, 15, 23, 0, 16, 31, 606, 0, 141], ["+", 0, 57, 15, 23, 0, 16, 31, 606, 0, 141], ["+", 8, 9, 0, 7, 0, 16, 12, 606, 0, 607]]
| 6
| 216
| 5
|
while ($n = trim(fgets(STDIN))) {
$score = array('a' => 0, 'b' =>0);
for ($i = 0; $i < $n; $i++) {
list($a_card, $b_card) = explode(' ', trim(fgets(STDIN)));
if($a_card == $b_card) {
$score['a'] += $a_card;
$score['b'] += $b_card;
} elseif($a_card > $b_card) {
$score['a'] += $a_card + $b_card;
} else {
$score['b'] += $a_card + $b_card;
}
}
echo implode(' ', $score).PHP_EOL;
}
|
<?php
while ($n = trim(fgets(STDIN))) {
$score = array('a' => 0, 'b' =>0);
for ($i = 0; $i < $n; $i++) {
list($a_card, $b_card) = explode(' ', trim(fgets(STDIN)));
if($a_card == $b_card) {
$score['a'] += $a_card;
$score['b'] += $b_card;
} elseif($a_card > $b_card) {
$score['a'] += $a_card + $b_card;
} else {
$score['b'] += $a_card + $b_card;
}
}
echo implode(' ', $score).PHP_EOL;
}
|
[["+", 36, 36, 36, 36, 36, 36, 0, 493, 0, 605]]
| 6
| 162
| 19
|
#include <bits/stdc++.h>
using namespace std;
const int N = 202;
int g[N][N];
int G(int w, int b) {
if (g[w][b] >= 0)
return g[w][b];
bool a[N];
if (w > 0)
a[G(w - 1, b)] = true;
for (int i = 1; i <= min(w, b); ++i)
a[G(w, b - i)] = true;
if (b > 0)
a[G(w + 1, b - 1)] = true;
int ret = 0;
while (a[ret])
++ret;
return g[w][b] = ret;
}
int main() {
memset(g, -1, sizeof(g));
int n;
cin >> n;
int a = 0;
while (n--) {
int w, b;
cin >> w >> b;
a ^= G(w, b);
}
cout << !a << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 202;
int g[N][N];
int G(int w, int b) {
if (g[w][b] >= 0)
return g[w][b];
bool a[N] = {};
if (w > 0)
a[G(w - 1, b)] = true;
for (int i = 1; i <= min(w, b); ++i)
a[G(w, b - i)] = true;
if (b > 0)
a[G(w + 1, b - 1)] = true;
int ret = 0;
while (a[ret])
++ret;
return g[w][b] = ret;
}
int main() {
memset(g, -1, sizeof(g));
int n;
cin >> n;
int a = 0;
while (n--) {
int w, b;
cin >> w >> b;
a ^= G(w, b);
}
cout << !a << endl;
return 0;
}
|
[["+", 0, 14, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 8, 9, 0, 43, 49, 50, 51, 83, 0, 45], ["+", 8, 9, 0, 43, 49, 50, 51, 83, 0, 46]]
| 1
| 227
| 3
|
#include <stdio.h>
typedef struct {
int flip;
long long rotate;
} Query;
long long n, k, q;
Query tree[(1 << 20) * 2];
void build(long long _n);
Query merge(Query a, Query b);
void update(Query data, long long i);
Query sum(void);
int main() {
long long _n;
long long a;
scanf("%lld %lld %lld", &k, &_n, &q);
build(_n);
for (long long i = 0; i < _n; i++) {
scanf("%lld", &a);
Query data = {0, 0};
if (a == 0)
data.flip = 1;
else
data.rotate = a;
update(data, i);
}
for (long long i = 0; i < q; i++) {
long long left, right;
Query l, r;
scanf("%lld %lld", &left, &right);
left--;
right--;
l = tree[left + n - 1];
r = tree[right + n - 1];
update(l, right);
update(r, left);
Query total = sum();
long long num;
if (total.rotate < 0)
total.rotate = k + total.rotate;
num = 1 + total.rotate;
if (total.flip) {
if (num == 1)
num *= -1;
else
num = ((k + 2) - num) * -1;
}
printf("%lld\n", num);
// printf("%d %lld\n", total.flip, total.rotate);
}
return 0;
}
void build(long long _n) {
n = 1;
while (n < _n) {
n *= 2;
}
for (long long i = 0; i < 2 * n; i++) {
tree[i] = (Query){0, 0};
}
return;
}
Query merge(Query a, Query b) {
Query x;
x.flip = (a.flip + b.flip) % 2;
if (b.flip) {
x.rotate = (b.rotate + a.rotate) % k;
} else {
x.rotate = (a.rotate - b.rotate) % k;
}
return x;
}
void update(Query data, long long i) {
i += n - 1;
tree[i] = data;
while (i != 0) {
i = (i - 1) / 2;
tree[i] = merge(tree[i * 2 + 1], tree[i * 2 + 2]);
}
return;
}
Query sum(void) { return tree[0]; }
|
#include <stdio.h>
typedef struct {
int flip;
long long rotate;
} Query;
long long n, k, q;
Query tree[(1 << 20) * 2];
void build(long long _n);
Query merge(Query a, Query b);
void update(Query data, long long i);
Query sum(void);
int main() {
long long _n;
long long a;
scanf("%lld %lld %lld", &k, &_n, &q);
build(_n);
for (long long i = 0; i < _n; i++) {
scanf("%lld", &a);
Query data = {0, 0};
if (a == 0)
data.flip = 1;
else
data.rotate = -a;
update(data, i);
}
for (long long i = 0; i < q; i++) {
long long left, right;
Query l, r;
scanf("%lld %lld", &left, &right);
left--;
right--;
l = tree[left + n - 1];
r = tree[right + n - 1];
update(l, right);
update(r, left);
Query total = sum();
long long num;
if (total.rotate < 0)
total.rotate = k + total.rotate;
num = 1 + total.rotate;
if (total.flip) {
if (num == 1)
num *= -1;
else
num = ((k + 2) - num) * -1;
}
printf("%lld\n", num);
// printf("%d %lld\n", total.flip, total.rotate);
}
return 0;
}
void build(long long _n) {
n = 1;
while (n < _n) {
n *= 2;
}
for (long long i = 0; i < 2 * n; i++) {
tree[i] = (Query){0, 0};
}
return;
}
Query merge(Query a, Query b) {
Query x;
x.flip = (a.flip + b.flip) % 2;
if (b.flip) {
x.rotate = (b.rotate - a.rotate) % k;
} else {
x.rotate = (a.rotate + b.rotate) % k;
}
return x;
}
void update(Query data, long long i) {
i += n - 1;
tree[i] = data;
while (i != 0) {
i = (i - 1) / 2;
tree[i] = merge(tree[i * 2 + 1], tree[i * 2 + 2]);
}
return;
}
Query sum(void) { return tree[0]; }
|
[["+", 75, 76, 0, 1, 0, 11, 12, 91, 17, 33], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 17, 72], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 33], ["-", 0, 11, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 72]]
| 0
| 554
| 5
|
A, B = map(int, input().split())
print((B+A-1)/A)
|
A, B = map(int, input().split())
print((B+A-1)//A)
|
[["-", 0, 1, 0, 652, 3, 4, 0, 657, 17, 85], ["+", 0, 1, 0, 652, 3, 4, 0, 657, 17, 676]]
| 5
| 28
| 2
|
H,a,b=map(int,input().split())
c=0
for i in range(a,b):
if H%i==0 :
c+=1
print(c)
|
H,a,b=map(int,input().split())
c=0
for i in range(a,b+1):
if H%i==0 :
c+=1
print(c)
|
[["+", 0, 7, 12, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612]]
| 5
| 45
| 2
|
N,K = map(int, input().split())
t = n = a = 1
while True:
n = (K+a-1)/K
a += n;
if N < a: break
t += 1
print(t)
|
N,K = map(int, input().split())
t = n = a = 1
while True:
n = (K+a-1)//K
a += n;
if N < a: break
t += 1
print(t)
|
[["-", 8, 196, 0, 1, 0, 662, 12, 657, 17, 85], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 17, 676]]
| 5
| 54
| 2
|
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define inf (INT_MAX - 1)
#define INF 9223372036854775807
#define sq(n) ((n) * (n))
#define rep(i, n) for (i = 0; i < n; i++)
#define rev(i, n) for (i = n - 1; i >= 0; i--)
#define sort(a, n) qsort(a, n, sizeof(TYPE), cmp)
#define sort_r(a, n) qsort(a, n, sizeof(TYPE), cmp_r);
#define TYPE int
#define MEMSET(a) memset(a, 0, sizeof(a))
const int mod = (int)1e09 + 7;
int in(void) {
int i;
scanf("%d", &i);
return i;
}
long long llin(void) {
long long i;
scanf("%lld", &i);
return i;
}
double din(void) {
double i;
scanf("%lf", &i);
return i;
}
void chin(char s[]) { scanf("%s", s); }
void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
long long max(long long a, long long b) { return a > b ? a : b; }
long long min(long long a, long long b) { return a < b ? a : b; }
long long llabs(long long a) { return a > 0 ? a : -a; }
double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int main(void) {
int x = in(), y = in(), i, ans;
ans = x + y;
for (i = 1; i < 2 * x; i++) {
if ((y * i) % (2 * x) == 0) {
ans--;
}
}
print(ans);
return 0;
}
|
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define inf (INT_MAX - 1)
#define INF 9223372036854775807
#define sq(n) ((n) * (n))
#define rep(i, n) for (i = 0; i < n; i++)
#define rev(i, n) for (i = n - 1; i >= 0; i--)
#define sort(a, n) qsort(a, n, sizeof(TYPE), cmp)
#define sort_r(a, n) qsort(a, n, sizeof(TYPE), cmp_r);
#define TYPE int
#define MEMSET(a) memset(a, 0, sizeof(a))
const int mod = (int)1e09 + 7;
int in(void) {
int i;
scanf("%d", &i);
return i;
}
long long llin(void) {
long long i;
scanf("%lld", &i);
return i;
}
double din(void) {
double i;
scanf("%lf", &i);
return i;
}
void chin(char s[]) { scanf("%s", s); }
void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
long long max(long long a, long long b) { return a > b ? a : b; }
long long min(long long a, long long b) { return a < b ? a : b; }
long long llabs(long long a) { return a > 0 ? a : -a; }
double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int main(void) {
int x = in(), y = in(), i, ans;
ans = x + y;
for (i = 2; i < 2 * x; i += 2) {
if ((y * i) % (2 * x) == 0) {
ans--;
}
}
print(ans);
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 7, 10, 11, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 10, 11, 12, 13], ["-", 0, 14, 8, 9, 0, 7, 26, 27, 17, 29], ["+", 0, 14, 8, 9, 0, 7, 26, 11, 17, 107], ["+", 0, 14, 8, 9, 0, 7, 26, 11, 12, 13]]
| 0
| 466
| 5
|
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
main() {
int x, y;
cin >> x >> y;
vector<int> v;
v.push_back(3);
for (int i = 0; i < 3000000; i++)
v.push_back(v[i]);
cout << (x + 1) + (y + 1) - (gcd(x, y) - 1) - 21 << endl;
return 0;
}
|
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;
int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
main() {
int x, y;
cin >> x >> y;
vector<int> v;
v.push_back(3);
for (int i = 0; i < 5000000; i++)
v.push_back(v[i]);
cout << (x + 1) + (y + 1) - (gcd(x, y) - 1) - 2 << endl;
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["-", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
| 1
| 122
| 4
|
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
signed main() {
int a, b;
cin >> a >> b;
cout << a + b + 2 - a * b / gcd(a, b) - 1 << endl;
}
|
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
signed main() {
int a, b;
cin >> a >> b;
cout << a + b + 2 - gcd(a, b) - 1 << endl;
}
|
[["-", 12, 16, 31, 16, 12, 16, 31, 16, 31, 22], ["-", 12, 16, 31, 16, 12, 16, 31, 16, 17, 48], ["-", 12, 16, 31, 16, 12, 16, 31, 16, 12, 22], ["-", 31, 16, 12, 16, 31, 16, 12, 16, 17, 85]]
| 1
| 108
| 4
|
#include <iostream>
using namespace std;
int min(int x, int y) { return (x > y) ? y : x; }
int gcd(int x, int y) {
int n = min(x, y);
for (; n >= 1; n--) {
if (x % n == 0 && y % n == 0)
return n;
}
return 1;
}
int main() {
int tate, yoko;
cin >> yoko >> tate;
cout << (tate + 1) + (yoko) + 1 - gcd(tate, yoko * 2) - 1 << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int min(int x, int y) { return (x > y) ? y : x; }
int gcd(int x, int y) {
int n = min(x, y);
for (; n >= 1; n--) {
if (x % n == 0 && y % n == 0)
return n;
}
return 1;
}
int main() {
int tate, yoko;
cin >> yoko >> tate;
cout << (tate + 1) + (yoko) + 1 - gcd(tate, yoko) - 1 << endl;
return 0;
}
|
[["-", 31, 16, 12, 2, 3, 4, 0, 16, 17, 48], ["-", 31, 16, 12, 2, 3, 4, 0, 16, 12, 13]]
| 1
| 128
| 2
|
#include <iostream>
using namespace std;
int gcd(int x, int y) {
if (y == 0)
return x;
return gcd(y, y % x);
}
int main() {
int x, y;
cin >> x >> y;
int g = gcd(x, y);
cout << (x + 1) + (y + 1) - (g + 1) << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int gcd(int x, int y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
int main() {
int x, y;
cin >> x >> y;
int g = gcd(x, y);
cout << (x + 1) + (y + 1) - (g + 1) << endl;
return 0;
}
|
[["-", 0, 37, 0, 2, 3, 4, 0, 16, 31, 22], ["-", 0, 37, 0, 2, 3, 4, 0, 16, 17, 109], ["+", 0, 37, 0, 2, 3, 4, 0, 16, 17, 109], ["+", 0, 37, 0, 2, 3, 4, 0, 16, 12, 22]]
| 1
| 88
| 4
|
#include <stdio.h>
int d[300005];
int check1(int s);
int check2(int s, int N);
int main(void) {
int N, i, f;
scanf("%d", &N);
for (i = 0; i < N; i++) {
scanf("%d", &d[i]);
}
f = check1(N - 1);
if (f == 0) {
printf("no\n");
return 0;
}
f = check2(0, N - 1);
if (f == 0) {
printf("no\n");
return 0;
} else {
printf("yes\n");
}
return 0;
}
int check1(int s) {
int i, f;
// printf("%d\n",d[s]);
if (s == 0) {
return 1;
}
for (i = s - 1; i >= 0; i--) {
if (d[i] >= 10 * (s - i)) {
f = check1(i);
if (f == 0) {
return 0;
} else {
return 1;
}
}
}
return 0;
}
int check2(int s, int N) {
int i, f;
// printf("%d\n",d[s]);
if (s == N - 1) {
return 1;
}
for (i = s + 1; i < N; i++) {
if (d[i] >= 10 * (i - s)) {
f = check2(i, N);
if (f == 0) {
return 0;
} else {
return 1;
}
}
}
return 0;
}
|
#include <stdio.h>
int d[300005];
int check1(int s);
int check2(int s, int N);
int main(void) {
int N, i, f;
scanf("%d", &N);
for (i = 0; i < N; i++) {
scanf("%d", &d[i]);
}
f = check1(N - 1);
if (f == 0) {
printf("no\n");
return 0;
}
f = check2(0, N - 1);
if (f == 0) {
printf("no\n");
return 0;
} else {
printf("yes\n");
}
return 0;
}
int check1(int s) {
int i, f;
// printf("%d\n",d[s]);
if (s == 0) {
return 1;
}
for (i = s - 1; i >= 0; i--) {
if (d[i] >= 10 * (s - i)) {
f = check1(i);
if (f == 0) {
return 0;
} else {
return 1;
}
}
}
return 0;
}
int check2(int s, int N) {
int i, f;
// printf("%d\n",d[s]);
if (s == N) {
return 1;
}
for (i = s + 1; i <= N; i++) {
if (d[i] >= 10 * (i - s)) {
f = check2(i, N);
if (f == 0) {
return 0;
} else {
return 1;
}
}
}
return 0;
}
|
[["-", 0, 57, 15, 23, 0, 16, 12, 16, 17, 33], ["-", 0, 57, 15, 23, 0, 16, 12, 16, 12, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 17, 19]]
| 0
| 328
| 4
|
#include <algorithm>
#include <iostream>
#include <vector>
#define LL long long
int n;
std::vector<int> d;
int main() {
std::cin >> n;
for (int i = 0; i < n; i++) {
int tmp;
std::cin >> tmp;
d.push_back(tmp / 10);
}
bool flag = true;
int st = 0;
for (int i = 0; i < n - 1; i++) {
st = std::max(st, d[i]);
if (st < 0)
flag = false;
st--;
}
if (st < 0)
flag = false;
st = 0;
std::reverse(d.begin(), d.end());
for (int i = 0; i < n - 1; i++) {
st = std::max(st, d[i]);
if (st < 0)
flag = false;
st--;
}
if (st < 0)
flag = false;
std::cout << (flag ? "yes" : "no") << std::endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
#define LL long long
int n;
std::vector<int> d;
int main() {
std::cin >> n;
for (int i = 0; i < n; i++) {
int tmp;
std::cin >> tmp;
d.push_back(tmp / 10);
}
bool flag = true;
int st = 0;
for (int i = 0; i < n - 1; i++) {
st = std::max(st, d[i]);
if (st <= 0)
flag = false;
st--;
}
if (st < 0)
flag = false;
st = 0;
std::reverse(d.begin(), d.end());
for (int i = 0; i < n - 1; i++) {
st = std::max(st, d[i]);
if (st <= 0)
flag = false;
st--;
}
if (st < 0)
flag = false;
std::cout << (flag ? "yes" : "no") << std::endl;
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19]]
| 1
| 230
| 4
|
#include <iostream>
using namespace std;
int main() {
long long a[300002];
int x, y, z;
cin >> x;
for (int i = 0; i < x; i++) {
cin >> a[i];
}
if (a[0] >= 10 && a[x - 1] >= 10) {
for (int i = 1; i < x; i++) {
int f = 0;
if (a[i] < 10) {
for (int j = i - 1; j >= 0; j--) {
if (a[j] >= (i - j) * 10) {
break;
}
if (j == 0) {
cout << "no\n";
return 0;
}
}
for (int j = i + 1; j < x; j++) {
if (a[j] >= (j - i) * 10) {
break;
}
if (j == x - 1) {
cout << "no\n";
return 0;
}
}
}
}
} else {
cout << "no\n";
return 0;
}
cout << "yes\n";
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
long long a[300002];
int x, y, z;
cin >> x;
for (int i = 0; i < x; i++) {
cin >> a[i];
}
if (a[0] >= 10 && a[x - 1] >= 10) {
for (int i = 1; i < x; i++) {
int f = 0;
if (a[i] < 10) {
for (int j = i - 1; j >= 0; j--) {
if (a[j] >= (i - j) * 10 + 10) {
break;
}
if (j == 0) {
cout << "no\n";
return 0;
}
}
for (int j = i + 1; j < x; j++) {
if (a[j] >= (j - i) * 10 + 10) {
break;
}
if (j == x - 1) {
cout << "no\n";
return 0;
}
}
}
}
} else {
cout << "no\n";
return 0;
}
cout << "yes\n";
return 0;
}
|
[["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 72], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13], ["+", 15, 339, 51, 16, 12, 16, 31, 16, 12, 13]]
| 1
| 240
| 4
|
#include <bits/stdc++.h>
#define rep(i, n) for (long long int(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (long long int i = (a); i < (b); i++)
#define rrrep(i, a, b) for (long long int i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a, b) max(a, b) - min(a, b)
#define YES(condition) \
if (condition) { \
cout << "YES" << endl; \
} else { \
cout << "NO" << endl; \
}
#define Yes(condition) \
if (condition) { \
cout << "Yes" << endl; \
} else { \
cout << "No" << endl; \
}
#define Cout(x) cout << (x) << endl
#define POSSIBLE(condition) \
if (condition) { \
cout << "POSSIBLE" << endl; \
} else { \
cout << "IMPOSSIBLE" << endl; \
}
#define Possible(condition) \
if (condition) { \
cout << "Possible" << endl; \
} else { \
cout << "Impossible" << endl; \
}
#define possible(condition) \
if (condition) { \
cout << "possible" << endl; \
} else { \
cout << "impossible" << endl; \
}
#define Size(n) (n).size()
typedef long long ll;
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7;
const ll LINF = 1e18;
/*---------------------------------------------------------------
long long int kaizyo(long long int hh){
cmp=1;
while(hh>1){
cmp=(cmp*hh)%MOD;
hh--;
}
return cmp;
}
long long int ruizyo(long long int aa, long long int bb){
if(aa==0){
return 1;
}
else if(aa%2==0){
long long int tt=ruizyo(aa/2,bb);
return (tt*tt)%MOD;
}
else{
return (ruizyo(aa-1,bb)*bb)%MOD;
}
}フェルマ-のア
---------------------------------------------------------------
while(x!=0){
sum+=x%10;
/ x/=10;
}
各桁の和
---------------------------------------------------------------
pair<int,int> p[100000];
cin >> tmp;
p[i]=make_pair(tmp,i);
cout << p[i].second+1 << endl;//ペアの右側つまりiを出力
---------------------------------------------------------------
s.find(w[i])==string::npos
findの使い方
---------------------------------------------------------------
for(int i=0;i<n;i++){
b[i]=x%2;
x/=2;
}二進数
---------------------------------------------------------------
bool f[100001];//1000000以下の素数を調べよう!
rrep(i,2,100001){
f[i]=false;
}
rrep(i,2,100001){
if(!f[i]){
for(int j=i+i;j<=100000;j+=i){
f[j]=true;
}
}
}
for(int i=3;i<=100000;i+=2){
if(!f[i]){
c[i]++;
}
}
---------------------------------------------------------------
visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに
---------------------------------------------------------------
long long gcd(long long aaa,long long bbb){
if(bbb==0){
return aaa;
}
return gcd(bbb,aaa%bbb);
}
long long lcm(long long aaa,long long bbb){
long long g = gcd(aaa,bbb);
return aaa/g * bbb;
}左から最大公約数と最小公倍数
---------------------------------------------------------------
long long int prime_cnt[10000];
for(int i=2;i*i<=n;i++){
while(n%i==0){
n/=i;
prime_cnt[i]+=1;
}
if(n>1){
prime_cnt[n]+=1;
break;
}
}ある数nを素因数分解しましょう
---------------------------------------------------------------
debug:
cout<<"i: "<<i<<" j: "<<j<<" cnt: "<<cnt<<"\n";
---------------------------------------------------------------*/
long long int n, cnt = 0, ans = 0, a[1000000], b, c, d, cmp = 0, cmpp, m, h, w,
x, y, sum = 0, pos;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
bool fl = true;
struct edge {
int to, cost;
};
//-------------------------↓↓↓↓↓↓------------------------
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
rep(i, n) {
cin >> a[i];
a[i] /= 10;
}
rep(i, n) {
cmp = max(cmp, i + a[i]);
if (cmp < i) {
Cout("no");
return 0;
}
}
reverse(a, a + n);
cmp = 0;
rep(i, n) {
cmp = max(cmp, i + a[i]);
if (cmp <= i) {
Cout("no");
return 0;
}
}
Cout("yes");
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (long long int(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (long long int i = (a); i < (b); i++)
#define rrrep(i, a, b) for (long long int i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a, b) max(a, b) - min(a, b)
#define YES(condition) \
if (condition) { \
cout << "YES" << endl; \
} else { \
cout << "NO" << endl; \
}
#define Yes(condition) \
if (condition) { \
cout << "Yes" << endl; \
} else { \
cout << "No" << endl; \
}
#define Cout(x) cout << (x) << endl
#define POSSIBLE(condition) \
if (condition) { \
cout << "POSSIBLE" << endl; \
} else { \
cout << "IMPOSSIBLE" << endl; \
}
#define Possible(condition) \
if (condition) { \
cout << "Possible" << endl; \
} else { \
cout << "Impossible" << endl; \
}
#define possible(condition) \
if (condition) { \
cout << "possible" << endl; \
} else { \
cout << "impossible" << endl; \
}
#define Size(n) (n).size()
typedef long long ll;
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7;
const ll LINF = 1e18;
/*---------------------------------------------------------------
long long int kaizyo(long long int hh){
cmp=1;
while(hh>1){
cmp=(cmp*hh)%MOD;
hh--;
}
return cmp;
}
long long int ruizyo(long long int aa, long long int bb){
if(aa==0){
return 1;
}
else if(aa%2==0){
long long int tt=ruizyo(aa/2,bb);
return (tt*tt)%MOD;
}
else{
return (ruizyo(aa-1,bb)*bb)%MOD;
}
}フェルマ-のア
---------------------------------------------------------------
while(x!=0){
sum+=x%10;
/ x/=10;
}
各桁の和
---------------------------------------------------------------
pair<int,int> p[100000];
cin >> tmp;
p[i]=make_pair(tmp,i);
cout << p[i].second+1 << endl;//ペアの右側つまりiを出力
---------------------------------------------------------------
s.find(w[i])==string::npos
findの使い方
---------------------------------------------------------------
for(int i=0;i<n;i++){
b[i]=x%2;
x/=2;
}二進数
---------------------------------------------------------------
bool f[100001];//1000000以下の素数を調べよう!
rrep(i,2,100001){
f[i]=false;
}
rrep(i,2,100001){
if(!f[i]){
for(int j=i+i;j<=100000;j+=i){
f[j]=true;
}
}
}
for(int i=3;i<=100000;i+=2){
if(!f[i]){
c[i]++;
}
}
---------------------------------------------------------------
visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに
---------------------------------------------------------------
long long gcd(long long aaa,long long bbb){
if(bbb==0){
return aaa;
}
return gcd(bbb,aaa%bbb);
}
long long lcm(long long aaa,long long bbb){
long long g = gcd(aaa,bbb);
return aaa/g * bbb;
}左から最大公約数と最小公倍数
---------------------------------------------------------------
long long int prime_cnt[10000];
for(int i=2;i*i<=n;i++){
while(n%i==0){
n/=i;
prime_cnt[i]+=1;
}
if(n>1){
prime_cnt[n]+=1;
break;
}
}ある数nを素因数分解しましょう
---------------------------------------------------------------
debug:
cout<<"i: "<<i<<" j: "<<j<<" cnt: "<<cnt<<"\n";
---------------------------------------------------------------*/
long long int n, cnt = 0, ans = 0, a[1000000], b, c, d, cmp = 0, cmpp, m, h, w,
x, y, sum = 0, pos;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
bool fl = true;
struct edge {
int to, cost;
};
//-------------------------↓↓↓↓↓↓------------------------
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
rep(i, n) {
cin >> a[i];
a[i] /= 10;
}
rep(i, n) {
cmp = max(cmp, i + a[i]);
if (cmp <= i) {
Cout("no");
return 0;
}
}
reverse(a, a + n);
cmp = 0;
rep(i, n) {
cmp = max(cmp, i + a[i]);
if (cmp <= i) {
Cout("no");
return 0;
}
}
Cout("yes");
return 0;
}
|
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19]]
| 1
| 377
| 2
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T = int> T in() {
T x;
std::cin >> x;
return x;
}
#define output(e) std::cout << e << '\n'
#ifdef LOCAL
#define db std::cout << "L" << __LINE__
#define de << "\n"
#define dv(x) << " " << #x << "->" << x
#else
#define db
#define de
#define dv(x)
#endif
//
// Implementation
//
#define MAX_N 300000
int tp[MAX_N];
int main() {
int N = in();
rep(i, N) tp[i] = in();
bool reach = false;
int curr = 0;
while (true) {
if (curr == N - 1) {
reach = true;
}
int maxpos = -1;
int nextmaxpos = 0;
for (int i = curr + 1; i <= curr + 1 + (tp[curr] / 10); i++) {
if (i >= N)
break;
int can = i + (tp[i] / 10);
if (can > nextmaxpos) {
nextmaxpos = can;
maxpos = i;
}
}
if (maxpos == -1) {
break;
}
db dv(curr) de;
curr = maxpos;
}
if (!reach) {
output("no");
return 0;
}
reach = false;
curr = N - 1;
while (true) {
if (curr == 0) {
reach = true;
}
int maxpos = -1;
int nextmaxpos = 9999999;
for (int i = curr - 1; i > curr - 1 - (tp[curr] / 10); i--) {
if (i < 0)
break;
int can = i - (tp[i] / 10);
if (can < nextmaxpos) {
nextmaxpos = can;
maxpos = i;
}
}
if (maxpos == -1) {
break;
}
curr = maxpos;
db dv(curr) de;
}
if (!reach) {
output("no");
return 0;
}
output("yes");
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T = int> T in() {
T x;
std::cin >> x;
return x;
}
#define output(e) std::cout << e << '\n'
#ifdef LOCAL
#define db std::cout << "L" << __LINE__
#define de << "\n"
#define dv(x) << " " << #x << "->" << x
#else
#define db
#define de
#define dv(x)
#endif
//
// Implementation
//
#define MAX_N 300000
int tp[MAX_N];
int main() {
int N = in();
rep(i, N) tp[i] = in();
bool reach = false;
int curr = 0;
while (true) {
if (curr == N - 1) {
reach = true;
}
int maxpos = -1;
int nextmaxpos = 0;
for (int i = curr + 1; i < curr + 1 + (tp[curr] / 10); i++) {
if (i >= N)
break;
int can = i + (tp[i] / 10);
if (can > nextmaxpos) {
nextmaxpos = can;
maxpos = i;
}
}
if (maxpos == -1) {
break;
}
db dv(curr) de;
curr = maxpos;
}
if (!reach) {
output("no");
return 0;
}
reach = false;
curr = N - 1;
while (true) {
if (curr == 0) {
reach = true;
}
int maxpos = -1;
int nextmaxpos = 9999999;
for (int i = curr - 1; i > curr - 1 - (tp[curr] / 10); i--) {
if (i < 0)
break;
int can = i - (tp[i] / 10);
if (can < nextmaxpos) {
nextmaxpos = can;
maxpos = i;
}
}
if (maxpos == -1) {
break;
}
curr = maxpos;
db dv(curr) de;
}
if (!reach) {
output("no");
return 0;
}
output("yes");
}
|
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18]]
| 1
| 426
| 2
|
#include <bits/stdc++.h>
using namespace std;
int a[300001], A[300001];
int main(void) {
int n, q;
int x, y;
int cnt = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
A[i] = a[i];
}
sort(a, a + n);
for (int i = 0; i < n; i++) {
if (a[i] == A[i]) {
cnt++;
}
}
if (cnt == n) {
cout << 0 << endl;
return 0;
}
cin >> q;
for (int i = 0; i < q; i++) {
cin >> x >> y;
x--;
y--;
if (a[x] == A[x]) {
cnt--;
}
if (a[y] == a[y]) {
cnt--;
}
swap(A[x], A[y]);
if (a[x] == A[x]) {
cnt++;
}
if (a[y] == A[y]) {
cnt++;
}
if (cnt == n) {
cout << i + 1 << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[300001], A[300001];
int main(void) {
int n, q;
int x, y;
int cnt = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
A[i] = a[i];
}
sort(a, a + n);
for (int i = 0; i < n; i++) {
if (a[i] == A[i]) {
cnt++;
}
}
if (cnt == n) {
cout << 0 << endl;
return 0;
}
cin >> q;
for (int i = 0; i < q; i++) {
cin >> x >> y;
x--;
y--;
if (a[x] == A[x]) {
cnt--;
}
if (a[y] == A[y]) {
cnt--;
}
swap(A[x], A[y]);
if (a[x] == A[x]) {
cnt++;
}
if (a[y] == A[y]) {
cnt++;
}
if (cnt == n) {
cout << i + 1 << endl;
return 0;
}
}
cout << -1 << endl;
return 0;
}
|
[["-", 0, 57, 15, 339, 51, 16, 12, 69, 28, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 69, 28, 22]]
| 1
| 276
| 2
|
#include <bits/stdc++.h>
using namespace std;
char s[100000], t[100000];
int main(void) {
int n, cnt[30];
int i, j;
cin >> n;
for (i = 0; i < n; i++)
cin >> s[i];
for (i = 0; i < n; i++)
cin >> t[i];
for (i = 0; i < 30; i++)
cnt[i] = 0;
cnt[s[0] - 97]++;
for (i = 0; i < n - 1; i++) {
if (cnt[t[i] - 97] != 0) {
cnt[s[i] - 97] += cnt[t[i] - 97];
if (cnt[s[i] - 97] % 1000000007 != 0) {
cnt[s[i] - 97] %= 1000000007;
}
}
}
printf("%d\n", cnt[t[n - 1] - 97]);
/*for(j=0;j<30;j++) printf("%c ",j+97);
printf("\n");
for(j=0;j<30;j++) printf("%d ",cnt[j]);
printf("\n");*/
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
char s[100000], t[100000];
int main(void) {
int n, cnt[30];
int i, j;
cin >> n;
for (i = 0; i < n; i++)
cin >> s[i];
for (i = 0; i < n; i++)
cin >> t[i];
for (i = 0; i < 30; i++)
cnt[i] = 0;
cnt[s[0] - 97]++;
for (i = 1; i < n - 1; i++) {
if (cnt[t[i] - 97] != 0) {
cnt[s[i] - 97] += cnt[t[i] - 97];
if (cnt[s[i] - 97] % 1000000007 != 0) {
cnt[s[i] - 97] %= 1000000007;
}
}
}
printf("%d\n", cnt[t[n - 1] - 97]);
/*for(j=0;j<30;j++) printf("%c ",j+97);
printf("\n");
for(j=0;j<30;j++) printf("%d ",cnt[j]);
printf("\n");*/
return 0;
}
|
[["-", 0, 14, 8, 9, 0, 7, 10, 11, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 10, 11, 12, 13]]
| 1
| 219
| 2
|
#include <iostream>
#define MOD 1000000007
#define N_MAX 100001
int main() {
int dp[27] = {};
char enter[N_MAX], exit[N_MAX];
int N;
std::cin >> N;
std::cin >> enter >> exit;
dp[enter[0] - 'a'] += 1;
for (int i = 0; i < N - 1; i++) {
dp[enter[i] - 'a'] += dp[exit[i] - 'a'];
dp[enter[i] - 'a'] %= MOD;
}
std::cout << dp[exit[N - 1] - 'a'] << std::endl;
return 0;
}
|
#include <iostream>
#define MOD 1000000007
#define N_MAX 100001
int main() {
int dp[27] = {};
char enter[N_MAX], exit[N_MAX];
int N;
std::cin >> N;
std::cin >> enter >> exit;
dp[enter[0] - 'a'] += 1;
for (int i = 1; i < N - 1; i++) {
dp[enter[i] - 'a'] += dp[exit[i] - 'a'];
dp[enter[i] - 'a'] %= MOD;
}
std::cout << dp[exit[N - 1] - 'a'] << std::endl;
return 0;
}
|
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
| 1
| 146
| 2
|
#include <iostream>
#include <string>
using namespace std;
int main(void) {
int N;
unsigned long long star[26];
string EN, EX;
cin >> N;
cin >> EN;
cin >> EX;
for (int i = 0; i < 26; i++) {
star[i] = 0;
}
star[EN[0] - 0x61] = 1;
for (int i = 1; i < N; i++) {
int en = EN[i] - 0x61;
int ex = EX[i] - 0x61;
if (star[ex] > 0) {
star[en] = star[ex] + star[en];
}
}
cout << star[EX[N - 1] - 0x61] << endl;
}
|
#include <iostream>
#include <string>
using namespace std;
int main(void) {
int N;
unsigned long long star[26];
string EN, EX;
cin >> N;
cin >> EN;
cin >> EX;
for (int i = 0; i < 26; i++) {
star[i] = 0;
}
star[EN[0] - 0x61] = 1;
for (int i = 1; i < N - 1; i++) {
int en = EN[i] - 0x61;
int ex = EX[i] - 0x61;
if (star[ex] > 0) {
star[en] = (star[ex] + star[en]) % 1000000007;
}
}
cout << star[EX[N - 1] - 0x61] << endl;
}
|
[["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 33], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 13], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 109], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 12, 13]]
| 1
| 156
| 6
|
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <functional>
typedef long long ll;
using namespace std;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 100010
typedef double P_type; //座標(integer or real)
typedef double G_real; //実数の戻り値(float or double or long double)
typedef complex<P_type> P;
const G_real P_eps = 1e-8; //整数の時はゼロ
namespace std {
template <class T> bool operator<(const complex<T> &a, const complex<T> &b) {
return abs(a.real() - b.real()) < -P_eps ? a.imag() + P_eps < b.imag()
: a.real() + P_eps < b.real();
}
}; // namespace std
int main() {
int n, k;
vector<P> vec;
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) {
int x, y;
scanf("%d%d", &x, &y);
vec.push_back(P(x, y));
}
int ans = 0;
for (int i = 0; i < n; i++) {
map<P, int> dic;
for (int j = 0; j < n; j++) {
if (i == j)
continue;
P r = (vec[i] - vec[j]) / abs(vec[i] - vec[j]);
if (r.real() < 0)
r *= -1;
if (abs(r.real()) < P_eps && r.imag() < 0)
r *= -1;
dic[r]++;
}
for (auto it : dic) {
ans = max(ans, it.second);
}
}
printf("%d\n", ans >= k - 1);
return 0;
}
|
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <functional>
typedef long long ll;
using namespace std;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 100010
typedef double P_type; //座標(integer or real)
typedef double G_real; //実数の戻り値(float or double or long double)
typedef complex<P_type> P;
const G_real P_eps = 1e-8; //整数の時はゼロ
namespace std {
template <class T> bool operator<(const complex<T> &a, const complex<T> &b) {
return abs(a.real() - b.real()) < P_eps ? a.imag() + P_eps < b.imag()
: a.real() + P_eps < b.real();
}
}; // namespace std
int main() {
int n, k;
vector<P> vec;
scanf("%d%d", &n, &k);
for (int i = 0; i < n; i++) {
int x, y;
scanf("%d%d", &x, &y);
vec.push_back(P(x, y));
}
int ans = 0;
for (int i = 0; i < n; i++) {
map<P, int> dic;
for (int j = 0; j < n; j++) {
if (i == j)
continue;
P r = (vec[i] - vec[j]) / abs(vec[i] - vec[j]);
if (r.real() < 0)
r *= -1;
if (abs(r.real()) < P_eps && r.imag() < 0)
r *= -1;
dic[r]++;
}
for (auto it : dic) {
ans = max(ans, it.second);
}
}
printf("%d\n", ans >= k - 1);
return 0;
}
|
[["-", 0, 37, 0, 41, 15, 16, 12, 91, 17, 33]]
| 1
| 404
| 1
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.