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
#include <string> int n, a; std::string s; main() { scanf("%d", &n); for (; n--; scanf("%d", &a), s += a + 48) ; for (; ~s.find(std::to_string(n++));) ; printf("%d\n", --n); }
#include <string> int n, a; std::string s; main() { scanf("%d", &n); for (; n--; scanf("%d", &a), s += a + 48) ; for (; ~s.find(std::to_string(++n));) ; printf("%d\n", n); }
[["-", 3, 4, 0, 2, 3, 4, 0, 27, 28, 22], ["+", 3, 4, 0, 2, 3, 4, 0, 27, 28, 22], ["-", 0, 1, 0, 2, 3, 4, 0, 27, 17, 68]]
1
80
#include <iostream> #include <string> using namespace std; string S; int n, a; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a; S += to_string(a); } for (int i = 1; i < 100000; i++) { string target = to_string(i); int x = (int)(S.size()) - (int)(target.size()); for (int i = 0; i <= x; i++) { if (S.substr(i, target.size()) == target) { goto E; } } cout << i << endl; break; E:; } return 0; }
#include <iostream> #include <string> using namespace std; string S; int n, a; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a; S += to_string(a); } for (int i = 0; i < 100000; i++) { string target = to_string(i); int x = (int)(S.size()) - (int)(target.size()); for (int i = 0; i <= x; i++) { if (S.substr(i, target.size()) == target) { goto E; } } cout << i << endl; break; E:; } return 0; }
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
1
154
#include <bits/stdc++.h> using namespace std; int main() { int n, a[1000], ans = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; if (a[i]) ans = 100000000; } bool f = 1; int i = 0; while (f) { int k = 1, idx = n - 1; f = 0; for (int j = n - 1; j >= 0; j--) { if (a[j] == i / k % 10) { if (k == 1) idx = j; k *= 10; } else if (k != 1) j = idx, k = 1; if (k > i) f = 1; } i++; } cout << min(ans, i - 1) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a[1000], ans = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; if (!a[i]) ans = 100000000; } bool f = 1; int i = 0; while (f) { int k = 1, idx = n - 1; f = 0; for (int j = n - 1; j >= 0; j--) { if (a[j] == i / k % 10) { if (k == 1) idx = j; k *= 10; } else if (k != 1) j = idx, k = 1; if (k > i) f = 1; } i++; } cout << min(ans, i - 1) << endl; return 0; }
[["+", 8, 9, 0, 57, 15, 339, 51, 91, 17, 111]]
1
184
#include <bits/stdc++.h> using namespace std; int main() { int n, a[1000], f[1000] = {}; cin >> n; for (int i = 0; i < n; i++) cin >> a[i], f[a[i]] = 1; for (int i = 0; i < n - 1; i++) f[a[i] * 10 + a[i + 1]] = 1; for (int i = 0; i < n - 2; i++) f[a[i] * 100 + a[i + 1] * 10 + a[i]] = 1; for (int i = 0; i < 1000; i++) if (f[i] == 0) { cout << i << endl; break; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a[1000], f[1000000] = {}; cin >> n; for (int i = 0; i < n; i++) cin >> a[i], f[a[i]] = 1; for (int i = 0; i < n - 1; i++) f[a[i] * 10 + a[i + 1]] = 1; for (int i = 0; i < n - 2; i++) f[a[i] * 100 + a[i + 1] * 10 + a[i + 2]] = 1; for (int i = 0; i < 1000; i++) if (f[i] == 0) { cout << i << endl; break; } return 0; }
[["-", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["+", 8, 9, 0, 43, 49, 50, 49, 80, 81, 13], ["+", 0, 16, 12, 69, 341, 342, 0, 16, 17, 72], ["+", 0, 16, 12, 69, 341, 342, 0, 16, 12, 13]]
1
176
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using std::cin; using std::cout; using std::endl; using std::fixed; using std::list; using std::make_pair; using std::map; using std::pair; using std::priority_queue; using std::queue; using std::set; // insert erase find count using std::setprecision; using std::stack; using std::string; using std::vector; typedef long long int lli; typedef vector<lli> VI; typedef vector<vector<lli>> VII; typedef vector<string> VS; typedef pair<lli, lli> PII; int string_to_int(string str) { int length = str.length(); int number = 0; for (int i = 0; i < length; i++) { number += (int)(str[i] - '0'); number *= 10; } number /= 10; return number; } int main(void) { lli n; string d = ""; char input; cin >> n; for (lli loop = 0; loop < n; loop++) { cin >> input; d += input; } int digit = 0; int num = 1; bool cont = true; while (cont) { digit++; num *= 10; set<lli> st; int length = d.length(); for (int i = 0; i <= length - digit; i++) { string temp = d.substr(i, digit); int element = string_to_int(temp); st.insert(element); } if (digit == 1 && st.count(0) == 0) { cout << 0 << endl; } for (int i = num / 10; i < num; i++) { if (st.count(i) == 0) { cout << i << endl; cont = false; break; } } } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using std::cin; using std::cout; using std::endl; using std::fixed; using std::list; using std::make_pair; using std::map; using std::pair; using std::priority_queue; using std::queue; using std::set; // insert erase find count using std::setprecision; using std::stack; using std::string; using std::vector; typedef long long int lli; typedef vector<lli> VI; typedef vector<vector<lli>> VII; typedef vector<string> VS; typedef pair<lli, lli> PII; int string_to_int(string str) { int length = str.length(); int number = 0; for (int i = 0; i < length; i++) { number += (int)(str[i] - '0'); number *= 10; } number /= 10; return number; } int main(void) { lli n; string d = ""; char input; cin >> n; for (lli loop = 0; loop < n; loop++) { cin >> input; d += input; } int digit = 0; int num = 1; bool cont = true; while (cont) { digit++; num *= 10; set<lli> st; int length = d.length(); for (int i = 0; i <= length - digit; i++) { string temp = d.substr(i, digit); int element = string_to_int(temp); st.insert(element); } if (digit == 1 && st.count(0) == 0) { cout << 0 << endl; break; } for (int i = num / 10; i < num; i++) { if (st.count(i) == 0) { cout << i << endl; cont = false; break; } } } return 0; }
[["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 94], ["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 35]]
1
412
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #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 n; cin >> n; int d[n]; bool zero = false; FOR(i, 0, n) { cin >> d[i]; zero = d[i] == 0; } if (!zero) { cout << 0 << endl; return 0; } set<int> SET; // ?????° FOR(i, 1, 10000) { // ?????? FOR(j, 0, n) { int x = 0; if (d[j] == 0) continue; FOR(k, 0, i) { x *= 10; x += d[j + k]; } SET.insert(x); } for (int x = pow(10, i - 1); x < pow(10, i); x++) { if (SET.count(x) == 0) { cout << x << endl; return 0; } } } }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #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 n; cin >> n; int d[n]; bool zero = false; FOR(i, 0, n) { cin >> d[i]; zero |= d[i] == 0; } if (!zero) { cout << 0 << endl; return 0; } set<int> SET; // ?????° FOR(i, 1, 10000) { // ?????? FOR(j, 0, n) { int x = 0; if (d[j] == 0) continue; FOR(k, 0, i) { x *= 10; x += d[j + k]; } SET.insert(x); } for (int x = pow(10, i - 1); x < pow(10, i); x++) { if (SET.count(x) == 0) { cout << x << endl; return 0; } } } }
[["-", 8, 9, 0, 9, 0, 1, 0, 11, 17, 32], ["+", 8, 9, 0, 9, 0, 1, 0, 11, 17, 160]]
1
263
// aoj-VolumeICPCOOC2015-B / 2015-11-30 #include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef ll int__; #define rep(i, j) for (int__ i = 0; i < (int__)(j); i++) #define repeat(i, j, k) for (int__ i = (j); i < (int__)(k); i++) #define all(v) v.begin(), v.end() template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) os << v[i] << (i != v.size() - 1 ? " " : ""); return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { rep(i, v.size()) is >> v[i]; return is; } #ifdef DEBUG void debug() { cerr << " : Debug" << endl; } #endif template <class F, class... R> void debug(const F &car, const R &...cdr) { #ifdef DEBUG cerr << car << " "; debug(cdr...); #endif } const double EPS = 1e-8; struct Point { double x, y; Point() : x(0), y(0) {} Point(double x, double y) : x(x), y(y){}; bool operator==(const Point &a) const { return x == a.x && y == a.y; } Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); } }; istream &operator>>(istream &is, Point &p) { return is >> p.x >> p.y; } ostream &operator<<(ostream &os, const Point &p) { return os << "(" << p.x << "," << p.y << ")"; } double dot(const Point &a, const Point &b) { return a.x * b.x + a.y * b.y; } double cross(const Point &a, const Point &b) { return a.x * b.y - a.y * b.x; } double norm(const Point &a) { return sqrt(dot(a, a)); } double distance(const Point &a, const Point &b) { return norm(a - b); } bool check(vector<Point> &P, vector<int> &R, Point &np, int nr) { rep(i, P.size()) { if (distance(P[i], np) - (R[i] + nr) > EPS) return false; } return true; } bool solve() { int n; cin >> n; vector<int> R(n); cin >> R; vector<Point> P; for (int r : R) { double l = P.size() > 0 ? max(P.back().x, (double)r) : r; double h = 1e10; while (h - l > 1e-8) { double m = (l + h) / 2; Point p = Point(m, r); if (check(P, R, p, r)) h = m; else l = m; } P.push_back(Point(h, r)); } debug(P); double ans = 0; rep(i, P.size()) ans = max(ans, P[i].x + R[i]); printf("%.8f\n", ans); return false; } int main() { ios::sync_with_stdio(false); while (solve()) ; return 0; }
// aoj-VolumeICPCOOC2015-B / 2015-11-30 #include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef ll int__; #define rep(i, j) for (int__ i = 0; i < (int__)(j); i++) #define repeat(i, j, k) for (int__ i = (j); i < (int__)(k); i++) #define all(v) v.begin(), v.end() template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) os << v[i] << (i != v.size() - 1 ? " " : ""); return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { rep(i, v.size()) is >> v[i]; return is; } #ifdef DEBUG void debug() { cerr << " : Debug" << endl; } #endif template <class F, class... R> void debug(const F &car, const R &...cdr) { #ifdef DEBUG cerr << car << " "; debug(cdr...); #endif } const double EPS = 1e-8; struct Point { double x, y; Point() : x(0), y(0) {} Point(double x, double y) : x(x), y(y){}; bool operator==(const Point &a) const { return x == a.x && y == a.y; } Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); } }; istream &operator>>(istream &is, Point &p) { return is >> p.x >> p.y; } ostream &operator<<(ostream &os, const Point &p) { return os << "(" << p.x << "," << p.y << ")"; } double dot(const Point &a, const Point &b) { return a.x * b.x + a.y * b.y; } double cross(const Point &a, const Point &b) { return a.x * b.y - a.y * b.x; } double norm(const Point &a) { return sqrt(dot(a, a)); } double distance(const Point &a, const Point &b) { return norm(a - b); } bool check(vector<Point> &P, vector<int> &R, Point &np, int nr) { rep(i, P.size()) { if (distance(P[i], np) - (R[i] + nr) < 0.0) return false; } return true; } bool solve() { int n; cin >> n; vector<int> R(n); cin >> R; vector<Point> P; for (int r : R) { double l = P.size() > 0 ? max(P.back().x, (double)r) : r; double h = 1e10; while (h - l > 1e-8) { double m = (l + h) / 2; Point p = Point(m, r); if (check(P, R, p, r)) h = m; else l = m; } P.push_back(Point(h, r)); } debug(P); double ans = 0; rep(i, P.size()) ans = max(ans, P[i].x + R[i]); printf("%.10f\n", ans); return false; } int main() { ios::sync_with_stdio(false); while (solve()) ; return 0; }
[["-", 0, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["-", 0, 9, 0, 57, 15, 339, 51, 16, 12, 22], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
800
#include <bits/stdc++.h> #define N 10005 using namespace std; int main() { int n, r[N]; cin >> n; for (int i = 0; i < n; i++) cin >> r[i]; double x[N], ans = 0; x[0] = r[0]; for (int i = 1; i < n; i++) { double maxx = 0; for (int j = 0; j < i; j++) { int A = r[i] + r[j]; int B = r[i] - r[j]; maxx = max(maxx, max(x[j] + sqrt(A * A - B * B), 1.0 * r[i])); } x[i] = maxx; ans = max(ans, x[i] + r[i]); } printf("%.8f\n", ans); return 0; }
#include <bits/stdc++.h> #define N 10005 using namespace std; int main() { int n, r[N]; cin >> n; for (int i = 0; i < n; i++) cin >> r[i]; double x[N], ans = r[0] * 2; x[0] = r[0]; for (int i = 1; i < n; i++) { double maxx = 0; for (int j = 0; j < i; j++) { int A = r[i] + r[j]; int B = r[i] - r[j]; maxx = max(maxx, max(x[j] + sqrt(A * A - B * B), 1.0 * r[i])); } x[i] = maxx; ans = max(ans, x[i] + r[i]); } printf("%.8f\n", ans); return 0; }
[["+", 0, 43, 49, 50, 51, 16, 31, 69, 28, 22], ["+", 49, 50, 51, 16, 31, 69, 341, 342, 0, 70], ["+", 49, 50, 51, 16, 31, 69, 341, 342, 0, 73], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 17, 48], ["+", 8, 9, 0, 43, 49, 50, 51, 16, 12, 13]]
1
201
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define all(c) c.begin(), c.end() #define pb push_back #define fs first #define sc second #define show(x) cout << #x << " = " << x << endl #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) using namespace std; int N, M, a[3], dp[50]; vector<int> G[50]; int inf = 1e8; bool can[101][50][50]; int main() { cin >> N >> M >> a[0] >> a[1] >> a[2]; rep(i, M) { int v, w; cin >> v >> w; v--, w--; G[v].pb(w); } rep(i, N) can[0][i][i] = 1; rep(i, N) { rep(v, N) for (int u : G[v]) rep(x, N) if (can[i][u][x]) can[i + 1][v][x] = 1; } rep(i, N) dp[i] = inf; dp[N - 1] = 0; bool update = 1; while (update) { update = 0; rep(i, N) { int mx = -1; rep(j, 3) { int mn = inf; rep(v, N) { if (can[a[j]][i][v]) chmin(mn, dp[v] + 1); } chmax(mx, mn); } if (mx < dp[i]) { update = 1; dp[i] = mx; } } } if (dp[0] == inf) puts("IMPOSSIBLE"); else cout << dp[0] << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define all(c) c.begin(), c.end() #define pb push_back #define fs first #define sc second #define show(x) cout << #x << " = " << x << endl #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) using namespace std; int N, M, a[3], dp[50]; vector<int> G[50]; int inf = 1e8; bool can[101][50][50]; int main() { cin >> N >> M >> a[0] >> a[1] >> a[2]; rep(i, M) { int v, w; cin >> v >> w; v--, w--; G[v].pb(w); } rep(i, N) can[0][i][i] = 1; rep(i, 100) { rep(v, N) for (int u : G[v]) rep(x, N) if (can[i][u][x]) can[i + 1][v][x] = 1; } rep(i, N) dp[i] = inf; dp[N - 1] = 0; bool update = 1; while (update) { update = 0; rep(i, N) { int mx = -1; rep(j, 3) { int mn = inf; rep(v, N) { if (can[a[j]][i][v]) chmin(mn, dp[v] + 1); } chmax(mx, mn); } if (mx < dp[i]) { update = 1; dp[i] = mx; } } } if (dp[0] == inf) puts("IMPOSSIBLE"); else cout << dp[0] << endl; }
[["-", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 0, 1, 0, 2, 3, 4, 0, 25, 0, 35]]
1
394
#include <bits/stdc++.h> using namespace std; int N, M, A[3]; bool graph[50][50]; bool v[101][50][50]; void Calculation() { cin >> N >> M; for (int i = 0; i < 3; i++) { cin >> A[i]; } sort(begin(A), end(A)); while (M--) { int U, V; cin >> U >> V; --U, --V; graph[V][U] = v[0][V][U] = true; } for (int l = 1; l <= A[2]; l++) { for (int k = 0; k < N; ++k) { for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { v[l][i][j] |= v[l - 1][i][k] & graph[k][j]; } } } } int min_cost[50], bit[50] = {}; queue<int> que; memset(min_cost, -1, sizeof(min_cost)); que.emplace(N - 1); min_cost[N - 1] = 0; while (!que.empty()) { int p = que.front(); que.pop(); if (p == 0) { cout << min_cost[p] + 1 << endl; return; } for (int i = 0; i < 3; i++) { for (int j = 0; j < N; j++) { if (!v[A[i]][p][j]) continue; bit[j] |= 1 << i; if (bit[j] == 7 && min_cost[j] == -1) { min_cost[j] = min_cost[p] + 1; que.emplace(j); } } } } cout << "IMPOSSIBLE" << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); Calculation(); }
#include <bits/stdc++.h> using namespace std; int N, M, A[3]; bool graph[50][50]; bool v[101][50][50]; void Calculation() { cin >> N >> M; for (int i = 0; i < 3; i++) { cin >> A[i]; } sort(begin(A), end(A)); while (M--) { int U, V; cin >> U >> V; --U, --V; graph[V][U] = v[0][V][U] = true; } for (int l = 1; l <= A[2]; l++) { for (int k = 0; k < N; ++k) { for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) { v[l][i][j] |= v[l - 1][i][k] & graph[k][j]; } } } } int min_cost[50], bit[50] = {}; queue<int> que; memset(min_cost, -1, sizeof(min_cost)); que.emplace(N - 1); min_cost[N - 1] = 0; while (!que.empty()) { int p = que.front(); que.pop(); if (p == 0) { cout << min_cost[p] << endl; return; } for (int i = 0; i < 3; i++) { for (int j = 0; j < N; j++) { if (!v[A[i] - 1][p][j]) continue; bit[j] |= 1 << i; if (bit[j] == 7 && min_cost[j] == -1) { min_cost[j] = min_cost[p] + 1; que.emplace(j); } } } } cout << "IMPOSSIBLE" << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); Calculation(); }
[["-", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["-", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13], ["+", 28, 69, 28, 69, 341, 342, 0, 16, 17, 33], ["+", 28, 69, 28, 69, 341, 342, 0, 16, 12, 13]]
1
455
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <string> #include <vector> using namespace std; int N, M; string S; int A[11]; vector<int> D; int calc(char num) { int n = (int)(num - '0'); n *= 2; return n / 10 + n % 10; } int calc(int num) { int n = num; n *= 2; return n / 10 + n % 10; } int solve(int no, int sum) { if (no == (int)D.size()) { // printf("%d\n",sum); if (!(sum % 10)) return 1; return 0; } int ret = 0; for (int i = 0; i < M; i++) { ret += solve(no + 1, sum + (((N - D[no]) % 2) ? A[i] : calc(A[i]))); } return ret; } int main() { cin >> N; cin >> S; cin >> M; for (int i = 0; i < M; i++) { cin >> A[i]; } for (int i = 0; i < N; i++) if (S[i] == '*') D.push_back(N - i); int sum = 0; for (int i = N - 1, j = 1; i > -1; i--, j++) { if (S[i] == '*') continue; if (!(j % 2)) sum += calc(S[i]); else sum += (int)(S[i] - '0'); } // printf("%d\n",sum); printf("%d\n", solve(0, sum)); }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <string> #include <vector> using namespace std; int N, M; string S; int A[11]; vector<int> D; int calc(char num) { int n = (int)(num - '0'); n *= 2; return n / 10 + n % 10; } int calc(int num) { int n = num; n *= 2; return n / 10 + n % 10; } int solve(int no, int sum) { if (no == (int)D.size()) { // printf("%d\n",sum); if (!(sum % 10)) return 1; return 0; } int ret = 0; for (int i = 0; i < M; i++) { ret += solve(no + 1, sum + (((D[no]) % 2) ? A[i] : calc(A[i]))); } return ret; } int main() { cin >> N; cin >> S; cin >> M; for (int i = 0; i < M; i++) cin >> A[i]; for (int i = 0; i < N; i++) if (S[i] == '*') D.push_back(N - i); int sum = 0; for (int i = N - 1, j = 1; i > -1; i--, j++) { if (S[i] == '*') continue; if (!(j % 2)) sum += calc(S[i]); else sum += (int)(S[i] - '0'); } // printf("%d\n",sum); printf("%d\n", solve(0, sum)); }
[["-", 15, 23, 0, 16, 31, 23, 0, 16, 31, 22], ["-", 15, 23, 0, 16, 31, 23, 0, 16, 17, 33], ["-", 0, 14, 8, 9, 0, 7, 8, 9, 0, 45], ["-", 0, 14, 8, 9, 0, 7, 8, 9, 0, 46]]
1
372
#include <stdio.h> char str[131072]; int c[10]; int dp[8][10]; int main() { int a; scanf("%d%s", &a, str); int b; int s; scanf("%d", &b); for (int i = 0; i < b; i++) { scanf("%d", &s); c[s] = 1; // scanf("%d",c+i); } int d = 0; int e = 0; int v = 0; for (int i = 0; i < a; i++) { if (str[i] == '*') { if ((a - i) % 2 == 1) d++; else e++; } else { int p = str[i] - '0'; if ((a - 1) % 2 == 0) p *= 2; if (p >= 10) p -= 9; v += p; } } dp[0][v % 10] = 1; for (int i = 0; i < d + e; i++) { for (int j = 0; j < 10; j++) { if (i < d) { for (int k = 0; k < 10; k++) { if (!c[k]) continue; dp[i + 1][(j + k) % 10] += dp[i][j]; } } else { for (int k = 0; k < 10; k++) { if (!c[k]) continue; int p = k * 2; if (p >= 10) p -= 9; dp[i + 1][(j + p) % 10] += dp[i][j]; } } } } printf("%d\n", dp[d + e][0]); }
#include <stdio.h> char str[131072]; int c[10]; int dp[8][10]; int main() { int a; scanf("%d%s", &a, str); int b; int s; scanf("%d", &b); for (int i = 0; i < b; i++) { scanf("%d", &s); c[s] = 1; // scanf("%d",c+i); } int d = 0; int e = 0; int v = 0; for (int i = 0; i < a; i++) { if (str[i] == '*') { if ((a - i) % 2 == 1) d++; else e++; } else { int p = str[i] - '0'; if ((a - i) % 2 == 0) p *= 2; if (p >= 10) p -= 9; v += p; } } dp[0][v % 10] = 1; for (int i = 0; i < d + e; i++) { for (int j = 0; j < 10; j++) { if (i < d) { for (int k = 0; k < 10; k++) { if (!c[k]) continue; dp[i + 1][(j + k) % 10] += dp[i][j]; } } else { for (int k = 0; k < 10; k++) { if (!c[k]) continue; int p = k * 2; if (p >= 10) p -= 9; dp[i + 1][(j + p) % 10] += dp[i][j]; } } } } printf("%d\n", dp[d + e][0]); }
[["-", 51, 16, 31, 16, 31, 23, 0, 16, 12, 13], ["+", 51, 16, 31, 16, 31, 23, 0, 16, 12, 22]]
1
394
#include <iostream> #include <string> using namespace std; #define N 100000 int q2n[10] = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9}; int main() { int n, a[10], m, dp[N + 1][10]; string s; cin >> n >> s; cin >> m; for (int j = 0; j < 10; ++j) dp[0][j] = 0; for (int i = 0; i < m; ++i) cin >> a[i]; dp[0][0] = 1; for (int i = 0; i < n; ++i) { for (int j = 0; j < 10; ++j) dp[i + 1][j] = 0; if (s[n - 1 - i] == '*') { if (i % 2) { for (int j = 0; j < 10; ++j) for (int k = 0; k < m; ++k) { dp[i + 1][(j + q2n[a[k]]) % 10] += dp[i][j]; } } else { for (int j = 0; j < 10; ++j) for (int k = 0; k < m; ++k) { dp[i + 1][(j + a[k]) % 10] += dp[i][j]; } } } else { if (i % 2) { for (int j = 0; j < 10; ++j) { dp[i + 1][(j + q2n[(int)(s[n - 1 - i] - '0')]) % 10] += dp[i][j]; } } else { for (int j = 0; j < 10; ++j) { dp[i + 1][(j + (int)(s[n - 1 - i])) % 10] += dp[i][j]; } } } } cout << dp[n][0] << endl; return 0; }
#include <iostream> #include <string> using namespace std; #define N 100000 int q2n[10] = {0, 2, 4, 6, 8, 1, 3, 5, 7, 9}; int main() { int n, a[10], m, dp[N + 1][10]; string s; cin >> n >> s; cin >> m; for (int j = 0; j < 10; ++j) dp[0][j] = 0; for (int i = 0; i < m; ++i) cin >> a[i]; dp[0][0] = 1; for (int i = 0; i < n; ++i) { for (int j = 0; j < 10; ++j) dp[i + 1][j] = 0; if (s[n - 1 - i] == '*') { if (i % 2) { for (int j = 0; j < 10; ++j) for (int k = 0; k < m; ++k) { dp[i + 1][(j + q2n[a[k]]) % 10] += dp[i][j]; } } else { for (int j = 0; j < 10; ++j) for (int k = 0; k < m; ++k) { dp[i + 1][(j + a[k]) % 10] += dp[i][j]; } } } else { if (i % 2) { for (int j = 0; j < 10; ++j) { dp[i + 1][(j + q2n[(int)(s[n - 1 - i] - '0')]) % 10] += dp[i][j]; } } else { for (int j = 0; j < 10; ++j) { dp[i + 1][(j + (int)(s[n - 1 - i] - '0')) % 10] += dp[i][j]; } } } } cout << dp[n][0] << endl; return 0; }
[["+", 0, 16, 12, 74, 51, 23, 0, 16, 17, 33], ["+", 12, 74, 51, 23, 0, 16, 12, 103, 0, 104], ["+", 12, 74, 51, 23, 0, 16, 12, 103, 0, 125]]
1
460
n = gets.to_i s = gets.chomp gets candidates = gets.split.map(&:to_i) dp = [1] + [0] * 9 (0..s.size-1).each do |i| new_dp = [0] * 10 (s[i] == ?* ? candidates : [s[i].to_i]).each do |c| if (s.size - i).even? c = (c * 2).to_s.split("").map(&:to_i).inject(:+) end (0..9).each do |j| new_dp[(j + c) % 10] += dp[j] end end p dp = new_dp end p dp[0]
n = gets.to_i s = gets.chomp gets candidates = gets.split.map(&:to_i) dp = [1] + [0] * 9 (0..s.size-1).each do |i| new_dp = [0] * 10 (s[i] == ?* ? candidates : [s[i].to_i]).each do |c| if (s.size - i).even? c = (c * 2).to_s.split("").map(&:to_i).inject(:+) end (0..9).each do |j| new_dp[(j + c) % 10] += dp[j] end end dp = new_dp end p dp[0]
[["-", 0, 652, 196, 737, 8, 736, 0, 652, 735, 22]]
4
155
#include <algorithm> #include <cmath> #include <iostream> using namespace std; typedef long long int lli; lli pascal[1010][1010]; const int MOD = 100000007; int main() { pascal[0][0] = 1; for (int i = 1; i < 1010; i++) { pascal[i][0] = pascal[i][i] = 1; for (int j = 1; j < i; j++) pascal[i][j] = (pascal[i - 1][j] + pascal[i - 1][j - 1]) % MOD; } int r, c, sx, sy, gx, gy; cin >> r >> c >> sx >> sy >> gx >> gy; int t = 0; int xx, yy; xx = min(abs(sx - gx), r - abs(sx - gx)); yy = min(abs(sy - gy), r - abs(sy - gy)); if (r == abs(sy - gy) * 2) t++; if (c == abs(sx - gx) * 2) t++; cout << (pascal[xx + yy][xx] << t) % MOD << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> using namespace std; typedef long long int lli; lli pascal[1010][1010]; const int MOD = 100000007; int main() { pascal[0][0] = 1; for (int i = 1; i < 1010; i++) { pascal[i][0] = pascal[i][i] = 1; for (int j = 1; j < i; j++) pascal[i][j] = (pascal[i - 1][j] + pascal[i - 1][j - 1]) % MOD; } int r, c, sx, sy, gx, gy; cin >> r >> c >> sx >> sy >> gx >> gy; int t = 0; int xx, yy; xx = min(abs(sx - gx), r - abs(sx - gx)); yy = min(abs(sy - gy), c - abs(sy - gy)); if (r == abs(sx - gx) * 2) t++; if (c == abs(sy - gy) * 2) t++; cout << (pascal[xx + yy][xx] << t) % MOD << endl; return 0; }
[["-", 0, 11, 12, 2, 3, 4, 0, 16, 31, 22], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 31, 22], ["-", 12, 16, 31, 2, 3, 4, 0, 16, 31, 22], ["+", 12, 16, 31, 2, 3, 4, 0, 16, 31, 22], ["-", 12, 16, 31, 2, 3, 4, 0, 16, 12, 22], ["+", 12, 16, 31, 2, 3, 4, 0, 16, 12, 22]]
1
263
#include <algorithm> #include <stdio.h> #define mod 1000000007 using namespace std; int r, c, a1, a2, b1, b2, f1, f2, dp[1001][1001]; int main() { scanf("%d%d%d%d%d%d", &r, &c, &a1, &a2, &b1, &b2); if (a1 > b1) swap(a1, b1); if (a2 > b2) swap(a2, b2); f1 = ((b1 - a1) * 2 == r ? 2 : 1); f2 = ((b2 - a2) * 2 == c ? 2 : 1); if ((b1 - a1) * 2 > r) a1 += r, swap(a1, b1); b1 -= a1, a1 = 0; if ((b2 - a2) * 2 > c) a2 += c, swap(a2, b2); b2 -= a2, a2 = 0; dp[0][0] = 1; for (int i = 0; i <= 1000; i++) { for (int j = 0; j <= 1000; j++) { if (i) dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod; if (j) dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod; } } printf("%d\n", dp[b1][b2] * f1 * f2 % mod); return 0; }
#include <algorithm> #include <stdio.h> #define mod 100000007 using namespace std; int r, c, a1, a2, b1, b2, f1, f2, dp[1001][1001]; int main() { scanf("%d%d%d%d%d%d", &r, &c, &a1, &a2, &b1, &b2); if (a1 > b1) swap(a1, b1); if (a2 > b2) swap(a2, b2); f1 = ((b1 - a1) * 2 == r ? 2 : 1); f2 = ((b2 - a2) * 2 == c ? 2 : 1); if ((b1 - a1) * 2 > r) a1 += r, swap(a1, b1); b1 -= a1, a1 = 0; if ((b2 - a2) * 2 > c) a2 += c, swap(a2, b2); b2 -= a2, a2 = 0; dp[0][0] = 1; for (int i = 0; i <= 1000; i++) { for (int j = 0; j <= 1000; j++) { if (i) dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod; if (j) dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod; } } printf("%d\n", dp[b1][b2] * f1 * f2 % mod); return 0; }
[["-", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59], ["+", 36, 36, 36, 36, 0, 30, 0, 58, 51, 59]]
1
326
#include <iostream> using namespace std; int a, b, c, d, e, f; int dp[4000][4000]; int main() { dp[0][0] = 1; for (int i = 0; i < 4000; i++) { for (int j = 0; j < 4000; j++) { if (i == 0 || j == 0) dp[i][j] = 1; else { dp[i][j] = dp[i - 1][j] + dp[i][j - 1]; } dp[i][j] %= 1000000007; } } int n, m, a, b, c, d, p = 1000000000, q = 0; cin >> n >> m >> a >> b >> c >> d; for (int i = -2; i <= 2; i++) { for (int j = -2; j <= 2; j++) { int x = c + i * n; int y = d + j * m; x -= a; y -= b; if (x < 0) x = -x; if (y < 0) y = -y; if (x + y < p) { p = x + y; q = dp[x][y]; } else if (x + y == p) { q += dp[x][y]; q %= 1000000007; } } } cout << q << endl; return 0; }
#include <iostream> using namespace std; int a, b, c, d, e, f; int dp[4000][4000]; int main() { dp[0][0] = 1; for (int i = 0; i < 4000; i++) { for (int j = 0; j < 4000; j++) { if (i == 0 || j == 0) dp[i][j] = 1; else { dp[i][j] = dp[i - 1][j] + dp[i][j - 1]; } dp[i][j] %= 100000007; } } int n, m, a, b, c, d, p = 1000000000, q = 0; cin >> n >> m >> a >> b >> c >> d; for (int i = -2; i <= 2; i++) { for (int j = -2; j <= 2; j++) { int x = c + i * n; int y = d + j * m; x -= a; y -= b; if (x < 0) x = -x; if (y < 0) y = -y; if (x + y < p) { p = x + y; q = dp[x][y]; } else if (x + y == p) { q += dp[x][y]; q %= 100000007; } } } cout << q << endl; return 0; }
[["-", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13], ["-", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13]]
1
312
#include <algorithm> #include <cstring> #include <iostream> #include <limits.h> #include <map> #include <queue> #define dprintf(s, ...) printf("%s:%d" s, __func__, __LINE__, __VA_ARGS__) using namespace std; typedef pair<int, int> P; typedef long long int ll; int r, c, a1, a2, b1, b2; int mod = 100000007; int extgcd(int a, int b, int &x, int &y) { // ax+by=gcd(a,b) int d = a; if (b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } int mod_inv(int a) { int x, y; extgcd(a, mod, x, y); return (mod + x % mod) % mod; } ll conb(int n, int r) { ll ret = 1, tmp = 1; while (r != 0) { int N = n % mod; int R = r % mod; if (N < R) return 0; for (int i = 0; i < R; i++) ret = ret * (N - i) % mod; for (int i = 0; i < R; i++) tmp = tmp * (i + 1) % mod; ret = ret * mod_inv(tmp) % mod; n /= mod; r /= mod; } return ret; } int solve() { ll ret = 0; int t = 1; int rr = min(abs(a1 - b1), r + abs(a1 - b1)); int cc = min(abs(a2 - b2), c + abs(a2 - b2)); if (r == abs(a1 - b1) * 2) t *= 2; if (c == abs(a2 - b2) * 2) t *= 2; ret = conb(rr, cc) * t % mod; return ret; } int main() { cin >> r >> c >> a1 >> a2 >> b1 >> b2; cout << solve() << endl; return 0; }
#include <algorithm> #include <cstring> #include <iostream> #include <limits.h> #include <map> #include <queue> #define dprintf(s, ...) printf("%s:%d" s, __func__, __LINE__, __VA_ARGS__) using namespace std; typedef pair<int, int> P; typedef long long int ll; int r, c, a1, a2, b1, b2; int mod = 100000007; int extgcd(int a, int b, int &x, int &y) { // ax+by=gcd(a,b) int d = a; if (b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } int mod_inv(int a) { int x, y; extgcd(a, mod, x, y); return (mod + x % mod) % mod; } ll conb(int n, int r) { ll ret = 1, tmp = 1; while (r != 0) { int N = n % mod; int R = r % mod; if (N < R) return 0; for (int i = 0; i < R; i++) ret = ret * (N - i) % mod; for (int i = 0; i < R; i++) tmp = tmp * (i + 1) % mod; ret = ret * mod_inv(tmp) % mod; n /= mod; r /= mod; } return ret; } int solve() { ll ret = 0; int t = 1; int rr = min(abs(a1 - b1), r - abs(a1 - b1)); int cc = min(abs(a2 - b2), c - abs(a2 - b2)); if (r == abs(a1 - b1) * 2) t *= 2; if (c == abs(a2 - b2) * 2) t *= 2; ret = conb(rr + cc, cc) * t % mod; return ret; } int main() { cin >> r >> c >> a1 >> a2 >> b1 >> b2; cout << solve() << endl; return 0; }
[["-", 49, 50, 51, 2, 3, 4, 0, 16, 17, 72], ["+", 49, 50, 51, 2, 3, 4, 0, 16, 17, 33], ["+", 31, 16, 31, 2, 3, 4, 0, 16, 17, 72], ["+", 31, 16, 31, 2, 3, 4, 0, 16, 12, 22]]
1
430
#include <bits/stdc++.h> #define r(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; const ll M = 100000007; ll extgcd(ll a, ll b, ll &x, ll &y) { ll d = a; if (b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } ll mod_inverse(ll a, ll m) { ll x, y; extgcd(a, m, x, y); return (m + x % m) % m; } ll combination(ll N, ll K) { ll res = 1; for (int i = 0; i < K; i++) res = (res * ((N - i) % M)) % M; for (int i = 1; i <= K; i++) res = (res * mod_inverse(i, M)) % M; return res; } int dx[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1}; int dy[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1}; int main() { int sum = 0, h, w, a1, a2, b1, b2, MIN = 1e9; cin >> w >> h >> a1 >> a2 >> b1 >> b2; r(i, 9) { int y = b1 + h * dy[i]; int x = b2 + w * dx[i]; MIN = min(MIN, abs(y - a1) + abs(x - a2)); } r(i, 9) { int y = b1 + h * dy[i]; int x = b2 + w * dx[i]; if (abs(y - a1) + abs(x - a2) == MIN) { sum += combination(abs(y - a1) + abs(x - a2), abs(y - a1)); sum %= M; } } cout << sum << endl; }
#include <bits/stdc++.h> #define r(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; const ll M = 100000007; ll extgcd(ll a, ll b, ll &x, ll &y) { ll d = a; if (b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } ll mod_inverse(ll a, ll m) { ll x, y; extgcd(a, m, x, y); return (m + x % m) % m; } ll combination(ll N, ll K) { ll res = 1; for (int i = 0; i < K; i++) res = (res * ((N - i) % M)) % M; for (int i = 1; i <= K; i++) res = (res * mod_inverse(i, M)) % M; return res; } int dx[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1}; int dy[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1}; int main() { int sum = 0, h, w, a1, a2, b1, b2, MIN = 1e9; cin >> h >> w >> a1 >> a2 >> b1 >> b2; r(i, 9) { int y = b1 + h * dy[i]; int x = b2 + w * dx[i]; MIN = min(MIN, abs(y - a1) + abs(x - a2)); } r(i, 9) { int y = b1 + h * dy[i]; int x = b2 + w * dx[i]; if (abs(y - a1) + abs(x - a2) == MIN) { sum += combination(abs(y - a1) + abs(x - a2), abs(y - a1)); sum %= M; } } cout << sum << endl; }
[["-", 31, 16, 31, 16, 31, 16, 31, 16, 12, 22], ["-", 31, 16, 31, 16, 31, 16, 31, 16, 17, 152], ["+", 31, 16, 31, 16, 31, 16, 31, 16, 17, 152], ["+", 31, 16, 31, 16, 31, 16, 31, 16, 12, 22]]
1
448
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> using namespace std; #define dump(n) cout << "# " << #n << '=' << (n) << endl #define repi(i, a, b) for (int i = int(a); i < int(b); i++) #define peri(i, a, b) for (int i = int(b); i-- > int(a);) #define rep(i, n) repi(i, 0, n) #define per(i, n) peri(i, 0, n) #define iter(c) __typeof__((c).begin()) #define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); ++i) #define all(c) (c).begin(), (c).end() #define mp make_pair typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<string> vs; typedef pair<int, int> pii; const int INFTY = 1 << 29; const double EPS = 1e-9; template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << '(' << p.first << ',' << p.second << ')'; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &a) { os << '['; rep(i, a.size()) os << (i ? " " : "") << a[i]; return os << ']'; } const int MOD = 1e8 + 7; int ncr(int n, int r) { static int memo[2001][2001]; if (memo[n][r] == 0) { if (r == 0 || r == n) memo[n][r] = 1; else memo[n][r] = (ncr(n - 1, r - 1) + ncr(n - 1, r)) % MOD; } return memo[n][r]; } int main() { for (int r, c, a1, a2, b1, b2; cin >> r >> c >> a1 >> a2 >> b1 >> b2;) { int v1 = abs(b1 - a1), v2 = r - v1; if (v1 > v2) swap(v1, v2); int h1 = abs(b2 - a2), h2 = c - h1; if (h1 > h2) swap(h1, h2); ll res = ncr(v1 + h1, v1); if (v1 == v2) (res *= res) %= MOD; if (h1 == h2) (res *= res) %= MOD; cout << res << endl; } return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> using namespace std; #define dump(n) cout << "# " << #n << '=' << (n) << endl #define repi(i, a, b) for (int i = int(a); i < int(b); i++) #define peri(i, a, b) for (int i = int(b); i-- > int(a);) #define rep(i, n) repi(i, 0, n) #define per(i, n) peri(i, 0, n) #define iter(c) __typeof__((c).begin()) #define foreach(i, c) for (iter(c) i = (c).begin(); i != (c).end(); ++i) #define all(c) (c).begin(), (c).end() #define mp make_pair typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<string> vs; typedef pair<int, int> pii; const int INFTY = 1 << 29; const double EPS = 1e-9; template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << '(' << p.first << ',' << p.second << ')'; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &a) { os << '['; rep(i, a.size()) os << (i ? " " : "") << a[i]; return os << ']'; } const int MOD = 1e8 + 7; int ncr(int n, int r) { static int memo[2001][2001]; if (memo[n][r] == 0) { if (r == 0 || r == n) memo[n][r] = 1; else memo[n][r] = (ncr(n - 1, r - 1) + ncr(n - 1, r)) % MOD; } return memo[n][r]; } int main() { for (int r, c, a1, a2, b1, b2; cin >> r >> c >> a1 >> a2 >> b1 >> b2;) { int v1 = abs(b1 - a1), v2 = r - v1; if (v1 > v2) swap(v1, v2); int h1 = abs(b2 - a2), h2 = c - h1; if (h1 > h2) swap(h1, h2); int res = ncr(v1 + h1, v1); if (v1 == v2) (res *= 2) %= MOD; if (h1 == h2) (res *= 2) %= MOD; cout << res << endl; } return 0; }
[["-", 8, 9, 0, 7, 8, 9, 0, 43, 39, 78], ["+", 8, 9, 0, 7, 8, 9, 0, 43, 39, 40], ["-", 0, 57, 64, 1, 0, 11, 31, 23, 0, 22], ["+", 64, 1, 0, 11, 31, 23, 0, 42, 0, 13]]
1
548
#include <iostream> using namespace std; int getLCM(int s, int t) { int tmp; if (s < t) { tmp = t; t = s; s = tmp; } while (s % t != 0) { tmp = s % t; s = t; t = tmp; } return t; } int main(int argc, char *argv[]) { int r, c, a1, a2, b1, b2; cin >> r >> c >> a1 >> a2 >> b1 >> b2; int hoge = 1; int x; if (a1 > b1) if (a1 - b1 < r - a1 + b1) { x = a1 - b1; } else if (a1 - b1 > r - a1 + b1) { x = r - a1 + b1; } else { x = a1 - b1; hoge *= 2; } else if (b1 - a1 < r - b1 + a1) { x = b1 - a1; } else if (b1 - a1 > r - b1 + a1) { x = r - b1 + a1; } else { x = b1 - a1; hoge *= 2; } int y; if (a2 > b2) if (a2 - b2 < c - a2 + b2) { y = a2 - b2; } else if (a2 - b2 > c - a2 + b2) { y = c - a2 + b2; } else { y = a2 - b2; hoge *= 2; } else if (b2 - a2 < c - b2 + a2) { y = b2 - a2; } else if (b2 - a2 > c - b2 + a2) { y = c - b2 + a2; } else { y = b2 - a2; hoge *= 2; } int *deno, *nume; deno = new int[x]; nume = new int[x]; for (int i = 0; i < x; i++) { nume[i] = x + y - i; deno[i] = x - i; } for (int i = 0; i < x; i++) for (int j = 0; j < x; j++) { int lcm = getLCM(nume[i], deno[j]); nume[i] /= lcm; deno[j] /= lcm; } /* for (int i = 0; i < x; i++) cout << nume[i] << endl; for (int i = 0; i < x; i++) cout << deno[i] << endl; */ long long result = 1; for (int i = 0; i < x; i++) { result *= nume[i]; if (result > 100000007) result %= 100000007; } result = result * hoge % 100000007; cout << result * hoge << endl; return 0; }
#include <iostream> using namespace std; int getLCM(int s, int t) { int tmp; if (s < t) { tmp = t; t = s; s = tmp; } while (s % t != 0) { tmp = s % t; s = t; t = tmp; } return t; } int main(int argc, char *argv[]) { int r, c, a1, a2, b1, b2; cin >> r >> c >> a1 >> a2 >> b1 >> b2; int hoge = 1; int x; if (a1 > b1) if (a1 - b1 < r - a1 + b1) { x = a1 - b1; } else if (a1 - b1 > r - a1 + b1) { x = r - a1 + b1; } else { x = a1 - b1; hoge *= 2; } else if (b1 - a1 < r - b1 + a1) { x = b1 - a1; } else if (b1 - a1 > r - b1 + a1) { x = r - b1 + a1; } else { x = b1 - a1; hoge *= 2; } int y; if (a2 > b2) if (a2 - b2 < c - a2 + b2) { y = a2 - b2; } else if (a2 - b2 > c - a2 + b2) { y = c - a2 + b2; } else { y = a2 - b2; hoge *= 2; } else if (b2 - a2 < c - b2 + a2) { y = b2 - a2; } else if (b2 - a2 > c - b2 + a2) { y = c - b2 + a2; } else { y = b2 - a2; hoge *= 2; } int *deno, *nume; deno = new int[x]; nume = new int[x]; for (int i = 0; i < x; i++) { nume[i] = x + y - i; deno[i] = x - i; } for (int i = 0; i < x; i++) for (int j = 0; j < x; j++) { int lcm = getLCM(nume[i], deno[j]); nume[i] /= lcm; deno[j] /= lcm; } /* for (int i = 0; i < x; i++) cout << nume[i] << endl; for (int i = 0; i < x; i++) cout << deno[i] << endl; */ long long result = 1; for (int i = 0; i < x; i++) { result *= nume[i]; if (result > 100000007) result %= 100000007; } result = result * hoge % 100000007; cout << result << endl; return 0; }
[["-", 0, 1, 0, 16, 31, 16, 12, 16, 17, 48], ["-", 0, 1, 0, 16, 31, 16, 12, 16, 12, 22]]
1
535
#include <cmath> #include <iostream> using namespace std; #define rep(i, n) for (int i = 0; i < int(n); ++i) const int MOD = 100000007; long long nck[1111][1111]; int main() { rep(i, 1111) nck[i][0] = 1; rep(i, 1110) rep(j, 1110) { nck[i + 1][j + 1] = (nck[i][j] + nck[i][j + 1]) % MOD; } int r, c, a1, a2, b1, b2, t = 1; cin >> r >> c >> a1 >> a2 >> b1 >> b2; if (r == abs(a1 - b1) * 2) t *= 2; if (c == abs(a2 - b2) * 2) t *= 2; int aa = min(abs(a1 - b1), r - abs(a1 - b1)); int bb = min(abs(a2 - b2), r - abs(a2 - b2)); cout << nck[aa + bb][aa] * t % MOD << endl; return 0; }
#include <cmath> #include <iostream> using namespace std; #define rep(i, n) for (int i = 0; i < int(n); ++i) const int MOD = 100000007; long long nck[1111][1111]; int main() { rep(i, 1111) nck[i][0] = 1; rep(i, 1110) rep(j, 1110) { nck[i + 1][j + 1] = (nck[i][j] + nck[i][j + 1]) % MOD; } int r, c, a1, a2, b1, b2, t = 1; cin >> r >> c >> a1 >> a2 >> b1 >> b2; if (r == abs(a1 - b1) * 2) t *= 2; if (c == abs(a2 - b2) * 2) t *= 2; int aa = min(abs(a1 - b1), r - abs(a1 - b1)); int bb = min(abs(a2 - b2), c - abs(a2 - b2)); cout << nck[aa + bb][aa] * t % MOD << endl; return 0; }
[["-", 49, 50, 51, 2, 3, 4, 0, 16, 31, 22], ["+", 49, 50, 51, 2, 3, 4, 0, 16, 31, 22]]
1
234
r, c, a1, a2, b1, b2 = gets.split.map(&:to_i) m = [(a1-b1).abs, a1+r-b1, b1+r-a1].min n = [(a2-b2).abs, a2+c-b2, b2+c-a2].min x = (1..m+n).inject(:*) / (1..m).inject(:*) / (1..n).inject(:*) x *= 2 if (a1-b1).abs * 2 == r x *= 2 if (a2-b2).abs * 2 == c p x % 100000007
r, c, a1, a2, b1, b2 = gets.split.map(&:to_i) m = [(a1-b1).abs, a1+r-b1, b1+r-a1].min n = [(a2-b2).abs, a2+c-b2, b2+c-a2].min x = (1..m+n).inject(1, :*) / (1..m).inject(1, :*) / (1..n).inject(1, :*) x *= 2 if (a1-b1).abs * 2 == r x *= 2 if (a2-b2).abs * 2 == c p x % 100000007
[["+", 12, 738, 31, 738, 31, 652, 3, 4, 0, 612], ["+", 12, 738, 31, 738, 31, 652, 3, 4, 0, 21], ["+", 12, 738, 31, 738, 12, 652, 3, 4, 0, 612], ["+", 12, 738, 31, 738, 12, 652, 3, 4, 0, 21], ["+", 0, 662, 12, 738, 12, 652, 3, 4, 0, 612], ["+", 0, 662, 12, 738, 12, 652, 3, 4, 0, 21]]
4
141
import math def comb (x,y): return factorial(x)//factorial(x-y)//factorial(y) w,h,ax,ay,bx,by=map(int,input().split()) dx=min(w-abs(ax-bx),abs(ax-bx)) dy=min(h-abs(ay-by),abs(ay-by)) ans=1 if dx*2==w:ans*=2 if dy*2==h:ans*=2 ans*=comb(dx+dy,dx) print(ans%100000007)
from math import factorial def comb (x,y): return factorial(x)//factorial(x-y)//factorial(y) w,h,ax,ay,bx,by=map(int,input().split()) dx=min(w-abs(ax-bx),abs(ax-bx)) dy=min(h-abs(ay-by),abs(ay-by)) ans=1 if dx*2==w:ans*=2 if dy*2==h:ans*=2 ans*=comb(dx+dy,dx) print(ans%100000007)
[["-", 36, 36, 36, 36, 0, 656, 0, 596, 0, 487], ["+", 36, 36, 36, 36, 0, 656, 0, 686, 0, 314], ["+", 36, 36, 36, 36, 0, 656, 0, 686, 0, 487], ["+", 36, 36, 0, 656, 0, 686, 141, 673, 0, 22]]
5
130
from math import factorial def comb (x,y): return factorial(x)//factorial(x-y)//factorial(y) w,h,ax,ay,bx,by=map(int,input().split()) dx=abs(ax-bx) dx=min(dx,w-dx) dy=abs(ay-by) dy=min(dy,h-dy) an=1 if dx*2==w:an*=2 if dy*2==h:an*=2 an*=comb(dx+dy,dx) print(an%int(1E9+7))
from math import factorial def comb (x,y): return factorial(x)//factorial(x-y)//factorial(y) w,h,ax,ay,bx,by=map(int,input().split()) dx=abs(ax-bx) dx=min(dx,w-dx) dy=abs(ay-by) dy=min(dy,h-dy) an=1 if dx*2==w:an*=2 if dy*2==h:an*=2 an*=comb(dx+dy,dx) print(an%int(1E8+7))
[["-", 0, 657, 12, 652, 3, 4, 0, 657, 31, 531], ["+", 0, 657, 12, 652, 3, 4, 0, 657, 31, 531]]
5
133
int Z(int *a, int *b) { return *a - *b; } a[999], i; main(n, j) { for (scanf("%d", &n); i < n; i++) scanf("%d", a + i); qsort(a, n, 4, Z); long long r = 1; for (i = 0; i < n && (j = a[i] - i / 4) > 0; i++) r += j; i = !printf("%lld\n", r); }
int Z(int *a, int *b) { return *b - *a; } a[999], i; main(n, j) { for (scanf("%d", &n); i < n; i++) scanf("%d", a + i); qsort(a, n, 4, Z); long long r = 1; for (i = 0; i < n && (j = a[i] - i / 4) > 0; i++) r += j; i = !printf("%lld\n", r); }
[["-", 8, 9, 0, 37, 0, 16, 31, 66, 28, 22], ["+", 8, 9, 0, 37, 0, 16, 31, 66, 28, 22], ["-", 8, 9, 0, 37, 0, 16, 12, 66, 28, 22], ["+", 8, 9, 0, 37, 0, 16, 12, 66, 28, 22]]
0
128
#include <algorithm> #include <iostream> using namespace std; int n, a, c[126]; long long s; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a; s += a; for (int i = 1; i <= 125 && a <= i; i++) c[i]++; } for (int i = 1; i <= 125; i++) s -= max(c[i] - i * 4, 0); cout << s - 1 << endl; }
#include <algorithm> #include <iostream> using namespace std; int n, a, c[126]; long long s; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> a; s += a; for (int i = 1; i <= 125 && i <= a; i++) c[i]++; } for (int i = 1; i <= 125; i++) s -= max(c[i] - i * 4, 0); cout << s + 1 << endl; return 0; }
[["-", 8, 9, 0, 7, 15, 16, 12, 16, 31, 22], ["-", 8, 9, 0, 7, 15, 16, 12, 16, 17, 19], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 19], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 12, 22], ["-", 0, 1, 0, 16, 31, 16, 12, 16, 17, 33], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 38], ["+", 0, 30, 0, 14, 8, 9, 0, 37, 0, 13]]
1
118
#include <algorithm> #include <cstdio> #include <iostream> #include <queue> #include <set> #include <string.h> #include <string> #include <unordered_map> #include <vector> #define int long long using namespace std; signed main() { int ans = 0; int a; cin >> a; vector<int> V; for (int b = 0; b < a; b++) { int c; cin >> c; V.push_back(-c); } sort(V.begin(), V.end()); for (int b = 0; b < a; b++) { int c = V[b]; ans += max(0ll, c - b / 4); } cout << ans + 1 << endl; }
#include <algorithm> #include <cstdio> #include <iostream> #include <queue> #include <set> #include <string.h> #include <string> #include <unordered_map> #include <vector> #define int long long using namespace std; signed main() { int ans = 0; int a; cin >> a; vector<int> V; for (int b = 0; b < a; b++) { int c; cin >> c; V.push_back(-c); } sort(V.begin(), V.end()); for (int b = 0; b < a; b++) { int c = -V[b]; ans += max(0ll, c - b / 4); } cout << ans + 1 << endl; }
[["+", 8, 9, 0, 43, 49, 50, 51, 91, 17, 33]]
1
140
#include <algorithm> #include <cstdio> using namespace std; int main() { int s[551], minus = 0, n; long long int res = 1; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", s + i); sort(s, s + n); for (int i = n - 1; i >= 0; i--, minus++) { res += s[i] - minus / 4; } printf("%lld\n", res); return 0; }
#include <algorithm> #include <cstdio> using namespace std; int main() { int s[551], minus = 0, n; long long int res = 1; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", s + i); sort(s, s + n); for (int i = n - 1; i >= 0; i--, minus++) { res += max(0, s[i] - minus / 4); } printf("%lld\n", res); return 0; }
[["+", 8, 9, 0, 1, 0, 11, 12, 2, 63, 22], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 24], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 13], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 25]]
1
122
n, *hs = $<.read.split($/).map(&:to_i) hs.sort!.reverse! count = 0 unfilled_dist = 0 capacity = 1 hs.each_with_index {|h, i| break if h < unfilled_dist count += h + 1 - unfilled_dist capacity -= 1 if capacity == 0 unfilled_dist += 1 capacity = 4 * unfilled_dist - i - 1 end }
n, *hs = $<.read.split($/).map(&:to_i) hs.sort!.reverse! count = 0 unfilled_dist = 0 capacity = 1 hs.each_with_index {|h, i| break if h < unfilled_dist count += h + 1 - unfilled_dist capacity -= 1 if capacity == 0 unfilled_dist += 1 capacity = 4 * unfilled_dist - i - 1 end } p count
[["+", 36, 36, 36, 36, 0, 493, 0, 652, 735, 22], ["+", 36, 36, 0, 493, 0, 652, 3, 4, 0, 22]]
4
75
a=($<.map &:to_i).sort.reverse p (1...a.size).inject(1){|s,i|s+[a[i]-(i-1)/4,0].max}
gets a=($<.map &:to_i).sort.reverse p (0...a.size).inject(1){|s,i|s+[a[i]-i/4,0].max}
[["+", 36, 36, 36, 36, 36, 36, 0, 493, 0, 22], ["-", 3, 4, 0, 652, 486, 739, 0, 475, 756, 612], ["+", 3, 4, 0, 652, 486, 739, 0, 475, 756, 612], ["-", 486, 516, 0, 738, 12, 738, 31, 739, 0, 24], ["-", 0, 738, 12, 738, 31, 739, 0, 738, 17, 33], ["-", 0, 738, 12, 738, 31, 739, 0, 738, 12, 612], ["-", 486, 516, 0, 738, 12, 738, 31, 739, 0, 25]]
4
53
#include <algorithm> #include <iostream> #include <queue> #include <set> #include <string> #include <tuple> #include <utility> #include <vector> #define REP(i, a, b) for (int i = int(a); i < int(b); i++) #ifdef _DEBUG_ #define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl #else #define dump(val) #endif using namespace std; typedef long long int ll; typedef pair<ll, ll> P; template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } const ll inf = 1LL << 60; void dijkstra(int s, vector<vector<P>> &G, vector<ll> &Cost) { int n = G.size(); Cost.assign(n, inf); Cost[s] = 0; priority_queue<P, vector<P>, greater<P>> pq; pq.emplace(0LL, s); while (pq.size()) { ll cost; int to; tie(cost, to) = pq.top(); pq.pop(); if (cost > Cost[to]) continue; for (auto p : G[to]) { ll ncost = p.first + cost; int nto = p.second; if (Cost[nto] > ncost) { Cost[nto] = ncost; pq.emplace(ncost, nto); } } } } class BIT { public: vector<ll> data; BIT(int n) { int N = 1; while (N < n) { N *= 2; } data.resize(N, 0); } void update(int pos, ll val) { pos++; for (int p = pos; p < data.size(); p += (p & -p)) { data[p] += val; } } ll query(int pos) { ll ans = 0; pos++; for (int p = pos; p > 0; p -= (p & -p)) { ans += data[p]; } return ans; } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector<vector<P>> Graph(n); REP(i, 0, m) { int a, b, c; cin >> a >> b >> c; Graph[a].push_back({c, b}); Graph[b].push_back({c, a}); } vector<P> Cost(n); { vector<ll> start, goal; dijkstra(0, Graph, start); dijkstra(n - 1, Graph, goal); REP(i, 0, n) { Cost[i] = {start[i], goal[i]}; } sort(Cost.begin(), Cost.end()); } int q; cin >> q; vector<P> F(q); REP(i, 0, q) { cin >> F[i].first >> F[i].second; } vector<int> indices(n); REP(i, 0, n) { indices[i] = i; } sort(indices.begin(), indices.end(), [&](int a, int b) { return F[a] < F[b]; }); int an = 0; // 座標圧縮 { vector<ll> val; REP(i, 0, n) { val.push_back(Cost[i].second); } REP(i, 0, q) { val.push_back(F[i].second); } sort(val.begin(), val.end()); val.erase(unique(val.begin(), val.end()), val.end()); an = val.size(); REP(i, 0, n) { Cost[i].second = lower_bound(val.begin(), val.end(), Cost[i].second) - val.begin(); } REP(i, 0, q) { F[i].second = lower_bound(val.begin(), val.end(), F[i].second) - val.begin(); } } BIT bit(an + 2); vector<int> ans(n, 0); int pos = 0; set<ll> s; REP(i, 0, n) { int v = indices[i]; while (pos < n && Cost[pos].first <= F[v].first) { bit.update(Cost[pos].second, 1); pos++; } ans[v] = pos - bit.query(F[v].second - 1); } REP(i, 0, n) { cout << ans[i] << endl; } return 0; }
#include <algorithm> #include <iostream> #include <queue> #include <set> #include <string> #include <tuple> #include <utility> #include <vector> #define REP(i, a, b) for (int i = int(a); i < int(b); i++) #ifdef _DEBUG_ #define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl #else #define dump(val) #endif using namespace std; typedef long long int ll; typedef pair<ll, ll> P; template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } const ll inf = 1LL << 60; void dijkstra(int s, vector<vector<P>> &G, vector<ll> &Cost) { int n = G.size(); Cost.assign(n, inf); Cost[s] = 0; priority_queue<P, vector<P>, greater<P>> pq; pq.emplace(0LL, s); while (pq.size()) { ll cost; int to; tie(cost, to) = pq.top(); pq.pop(); if (cost > Cost[to]) continue; for (auto p : G[to]) { ll ncost = p.first + cost; int nto = p.second; if (Cost[nto] > ncost) { Cost[nto] = ncost; pq.emplace(ncost, nto); } } } } class BIT { public: vector<ll> data; BIT(int n) { int N = 1; while (N < n) { N *= 2; } data.resize(N, 0); } void update(int pos, ll val) { pos++; for (int p = pos; p < data.size(); p += (p & -p)) { data[p] += val; } } ll query(int pos) { ll ans = 0; pos++; for (int p = pos; p > 0; p -= (p & -p)) { ans += data[p]; } return ans; } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m; cin >> n >> m; vector<vector<P>> Graph(n); REP(i, 0, m) { int a, b, c; cin >> a >> b >> c; Graph[a].push_back({c, b}); Graph[b].push_back({c, a}); } vector<P> Cost(n); { vector<ll> start, goal; dijkstra(0, Graph, start); dijkstra(n - 1, Graph, goal); REP(i, 0, n) { Cost[i] = {start[i], goal[i]}; } sort(Cost.begin(), Cost.end()); } int q; cin >> q; vector<P> F(q); REP(i, 0, q) { cin >> F[i].first >> F[i].second; } vector<int> indices(q); REP(i, 0, q) { indices[i] = i; } sort(indices.begin(), indices.end(), [&](int a, int b) { return F[a] < F[b]; }); int an = 0; // 座標圧縮 { vector<ll> val; REP(i, 0, n) { val.push_back(Cost[i].second); } REP(i, 0, q) { val.push_back(F[i].second); } sort(val.begin(), val.end()); val.erase(unique(val.begin(), val.end()), val.end()); an = val.size(); REP(i, 0, n) { Cost[i].second = lower_bound(val.begin(), val.end(), Cost[i].second) - val.begin(); } REP(i, 0, q) { F[i].second = lower_bound(val.begin(), val.end(), F[i].second) - val.begin(); } } BIT bit(an + 2); vector<int> ans(q, 0); int pos = 0; set<ll> s; REP(i, 0, q) { int v = indices[i]; while (pos < n && Cost[pos].first <= F[v].first) { bit.update(Cost[pos].second, 1); pos++; } ans[v] = pos - bit.query(F[v].second - 1); } REP(i, 0, q) { cout << ans[i] << endl; } return 0; }
[["-", 0, 43, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 0, 43, 49, 53, 54, 55, 0, 56, 39, 78], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["-", 8, 9, 0, 43, 49, 50, 51, 4, 0, 22], ["+", 8, 9, 0, 43, 49, 50, 51, 4, 0, 22]]
1
1,076
#include <algorithm> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> #define REP(i, k, n) for (int i = k; i < n; i++) #define rep(i, n) for (int i = 0; i < n; i++) #define INF 1LL << 61 #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef pair<int, int> P; struct edge { int from, to; ll cost; edge(int t, ll c) : to(t), cost(c) {} edge(int f, int t, ll c) : from(f), to(t), cost(c) {} bool operator<(const edge &e) const { return cost < e.cost; } }; vector<edge> G[100005]; ll d[100005], d2[100005]; void dijkstra(int s, int n) { priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> que; fill(d, d + n, INF); d[s] = 0; que.push(P(0, s)); while (que.size()) { P p = que.top(); que.pop(); int v = p.second; if (d[v] < p.first) continue; rep(i, G[v].size()) { edge e = G[v][i]; if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; que.push(P(d[e.to], e.to)); } } } } struct BIT { vector<int> bit; BIT(int n) : bit(n + 1) {} int sum(int i) { int s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } void add(int i, int x) { while (i <= bit.size()) { bit[i] += x; i += i & -i; } } }; int main() { int n, m; cin >> n >> m; rep(i, m) { ll a, b, c; cin >> a >> b >> c; G[a].push_back(edge(b, c)); G[b].push_back(edge(a, c)); } dijkstra(n - 1, n); memset(d2, 0, sizeof(d2)); rep(i, n) { d2[i] = d[i]; } dijkstra(0, n); vector<ll> d3(n); vector<pair<ll, int>> D, D2; rep(i, n) { d3[i] = d[i]; D.push_back(mp(d[i], i)); D2.push_back(mp(d2[i], i)); } sort(d3.begin(), d3.end()); sort(D.begin(), D.end()); sort(D2.begin(), D2.end()); // cout << "-------- D1:" << endl; // rep(i, n) { // cout << "i:" << i << "| " << D[i].first << " " << D[i].second << endl; // } // // cout << "-------- D2:" << endl; // rep(i, n) { // cout << "i:" << i << "| " << D2[i].first << " " << D2[i].second << endl; // } map<int, int> ma; rep(i, n) { ma[D[i].second] = i; } // cout << "-------- map D1:" << endl; // rep(i, n) { // cout << i << " " << ma[i] << endl; // } int q; cin >> q; vector<pair<pair<ll, ll>, int>> query(q); rep(i, q) { ll s, g; cin >> s >> g; query[i] = mp(mp(g, s), i); } sort(query.begin(), query.end()); // // cout << "------ query:" << endl; // rep(i, q) { // cout << "i:" << i << "| "; // cout << query[i].first.first << " " << query[i].first.second << " " << // query[i].second << endl; // } BIT bit(n + 5); vector<P> ans; int start = 0; rep(i, q) { ll s = query[i].first.second; ll g = query[i].first.first; int id = query[i].second; for (; start < n; start++) { if (g > D2[start].first) { int k = ma[D2[start].second]; bit.add(k + 1, 1); continue; } else break; } vector<ll>::iterator ite = upper_bound(d3.begin(), d3.end(), s); int k = ite - d3.begin() - 1; if (k < 0) { ans.push_back(mp(id, 0)); } else { int res = k + 1; // // cout << "---------------- i : " << i << " id:" << id << endl; // cout << "query:" << s << " " << g << endl; // cout << "k:" << k << endl; // cout << "ma[k]:" << ma[k] << endl; // cout << "res:" << res << endl; // cout << "bit:" << bit.sum(ma[k] + 1) << endl; // cout << "start:" << start << endl; res -= bit.sum(ma[k] + 1); // cout << "push:" << res << endl; ans.push_back(mp(id, res)); } } sort(ans.begin(), ans.end()); rep(i, ans.size()) { cout << ans[i].second << endl; } return 0; }
#include <algorithm> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> #define REP(i, k, n) for (int i = k; i < n; i++) #define rep(i, n) for (int i = 0; i < n; i++) #define INF 1LL << 61 #define pb push_back #define mp make_pair using namespace std; typedef long long ll; typedef pair<int, int> P; struct edge { int from, to; ll cost; edge(int t, ll c) : to(t), cost(c) {} edge(int f, int t, ll c) : from(f), to(t), cost(c) {} bool operator<(const edge &e) const { return cost < e.cost; } }; vector<edge> G[100005]; ll d[100005], d2[100005]; void dijkstra(int s, int n) { priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> que; fill(d, d + n, INF); d[s] = 0; que.push(P(0, s)); while (que.size()) { P p = que.top(); que.pop(); int v = p.second; if (d[v] < p.first) continue; rep(i, G[v].size()) { edge e = G[v][i]; if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; que.push(P(d[e.to], e.to)); } } } } struct BIT { vector<int> bit; BIT(int n) : bit(n + 1) {} int sum(int i) { int s = 0; while (i > 0) { s += bit[i]; i -= i & -i; } return s; } void add(int i, int x) { while (i <= bit.size()) { bit[i] += x; i += i & -i; } } }; int main() { int n, m; cin >> n >> m; rep(i, m) { ll a, b, c; cin >> a >> b >> c; G[a].push_back(edge(b, c)); G[b].push_back(edge(a, c)); } dijkstra(n - 1, n); memset(d2, 0, sizeof(d2)); rep(i, n) { d2[i] = d[i]; } dijkstra(0, n); vector<ll> d3(n); vector<pair<ll, int>> D, D2; rep(i, n) { d3[i] = d[i]; D.push_back(mp(d[i], i)); D2.push_back(mp(d2[i], i)); } sort(d3.begin(), d3.end()); sort(D.begin(), D.end()); sort(D2.begin(), D2.end()); map<int, int> ma; rep(i, n) { ma[D[i].second] = i; } int q; cin >> q; vector<pair<pair<ll, ll>, int>> query(q); rep(i, q) { ll s, g; cin >> s >> g; query[i] = mp(mp(g, s), i); } sort(query.begin(), query.end()); BIT bit(n + 5); vector<P> ans; int start = 0; rep(i, q) { ll s = query[i].first.second; ll g = query[i].first.first; int id = query[i].second; for (; start < n; start++) { if (g > D2[start].first) { int k = ma[D2[start].second]; bit.add(k + 1, 1); continue; } else break; } vector<ll>::iterator ite = upper_bound(d3.begin(), d3.end(), s); int k = ite - d3.begin() - 1; if (k < 0) { ans.push_back(mp(id, 0)); } else { int res = k + 1; res -= bit.sum(k + 1); ans.push_back(mp(id, res)); } } sort(ans.begin(), ans.end()); rep(i, ans.size()) { cout << ans[i].second << endl; } return 0; }
[["-", 12, 2, 3, 4, 0, 16, 31, 69, 28, 22], ["-", 3, 4, 0, 16, 31, 69, 341, 342, 0, 70], ["-", 3, 4, 0, 16, 31, 69, 341, 342, 0, 73]]
1
1,078
#include <iostream> #include <queue> #include <array> #include <map> using namespace std; const int kLose = -1; const int kBack = -2; const double kDice = 1.0 / 6.0; void Solve(double prob[102][101], int board[101], int goal, int T) { prob[0][0] = 1.0; for (int t = 0; t < T; t++) { for (int i = 0; i < goal; i++) { for (int n = 1; n <= 6; n++) { int npos = (i + n <= goal) ? i + n : 2 * goal - (i + n); if (board[npos] == kLose) { prob[t + 2][npos] += prob[t][i] * kDice; } else if (board[npos] == kBack) { prob[t + 1][0] += prob[t][i] * kDice; } else { prob[t + 1][npos] += prob[t][i] * kDice; } } } } } int main() { cin.tie(0); ios::sync_with_stdio(false); while (1) { double prob[102][101] = {{0.0}}; int board[101]; int N, T, L, B; cin >> N >> T >> L >> B; if (N == 0) { return 0; } for (int i = 0; i < L; i++) { int n; cin >> n; board[n] = kLose; } for (int i = 0; i < B; i++) { int n; cin >> n; board[n] = kBack; } Solve(prob, board, N, T); double sum = 0.0; for (int t = 1; t <= T; t++) { sum += prob[t][N]; } printf("%.6f\n", sum); } }
#include <iostream> #include <queue> #include <array> #include <map> using namespace std; const int kLose = -1; const int kBack = -2; const double kDice = 1.0 / 6.0; void Solve(double prob[102][101], int board[101], int goal, int T) { prob[0][0] = 1.0; for (int t = 0; t < T; t++) { for (int i = 0; i < goal; i++) { for (int n = 1; n <= 6; n++) { int npos = (i + n <= goal) ? i + n : 2 * goal - (i + n); if (board[npos] == kLose) { prob[t + 2][npos] += prob[t][i] * kDice; } else if (board[npos] == kBack) { prob[t + 1][0] += prob[t][i] * kDice; } else { prob[t + 1][npos] += prob[t][i] * kDice; } } } } } int main() { cin.tie(0); ios::sync_with_stdio(false); while (1) { double prob[102][101] = {{0.0}}; int board[101] = {0}; int N, T, L, B; cin >> N >> T >> L >> B; if (N == 0) { return 0; } for (int i = 0; i < L; i++) { int n; cin >> n; board[n] = kLose; } for (int i = 0; i < B; i++) { int n; cin >> n; board[n] = kBack; } Solve(prob, board, N, T); double sum = 0.0; for (int t = 1; t <= T; t++) { sum += prob[t][N]; } printf("%.6f\n", sum); } }
[["+", 0, 52, 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, 13], ["+", 8, 9, 0, 43, 49, 50, 51, 83, 0, 46]]
1
416
#include "bits/stdc++.h" using namespace std; //#define int int64_t #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0, a1, a2, a3, x, ...) x #define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal) #define REP2(i, s, n) REP1(i, s, < signed(n), ++) #define REP3(i, n) REP2(i, 0, n) #define rep(...) CHOOSE((__VA_ARGS__, REP1, REP2, REP3))(__VA_ARGS__) #define all(c) begin(c), end(c) #define maxup(ans, x) (ans = (ans < x ? x : ans)) #define minup(ans, x) (ans = (ans > x ? x : ans)) #define breakif(cond) \ if (cond) \ break; \ else template <typename T> inline void input(vector<T> &v) { for (auto &x : v) cin >> x; } using VV = vector<vector<int>>; using V = vector<int>; using P = pair<int, int>; using IP = pair<int, P>; const int INF = 1 << 29; signed main() { int n; while (cin >> n) { int t, l, b; cin >> t >> l >> b; vector<int> stage(n + 1); rep(i, l) { int lose; cin >> lose; stage[lose] = 1; } rep(i, l) { int back; cin >> back; stage[back] = 2; } vector<vector<double>> dp(t + 1, vector<double>(n + 1)); dp[0][0] = 1; rep(i, t) rep(j, n) rep(d, 6) { int next = j + d + 1; if (next > n) next = n - (next % n); double val = dp[i][j] * (1. / 6.); if (stage[next] == 1 && i + 2 <= t) { dp[i + 2][next] += val; } else if (stage[next] == 2) { dp[i + 1][0] += val; } else { dp[i + 1][next] += val; } } double ans = 0; rep(i, t + 1) ans += dp[i][n]; printf("%.8f\n", ans); } }
#include "bits/stdc++.h" using namespace std; //#define int int64_t #define CHOOSE(a) CHOOSE2 a #define CHOOSE2(a0, a1, a2, a3, x, ...) x #define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal) #define REP2(i, s, n) REP1(i, s, < signed(n), ++) #define REP3(i, n) REP2(i, 0, n) #define rep(...) CHOOSE((__VA_ARGS__, REP1, REP2, REP3))(__VA_ARGS__) #define all(c) begin(c), end(c) #define maxup(ans, x) (ans = (ans < x ? x : ans)) #define minup(ans, x) (ans = (ans > x ? x : ans)) #define breakif(cond) \ if (cond) \ break; \ else template <typename T> inline void input(vector<T> &v) { for (auto &x : v) cin >> x; } using VV = vector<vector<int>>; using V = vector<int>; using P = pair<int, int>; using IP = pair<int, P>; const int INF = 1 << 29; signed main() { int n; while (cin >> n && n) { int t, l, b; cin >> t >> l >> b; vector<int> stage(n + 1); rep(i, l) { int lose; cin >> lose; stage[lose] = 1; } rep(i, b) { int back; cin >> back; stage[back] = 2; } vector<vector<double>> dp(t + 1, vector<double>(n + 1)); dp[0][0] = 1; rep(i, t) rep(j, n) rep(d, 6) { int next = j + d + 1; if (next > n) next = n - (next % n); double val = dp[i][j] * (1. / 6.); if (stage[next] == 1 && i + 2 <= t) { dp[i + 2][next] += val; } else if (stage[next] == 2) { dp[i + 1][0] += val; } else { dp[i + 1][next] += val; } } double ans = 0; rep(i, t + 1) ans += dp[i][n]; printf("%.8f\n", ans); } }
[["+", 8, 9, 0, 52, 15, 339, 51, 16, 17, 98], ["+", 8, 9, 0, 52, 15, 339, 51, 16, 12, 22], ["-", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78]]
1
460
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> P; typedef pair<ll, P> P1; #define fr first #define sc second #define mp make_pair #define pb push_back #define rep(i, x) for (int i = 0; i < x; i++) #define rep1(i, x) for (int i = 1; i <= x; i++) #define rrep(i, x) for (int i = x - 1; i >= 0; i--) #define rrep1(i, x) for (int i = x; i > 0; i--) #define sor(v) sort(v.begin(), v.end()) #define rev(s) reverse(s.begin(), s.end()) #define lb(vec, a) lower_bound(vec.begin(), vec.end(), a) #define ub(vec, a) upper_bound(vec.begin(), vec.end(), a) #define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end()) #define mp1(a, b, c) P1(a, P(b, c)) const int INF = 1000000000; const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}}; int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } vector<P> dir[1002][1002]; int f(int x, int y, int dx, int dy) { int ret = 0; rep(i, dir[x][y].size()) { P p = dir[x][y][i]; int t = (p.fr - x) * dx + (p.sc - y) * dy; if (t > 0) ret |= 1; else if (t == 0) ret |= 3; else ret |= 2; } return ret; } ld cul_dist(ld x1, ld y1, ld x2, ld y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } static int n; static int xs, ys, xg, yg; static int cnt[1002][1002]; static vector<P> G[1002][1002]; static bool used[1002][1002]; static ld dist[1002][1002]; static P pre[1002][1002]; priority_queue<pair<ld, P>, vector<pair<ld, P>>, greater<pair<ld, P>>> que; int main() { while (1) { static int x1[202], y1[202], x2[202], y2[202]; scanf("%d", &n); if (n == 0) break; scanf("%d%d%d%d", &xs, &ys, &xg, &yg); rep(i, n) { scanf("%d%d%d%d", &x1[i], &y1[i], &x2[i], &y2[i]); } rep(i, 1002) rep(j, 1002) cnt[i][j] = 0; rep(i, n) { if (x1[i] > x2[i] || (x1[i] == x2[i] && y1[i] > y2[i])) { swap(x1[i], x2[i]); swap(y1[i], y2[i]); } cnt[x1[i]][y1[i]]++; cnt[x2[i]][y2[i]]++; } rep(i, n) { int dx = x2[i] - x1[i]; int dy = y2[i] - y1[i]; int g = gcd(abs(dx), abs(dy)); dx /= g; dy /= g; int locx = x1[i] + dx, locy = y1[i] + dy; while (!(locx == x2[i] && locy == y2[i])) { cnt[locx][locy]++; locx += dx; locy += dy; } } rep(i, 1002) rep(j, 1002) dir[i][j].clear(); rep(i, n) { if (cnt[x1[i]][y1[i]] == 1) { dir[x2[i]][y2[i]].pb(P(x1[i], y1[i])); } else if (cnt[x2[i]][y2[i]] == 1) { dir[x1[i]][y1[i]].pb(P(x2[i], y2[i])); } } rep(i, 1002) rep(j, 1002) G[i][j].clear(); rep(i, n) { if (cnt[x1[i]][y1[i]] == 1 || cnt[x2[i]][y2[i]] == 1) continue; int dx = x2[i] - x1[i]; int dy = y2[i] - y1[i]; int g = gcd(abs(dx), abs(dy)); dx /= g; dy /= g; int prex1 = -1, prey1 = -1; int prex2 = -1, prey2 = -1; int locx = x1[i], locy = y1[i]; while (locx <= x2[i] && !(dx == 0 && locy > y2[i])) { if (cnt[locx][locy] >= 1) { int t = f(locx, locy, dx, dy); if ((t & 1) == 0) { if (prex1 != -1) G[prex1][prey1].pb(P(locx, locy)); prex1 = locx; prey1 = locy; } else { prex1 = -1; prey1 = -1; } if ((t & 2) == 0) { if (prex2 != -1) G[locx][locy].pb(P(prex2, prey2)); prex2 = locx; prey2 = locy; } else { prex2 = -1; prey2 = -1; } } locx += dx; locy += dy; } } rep(i, 1002) rep(j, 1002) { used[i][j] = false; dist[i][j] = (ld)INF; pre[i][j] = P(-1, -1); } dist[xs][ys] = 0.0; que.push(pair<ld, P>(0.0, P(xs, ys))); while (!que.empty()) { pair<ld, P> p = que.top(); que.pop(); if (used[p.sc.fr][p.sc.sc]) continue; used[p.sc.fr][p.sc.sc] = true; rep(i, G[p.sc.fr][p.sc.sc].size()) { P to = G[p.sc.fr][p.sc.sc][i]; if (dist[to.fr][to.sc] > dist[p.sc.fr][p.sc.sc] + cul_dist(p.sc.fr, p.sc.sc, to.fr, to.sc)) { dist[to.fr][to.sc] = dist[p.sc.fr][p.sc.sc] + cul_dist(p.sc.fr, p.sc.sc, to.fr, to.sc); pre[to.fr][to.sc] = p.sc; que.push(pair<ld, P>(dist[to.fr][to.sc], to)); } } } if (pre[xg][yg].fr == -1) cout << -1 << endl; else { vector<P> ans; P loc = P(xg, yg); ans.pb(loc); while (loc != P(xs, ys)) { loc = pre[loc.fr][loc.sc]; ans.pb(loc); } rrep(i, ans.size()) { if (!(cnt[ans[i].fr][ans[i].sc] - dir[ans[i].fr][ans[i].sc].size() == 1)) printf("%d %d\n", ans[i].fr, ans[i].sc); } puts("0"); } } }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef double ld; typedef pair<short, short> P; typedef pair<ll, P> P1; #define fr first #define sc second #define mp make_pair #define pb push_back #define rep(i, x) for (int i = 0; i < x; i++) #define rep1(i, x) for (int i = 1; i <= x; i++) #define rrep(i, x) for (int i = x - 1; i >= 0; i--) #define rrep1(i, x) for (int i = x; i > 0; i--) #define sor(v) sort(v.begin(), v.end()) #define rev(s) reverse(s.begin(), s.end()) #define lb(vec, a) lower_bound(vec.begin(), vec.end(), a) #define ub(vec, a) upper_bound(vec.begin(), vec.end(), a) #define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end()) #define mp1(a, b, c) P1(a, P(b, c)) const int INF = 1000000000; const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}}; const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}}; int gcd(int x, int y) { if (y == 0) return x; return gcd(y, x % y); } vector<P> dir[1002][1002]; int f(int x, int y, int dx, int dy) { int ret = 0; rep(i, dir[x][y].size()) { P p = dir[x][y][i]; int t = (p.fr - x) * dx + (p.sc - y) * dy; if (t > 0) ret |= 1; else if (t == 0) ret |= 3; else ret |= 2; } return ret; } ld cul_dist(ld x1, ld y1, ld x2, ld y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } static int n; static int xs, ys, xg, yg; static short cnt[1002][1002]; static vector<P> G[1002][1002]; static bool used[1002][1002]; static double dist[1002][1002]; static P pre[1002][1002]; priority_queue<pair<ld, P>, vector<pair<ld, P>>, greater<pair<ld, P>>> que; int main() { while (1) { static int x1[202], y1[202], x2[202], y2[202]; scanf("%d", &n); if (n == 0) break; scanf("%d%d%d%d", &xs, &ys, &xg, &yg); rep(i, n) { scanf("%d%d%d%d", &x1[i], &y1[i], &x2[i], &y2[i]); } rep(i, 1002) rep(j, 1002) cnt[i][j] = 0; rep(i, n) { if (x1[i] > x2[i] || (x1[i] == x2[i] && y1[i] > y2[i])) { swap(x1[i], x2[i]); swap(y1[i], y2[i]); } cnt[x1[i]][y1[i]]++; cnt[x2[i]][y2[i]]++; } rep(i, n) { int dx = x2[i] - x1[i]; int dy = y2[i] - y1[i]; int g = gcd(abs(dx), abs(dy)); dx /= g; dy /= g; int locx = x1[i] + dx, locy = y1[i] + dy; while (!(locx == x2[i] && locy == y2[i])) { cnt[locx][locy]++; locx += dx; locy += dy; } } rep(i, 1002) rep(j, 1002) dir[i][j].clear(); rep(i, n) { if (cnt[x1[i]][y1[i]] == 1) { dir[x2[i]][y2[i]].pb(P(x1[i], y1[i])); } else if (cnt[x2[i]][y2[i]] == 1) { dir[x1[i]][y1[i]].pb(P(x2[i], y2[i])); } } rep(i, 1002) rep(j, 1002) G[i][j].clear(); rep(i, n) { if (cnt[x1[i]][y1[i]] == 1 || cnt[x2[i]][y2[i]] == 1) continue; int dx = x2[i] - x1[i]; int dy = y2[i] - y1[i]; int g = gcd(abs(dx), abs(dy)); dx /= g; dy /= g; int prex1 = -1, prey1 = -1; int prex2 = -1, prey2 = -1; int locx = x1[i], locy = y1[i]; while (locx <= x2[i] && !(dx == 0 && locy > y2[i])) { if (cnt[locx][locy] >= 1) { int t = f(locx, locy, dx, dy); if ((t & 1) == 0) { if (prex1 != -1) G[prex1][prey1].pb(P(locx, locy)); prex1 = locx; prey1 = locy; } else { prex1 = -1; prey1 = -1; } if ((t & 2) == 0) { if (prex2 != -1) G[locx][locy].pb(P(prex2, prey2)); prex2 = locx; prey2 = locy; } else { prex2 = -1; prey2 = -1; } } locx += dx; locy += dy; } } rep(i, 1002) rep(j, 1002) { used[i][j] = false; dist[i][j] = (ld)INF; pre[i][j] = P(-1, -1); } dist[xs][ys] = 0.0; que.push(pair<ld, P>(0.0, P(xs, ys))); while (!que.empty()) { pair<ld, P> p = que.top(); que.pop(); if (used[p.sc.fr][p.sc.sc]) continue; used[p.sc.fr][p.sc.sc] = true; rep(i, G[p.sc.fr][p.sc.sc].size()) { P to = G[p.sc.fr][p.sc.sc][i]; if (dist[to.fr][to.sc] > dist[p.sc.fr][p.sc.sc] + cul_dist(p.sc.fr, p.sc.sc, to.fr, to.sc)) { dist[to.fr][to.sc] = dist[p.sc.fr][p.sc.sc] + cul_dist(p.sc.fr, p.sc.sc, to.fr, to.sc); pre[to.fr][to.sc] = p.sc; que.push(pair<ld, P>(dist[to.fr][to.sc], to)); } } } if (pre[xg][yg].fr == -1) cout << -1 << endl; else { vector<P> ans; P loc = P(xg, yg); ans.pb(loc); while (loc != P(xs, ys)) { loc = pre[loc.fr][loc.sc]; ans.pb(loc); } rrep(i, ans.size()) { if (!(cnt[ans[i].fr][ans[i].sc] - dir[ans[i].fr][ans[i].sc].size() == 1)) printf("%d %d\n", ans[i].fr, ans[i].sc); } puts("0"); } } }
[["-", 36, 36, 0, 30, 0, 134, 39, 86, 0, 96], ["-", 0, 134, 39, 344, 3, 347, 0, 77, 39, 40], ["+", 39, 344, 3, 347, 0, 77, 39, 86, 0, 133], ["-", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40], ["+", 36, 36, 0, 30, 0, 43, 39, 86, 0, 133], ["-", 36, 36, 36, 36, 0, 30, 0, 43, 39, 78], ["+", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40]]
1
1,863
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; const ll LINF = 1e18; template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } int main(void) { cin.tie(0); ios_base::sync_with_stdio(false); ll n, t; cin >> n >> t; vector<ll> h(n); for (auto &in : h) cin >> in; ll startt = 0, waitt = 0; for (int i = 0; i < n; i++) { waitt = max(waitt, h[i]); ll t1 = (t - startt) / waitt; ll t2 = (t - startt) % waitt; cout << (t1 + (t2 >= h[i]) + 1) << endl; startt += h[i]; } return 0; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int INF = 1e9; const ll LINF = 1e18; template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } int main(void) { cin.tie(0); ios_base::sync_with_stdio(false); ll n, t; cin >> n >> t; vector<ll> h(n); for (auto &in : h) cin >> in; ll startt = 0, waitt = 0; for (int i = 0; i < n; i++) { waitt = max(waitt, h[i]); ll t1 = (t - startt) / waitt; ll t2 = (t - startt) % waitt; cout << max(1LL, (t1 + (t2 >= h[i]) + 1)) << endl; startt += h[i]; } return 0; }
[["+", 0, 1, 0, 16, 31, 16, 12, 2, 63, 22], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 13], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 21], ["+", 31, 16, 12, 2, 3, 4, 0, 23, 0, 24], ["+", 31, 16, 12, 2, 3, 4, 0, 23, 0, 25]]
1
347
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <thread> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef pair<ll, ll> pll; typedef pair<int, int> pi; typedef pair<double, double> pd; typedef pair<double, ll> pdl; #define F first #define S second const ll E = 1e18 + 7; const ll MOD = 1000000007; int main() { ll n, t; cin >> n >> t; vector<ll> a(n); ll sum = 0; ll mx = 0; for (auto &I : a) { cin >> I; mx = max(mx, I); sum += I; cout << (t - sum + 2 * mx) / mx << endl; } return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <thread> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef pair<ll, ll> pll; typedef pair<int, int> pi; typedef pair<double, double> pd; typedef pair<double, ll> pdl; #define F first #define S second const ll E = 1e18 + 7; const ll MOD = 1000000007; int main() { ll n, t; cin >> n >> t; vector<ll> a(n); ll sum = 0; ll mx = 0; for (auto &I : a) { cin >> I; mx = max(mx, I); sum += I; cout << max((t - sum + 2 * mx) / mx, 1LL) << endl; } return 0; }
[["+", 0, 1, 0, 16, 31, 16, 12, 2, 63, 22], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 24], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 21], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 13], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 25]]
1
205
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <string> #include <vector> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < (n); i++) #define INF ((long long)1e18) #define MOD ((int)1e9 + 7) #define endl "\n" #define yn(f) ((f) ? "Yes" : "No") #define YN(f) ((f) ? "YES" : "NO") #define MAX signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); int n, t; int sum = 0, speed = 0; vector<int> h; vector<pair<int, int>> ans; cin >> n >> t; h.resize(n); for (int i = 0; i < n; i++) { cin >> h[i]; } for (int i = 0; i < n; i++) { pair<int, int> temp; if (sum >= t) { temp.first = 1; temp.second = 1; } // cout<<"sum ->"<<sum<<" sp -> "<<speed<<endl; if (speed <= h[i]) { temp.first = (t - sum) / h[i] + 1; temp.second = ((t - sum) / h[i]) * h[i] + sum; speed = h[i]; } else { // cout<<t<<" - "<<ans[i-1].second<<" "<<h[i]<<yn(t - ans[i-1].second < // h[i])<<endl; if (t - ans[i - 1].second < h[i]) { temp.first = ans[i - 1].first - 1; temp.second = ans[i - 1].second - speed + h[i]; } else { temp.first = ans[i - 1].first; temp.second = ans[i - 1].second + h[i]; } } ans.push_back(temp); sum += h[i]; } for (int i = 0; i < n; i++) { // cout<<ans[i].first<<" "<<ans[i].second<<endl; cout << ans[i].first << endl; } return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <string> #include <vector> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < (n); i++) #define INF ((long long)1e18) #define MOD ((int)1e9 + 7) #define endl "\n" #define yn(f) ((f) ? "Yes" : "No") #define YN(f) ((f) ? "YES" : "NO") #define MAX signed main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); int n, t; int sum = 0, speed = 0; vector<int> h; vector<pair<int, int>> ans; cin >> n >> t; h.resize(n); for (int i = 0; i < n; i++) { cin >> h[i]; } for (int i = 0; i < n; i++) { pair<int, int> temp; if (sum >= t) { temp.first = 1; temp.second = 1; } else { // cout<<"sum ->"<<sum<<" sp -> "<<speed<<endl; if (speed <= h[i]) { temp.first = (t - sum) / h[i] + 1; temp.second = ((t - sum) / h[i]) * h[i] + sum; speed = h[i]; } else { // cout<<t<<" - "<<ans[i-1].second<<" "<<h[i]<<yn(t - ans[i-1].second < // h[i])<<endl; if (t - ans[i - 1].second < h[i]) { temp.first = ans[i - 1].first - 1; temp.second = ans[i - 1].second - speed + h[i]; } else { temp.first = ans[i - 1].first; temp.second = ans[i - 1].second + h[i]; } } } ans.push_back(temp); sum += h[i]; } for (int i = 0; i < n; i++) { // cout<<ans[i].first<<" "<<ans[i].second<<endl; cout << ans[i].first << endl; } return 0; }
[["+", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 45], ["+", 0, 9, 0, 57, 75, 76, 0, 9, 0, 46]]
1
389
#include <algorithm> #include <cassert> #include <cinttypes> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef int64_t ll; typedef uint64_t ull; typedef pair<ll, ll> P; inline P operator+(const P &p1, const P &p2) { return P(p1.first + p2.first, p1.second + p2.second); } int n, T; ll sum[100001]; vector<int> a, b, t; int main() { cin.tie(0), cout.tie(0); ios::sync_with_stdio(false); cin >> n >> T; a.resize(n); b.resize(n); t.resize(n); for (int i = 0; i < n; i++) { cin >> a[i]; if (i) b[i] = max(a[i], b[i - 1]); else b[i] = a[i]; if (i) t[i] = t[i - 1] - a[i]; else t[i] = T - a[0]; } for (int i = 0; i < n; ++i) { if (t[i] <= 0) cout << 1 << endl; else cout << 2 + t[i] / b[i] << endl; } return 0; }
#include <algorithm> #include <cassert> #include <cinttypes> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef int64_t ll; typedef uint64_t ull; typedef pair<ll, ll> P; inline P operator+(const P &p1, const P &p2) { return P(p1.first + p2.first, p1.second + p2.second); } int n, T; ll sum[100001]; vector<ll> a, b, t; int main() { cin.tie(0), cout.tie(0); ios::sync_with_stdio(false); cin >> n >> T; a.resize(n); b.resize(n); t.resize(n); for (int i = 0; i < n; i++) { cin >> a[i]; if (i) b[i] = max(a[i], b[i - 1]); else b[i] = a[i]; if (i) t[i] = t[i - 1] - a[i]; else t[i] = T - a[0]; } for (int i = 0; i < n; ++i) { if (t[i] < 0) cout << 1 << endl; else cout << 2 + t[i] / b[i] << endl; } return 0; }
[["-", 0, 43, 39, 344, 3, 347, 0, 77, 39, 40], ["+", 0, 43, 39, 344, 3, 347, 0, 77, 39, 78], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]]
1
306
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; using D = double; const D PI = acos(D(-1)), EPS = 1e-10; struct Pt2 { D x, y; Pt2() {} Pt2(D _x, D _y) : x(_x), y(_y) {} Pt2 operator+(const Pt2 &r) const { return Pt2(x + r.x, y + r.y); } Pt2 operator-(const Pt2 &r) const { return Pt2(x - r.x, y - r.y); } Pt2 operator*(const Pt2 &r) const { return Pt2(x * r.x - y * r.y, x * r.y + y * r.x); } Pt2 &operator+=(const Pt2 &r) { return *this = *this + r; } Pt2 &operator-=(const Pt2 &r) { return *this = *this - r; } Pt2 &operator*=(const Pt2 &r) { return *this = *this * r; } Pt2 operator-() const { return Pt2(-x, -y); } D abs() const { return sqrt(x * x + y * y); } D rabs() const { return max(x, y); } // robust abs D arg() const { return atan2(y, x); } pair<D, D> to_pair() const { return make_pair(x, y); } static Pt2 polar(D le, D th) { return Pt2(le * cos(th), le * sin(th)); } }; template <class T> ostream &operator<<(ostream &os, const Pt2 &p) { os << "(" << p.x << ", " << p.y << ")"; return os; } using P = Pt2; int sgn(D a) { if (abs(a) <= EPS) return 0; return (a < 0) ? -1 : 1; } // relative sign int rsgn(D a, D f) { if (abs(a) <= f * EPS) return 0; return (a < 0) ? -1 : 1; } bool near(P a, P b) { return !sgn((a - b).abs()); } bool lessP(P l, P r) { if (sgn(r.x - l.x)) return l.x < r.x; if (sgn(r.y - l.y)) return l.y < r.y; return false; } D cross(P a, P b) { return a.x * b.y - a.y * b.x; } D dot(P a, P b) { return a.x * b.x + a.y * b.y; } // -2, -1, 0, 1, 2 : front, clock, on, cclock, back int ccw(P b, P c) { int s = rsgn(cross(b, c), b.rabs()); if (s) return s; if (!sgn(c.rabs()) || !sgn((c - b).rabs())) return 0; if (dot(b, c) < 0) return 2; if (dot(-b, c - b) < 0) return -2; return 0; } int ccw(P a, P b, P c) { return ccw(b - a, c - a); } using Pol = V<P>; Pol convex_up(const Pol &p, int l, int r, int e1 = -1, int e2 = -1) { Pol up; for (int i = l; i <= r; i++) { if (i == e1 || i == e2) continue; P d = p[i]; while (up.size() > 1 && ccw(up[up.size() - 2], up[up.size() - 1], d) == 1) up.pop_back(); up.push_back(d); } return up; } Pol convex_down(const Pol &p, int l, int r, int e1 = -1, int e2 = -1) { Pol down; for (int i = l; i <= r; i++) { if (i == e1 || i == e2) continue; P d = p[i]; while (down.size() > 1 && ccw(down[down.size() - 2], down[down.size() - 1], d) == -1) down.pop_back(); down.push_back(d); } return down; } D line_len(const Pol &p) { int n = int(p.size()); D sm = 0; for (int i = 0; i < n - 1; i++) { sm += (p[i + 1] - p[i]).abs(); } return sm; } bool operator<(const P &x, const P &y) { return lessP(x, y); } D solve(V<P> v, bool one = false) { int n = int(v.size()); map<P, int> mp; for (int i = 0; i < n; i++) mp[v[i]] = i; auto up = convex_up(v, 0, n - 1); auto down = convex_down(v, 0, n - 1); int un = int(up.size()), dn = int(down.size()); V<D> bufu, bufd; for (int i = 1; i < un - 1; i++) { D base = (up[i - 1] - up[i]).abs() + (up[i] - up[i + 1]).abs(); bufu.push_back( base - line_len(convex_up(v, mp[up[i - 1]], mp[up[i + 1]], mp[up[i]]))); } for (int i = 1; i < dn - 1; i++) { D base = (down[i - 1] - down[i]).abs() + (down[i] - down[i + 1]).abs(); bufd.push_back(base - line_len(convex_down(v, mp[down[i - 1]], mp[down[i + 1]], mp[down[i]]))); } D ans = -1e100; D uma = -1e100, dma = -1e100; for (int i = 1; i < un - 2; i++) { ans = max(ans, uma + bufu[i]); uma = max(uma, bufu[i - 1]); } for (int i = 1; i < dn - 2; i++) { ans = max(ans, dma + bufu[i]); dma = max(dma, bufu[i - 1]); } for (auto d : bufu) uma = max(uma, d); for (auto d : bufd) dma = max(dma, d); if (one) return max(uma, dma); ans = max(ans, uma + dma); for (int i = 1; i < un - 1; i++) { D base = (up[i - 1] - up[i]).abs() + (up[i] - up[i + 1]).abs(); auto npo = convex_up(v, mp[up[i - 1]], mp[up[i + 1]], mp[up[i]]); base -= line_len(npo); int m = int(npo.size()); for (int j = 1; j < m - 1; j++) { D base2 = (npo[j - 1] - npo[j]).abs() + (npo[j] - npo[j + 1]).abs(); ans = max(ans, base + base2 - line_len(convex_up(v, mp[npo[j - 1]], mp[npo[j + 1]], mp[npo[j]], mp[up[i]]))); } } for (int i = 1; i < dn - 1; i++) { D base = (down[i - 1] - down[i]).abs() + (down[i] - down[i + 1]).abs(); auto npo = convex_down(v, mp[down[i - 1]], mp[down[i + 1]], mp[down[i]]); base -= line_len(npo); int m = int(npo.size()); for (int j = 1; j < m - 1; j++) { D base2 = (npo[j - 1] - npo[j]).abs() + (npo[j] - npo[j + 1]).abs(); ans = max(ans, base + base2 - line_len(convex_down(v, mp[npo[j - 1]], mp[npo[j + 1]], mp[npo[j]], mp[down[i]]))); } } for (int i = 1; i < un - 2; i++) { D base = (up[i - 1] - up[i]).abs() + (up[i] - up[i + 1]).abs() + (up[i + 1] - up[i + 2]).abs(); ans = max(ans, base - line_len(convex_up(v, mp[up[i - 1]], mp[up[i + 2]], mp[up[i]], mp[up[i + 1]]))); } for (int i = 1; i < dn - 2; i++) { D base = (down[i - 1] - down[i]).abs() + (down[i] - down[i + 1]).abs() + (down[i + 1] - down[i + 2]).abs(); ans = max(ans, base - line_len(convex_down(v, mp[down[i - 1]], mp[down[i + 2]], mp[down[i]], mp[down[i + 1]]))); } return ans; } D naive(V<P> v) { int n = int(v.size()); auto up = convex_up(v, 0, n - 1); auto down = convex_down(v, 0, n - 1); return line_len(up) + line_len(down); } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20); int n; cin >> n; V<P> v(n); for (int i = 0; i < n; i++) { D x, y; cin >> x >> y; v[i] = P(x, y); v[i] *= P::polar(1, 13.4514); } sort(begin(v), end(v)); D ma = -1; D base = naive(v); ma = max(ma, base - naive(V<P>(begin(v), end(v) - 2))); ma = max(ma, base - naive(V<P>(begin(v) + 1, end(v) - 1))); ma = max(ma, base - naive(V<P>(begin(v) + 2, end(v)))); ma = max(ma, base - naive(V<P>(begin(v), end(v) - 1)) + solve(V<P>(begin(v), end(v) - 1), true)); ma = max(ma, base - naive(V<P>(begin(v) + 1, end(v))) + solve(V<P>(begin(v) + 1, end(v)), true)); ma = max(ma, solve(v)); cout << ma << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; using D = double; const D PI = acos(D(-1)), EPS = 1e-10; struct Pt2 { D x, y; Pt2() {} Pt2(D _x, D _y) : x(_x), y(_y) {} Pt2 operator+(const Pt2 &r) const { return Pt2(x + r.x, y + r.y); } Pt2 operator-(const Pt2 &r) const { return Pt2(x - r.x, y - r.y); } Pt2 operator*(const Pt2 &r) const { return Pt2(x * r.x - y * r.y, x * r.y + y * r.x); } Pt2 &operator+=(const Pt2 &r) { return *this = *this + r; } Pt2 &operator-=(const Pt2 &r) { return *this = *this - r; } Pt2 &operator*=(const Pt2 &r) { return *this = *this * r; } Pt2 operator-() const { return Pt2(-x, -y); } D abs() const { return sqrt(x * x + y * y); } D rabs() const { return max(x, y); } // robust abs D arg() const { return atan2(y, x); } pair<D, D> to_pair() const { return make_pair(x, y); } static Pt2 polar(D le, D th) { return Pt2(le * cos(th), le * sin(th)); } }; template <class T> ostream &operator<<(ostream &os, const Pt2 &p) { os << "(" << p.x << ", " << p.y << ")"; return os; } using P = Pt2; int sgn(D a) { if (abs(a) <= EPS) return 0; return (a < 0) ? -1 : 1; } // relative sign int rsgn(D a, D f) { if (abs(a) <= f * EPS) return 0; return (a < 0) ? -1 : 1; } bool near(P a, P b) { return !sgn((a - b).abs()); } bool lessP(P l, P r) { if (sgn(r.x - l.x)) return l.x < r.x; if (sgn(r.y - l.y)) return l.y < r.y; return false; } D cross(P a, P b) { return a.x * b.y - a.y * b.x; } D dot(P a, P b) { return a.x * b.x + a.y * b.y; } // -2, -1, 0, 1, 2 : front, clock, on, cclock, back int ccw(P b, P c) { int s = rsgn(cross(b, c), b.rabs()); if (s) return s; if (!sgn(c.rabs()) || !sgn((c - b).rabs())) return 0; if (dot(b, c) < 0) return 2; if (dot(-b, c - b) < 0) return -2; return 0; } int ccw(P a, P b, P c) { return ccw(b - a, c - a); } using Pol = V<P>; Pol convex_up(const Pol &p, int l, int r, int e1 = -1, int e2 = -1) { Pol up; for (int i = l; i <= r; i++) { if (i == e1 || i == e2) continue; P d = p[i]; while (up.size() > 1 && ccw(up[up.size() - 2], up[up.size() - 1], d) == 1) up.pop_back(); up.push_back(d); } return up; } Pol convex_down(const Pol &p, int l, int r, int e1 = -1, int e2 = -1) { Pol down; for (int i = l; i <= r; i++) { if (i == e1 || i == e2) continue; P d = p[i]; while (down.size() > 1 && ccw(down[down.size() - 2], down[down.size() - 1], d) == -1) down.pop_back(); down.push_back(d); } return down; } D line_len(const Pol &p) { int n = int(p.size()); D sm = 0; for (int i = 0; i < n - 1; i++) { sm += (p[i + 1] - p[i]).abs(); } return sm; } bool operator<(const P &x, const P &y) { return lessP(x, y); } D solve(V<P> v, bool one = false) { int n = int(v.size()); map<P, int> mp; for (int i = 0; i < n; i++) mp[v[i]] = i; auto up = convex_up(v, 0, n - 1); auto down = convex_down(v, 0, n - 1); int un = int(up.size()), dn = int(down.size()); V<D> bufu, bufd; for (int i = 1; i < un - 1; i++) { D base = (up[i - 1] - up[i]).abs() + (up[i] - up[i + 1]).abs(); bufu.push_back( base - line_len(convex_up(v, mp[up[i - 1]], mp[up[i + 1]], mp[up[i]]))); } for (int i = 1; i < dn - 1; i++) { D base = (down[i - 1] - down[i]).abs() + (down[i] - down[i + 1]).abs(); bufd.push_back(base - line_len(convex_down(v, mp[down[i - 1]], mp[down[i + 1]], mp[down[i]]))); } D ans = -1e100; D uma = -1e100, dma = -1e100; for (int i = 1; i < un - 2; i++) { ans = max(ans, uma + bufu[i]); uma = max(uma, bufu[i - 1]); } for (int i = 1; i < dn - 2; i++) { ans = max(ans, dma + bufd[i]); dma = max(dma, bufd[i - 1]); } for (auto d : bufu) uma = max(uma, d); for (auto d : bufd) dma = max(dma, d); if (one) return max(uma, dma); ans = max(ans, uma + dma); for (int i = 1; i < un - 1; i++) { D base = (up[i - 1] - up[i]).abs() + (up[i] - up[i + 1]).abs(); auto npo = convex_up(v, mp[up[i - 1]], mp[up[i + 1]], mp[up[i]]); base -= line_len(npo); int m = int(npo.size()); for (int j = 1; j < m - 1; j++) { D base2 = (npo[j - 1] - npo[j]).abs() + (npo[j] - npo[j + 1]).abs(); ans = max(ans, base + base2 - line_len(convex_up(v, mp[npo[j - 1]], mp[npo[j + 1]], mp[npo[j]], mp[up[i]]))); } } for (int i = 1; i < dn - 1; i++) { D base = (down[i - 1] - down[i]).abs() + (down[i] - down[i + 1]).abs(); auto npo = convex_down(v, mp[down[i - 1]], mp[down[i + 1]], mp[down[i]]); base -= line_len(npo); int m = int(npo.size()); for (int j = 1; j < m - 1; j++) { D base2 = (npo[j - 1] - npo[j]).abs() + (npo[j] - npo[j + 1]).abs(); ans = max(ans, base + base2 - line_len(convex_down(v, mp[npo[j - 1]], mp[npo[j + 1]], mp[npo[j]], mp[down[i]]))); } } for (int i = 1; i < un - 2; i++) { D base = (up[i - 1] - up[i]).abs() + (up[i] - up[i + 1]).abs() + (up[i + 1] - up[i + 2]).abs(); ans = max(ans, base - line_len(convex_up(v, mp[up[i - 1]], mp[up[i + 2]], mp[up[i]], mp[up[i + 1]]))); } for (int i = 1; i < dn - 2; i++) { D base = (down[i - 1] - down[i]).abs() + (down[i] - down[i + 1]).abs() + (down[i + 1] - down[i + 2]).abs(); ans = max(ans, base - line_len(convex_down(v, mp[down[i - 1]], mp[down[i + 2]], mp[down[i]], mp[down[i + 1]]))); } return ans; } D naive(V<P> v) { int n = int(v.size()); auto up = convex_up(v, 0, n - 1); auto down = convex_down(v, 0, n - 1); return line_len(up) + line_len(down); } int main() { cin.tie(0); ios::sync_with_stdio(false); cout << setprecision(20); int n; cin >> n; V<P> v(n); for (int i = 0; i < n; i++) { D x, y; cin >> x >> y; v[i] = P(x, y); v[i] *= P::polar(1, 13.4514); } sort(begin(v), end(v)); D ma = -1; D base = naive(v); ma = max(ma, base - naive(V<P>(begin(v), end(v) - 2))); ma = max(ma, base - naive(V<P>(begin(v) + 1, end(v) - 1))); ma = max(ma, base - naive(V<P>(begin(v) + 2, end(v)))); ma = max(ma, base - naive(V<P>(begin(v), end(v) - 1)) + solve(V<P>(begin(v), end(v) - 1), true)); ma = max(ma, base - naive(V<P>(begin(v) + 1, end(v))) + solve(V<P>(begin(v) + 1, end(v)), true)); ma = max(ma, solve(v)); cout << ma << endl; return 0; }
[["-", 12, 2, 3, 4, 0, 16, 12, 69, 28, 22], ["+", 12, 2, 3, 4, 0, 16, 12, 69, 28, 22], ["-", 0, 11, 12, 2, 3, 4, 0, 69, 28, 22], ["+", 0, 11, 12, 2, 3, 4, 0, 69, 28, 22]]
1
2,738
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (int i = 0; i < N; i++) #define pb push_back typedef long long ll; typedef pair<ll, int> ll_i; struct edge { int v, w; }; const ll INF = LLONG_MAX / 3; const int MOD = 1e9 + 114514; pair<vector<ll>, vector<int>> dijkstra(int N, vector<vector<edge>> &G, int s) { vector<ll> d(N, INF); d[s] = 0; vector<int> way(N); way[s] = 1; priority_queue<ll_i, vector<ll_i>, greater<ll_i>> pq; pq.push(ll_i(0, s)); while (pq.size()) { ll_i p = pq.top(); pq.pop(); int u = p.second; if (p.first > d[u]) continue; for (edge e : G[u]) { if (d[e.v] > d[u] + e.w) { d[e.v] = d[u] + e.w; way[e.v] = 0; pq.push(ll_i(d[e.v], e.v)); } if (d[e.v] == d[u] + e.w) way[e.v] = (way[e.v] + way[u]) % MOD; } } return {d, way}; } int main() { int N, M; cin >> N >> M; vector<int> a(M), b(M), c(M); rep(i, M) scanf("%d%d%d", &a[i], &b[i], &c[i]), a[i]--, b[i]--; vector<vector<edge>> G(N), _G(N); rep(i, M) G[a[i]].pb({b[i], c[i]}), _G[b[i]].pb({a[i], c[i]}); auto z = dijkstra(N, G, 0), _z = dijkstra(N, _G, 1); vector<ll> d = z.first, _d = _z.first; vector<int> way = z.second, _way = _z.second; ll D = d[1]; int WAY = way[1]; rep(i, M) { int u = a[i], v = b[i]; if (d[u] + c[i] + _d[v] == D && (ll)way[u] * way[v] % MOD == WAY) printf("SAD\n"); else if (d[v] + c[i] + _d[u] < D) printf("HAPPY\n"); else printf("SOSO\n"); } }
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (int i = 0; i < N; i++) #define pb push_back typedef long long ll; typedef pair<ll, int> ll_i; struct edge { int v, w; }; const ll INF = LLONG_MAX / 3; const int MOD = 1e9 + 114514; pair<vector<ll>, vector<int>> dijkstra(int N, vector<vector<edge>> &G, int s) { vector<ll> d(N, INF); d[s] = 0; vector<int> way(N); way[s] = 1; priority_queue<ll_i, vector<ll_i>, greater<ll_i>> pq; pq.push(ll_i(0, s)); while (pq.size()) { ll_i p = pq.top(); pq.pop(); int u = p.second; if (p.first > d[u]) continue; for (edge e : G[u]) { if (d[e.v] > d[u] + e.w) { d[e.v] = d[u] + e.w; way[e.v] = 0; pq.push(ll_i(d[e.v], e.v)); } if (d[e.v] == d[u] + e.w) way[e.v] = (way[e.v] + way[u]) % MOD; } } return {d, way}; } int main() { int N, M; cin >> N >> M; vector<int> a(M), b(M), c(M); rep(i, M) scanf("%d%d%d", &a[i], &b[i], &c[i]), a[i]--, b[i]--; vector<vector<edge>> G(N), _G(N); rep(i, M) G[a[i]].pb({b[i], c[i]}), _G[b[i]].pb({a[i], c[i]}); auto z = dijkstra(N, G, 0), _z = dijkstra(N, _G, 1); vector<ll> d = z.first, _d = _z.first; vector<int> way = z.second, _way = _z.second; ll D = d[1]; int WAY = way[1]; rep(i, M) { int u = a[i], v = b[i]; if (d[u] + c[i] + _d[v] == D && (ll)way[u] * _way[v] % MOD == WAY) printf("SAD\n"); else if (d[v] + c[i] + _d[u] < D) printf("HAPPY\n"); else printf("SOSO\n"); } }
[["-", 12, 16, 31, 16, 31, 16, 12, 69, 28, 22], ["+", 12, 16, 31, 16, 31, 16, 12, 69, 28, 22]]
1
645
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <vector> using namespace std; const int mod = 1000000021; const long long inf = 1LL << 61; struct edge { int to, cost, id; }; struct edge2 { int to, id; }; struct state { int pos; long long cost; }; bool operator<(const state &s1, const state &s2) { return s1.cost > s2.cost; } int N, M, dp[100009], dp2[100009], va[100009]; bool vis1[100009], vis2[100009]; vector<int> a, b, c; vector<long long> shortest_path(vector<vector<edge>> g, int src) { vector<long long> ret(g.size(), inf); ret[src] = 0; priority_queue<state> que; que.push(state{src, 0}); while (!que.empty()) { int u = que.top().pos; que.pop(); for (edge e : g[u]) { long long nd = ret[u] + e.cost; if (ret[e.to] > nd) { ret[e.to] = nd; que.push(state{e.to, nd}); } } } return ret; } vector<int> solve() { vector<vector<edge>> g(N); vector<vector<edge>> rg(N); for (int i = 0; i < M; i++) { g[a[i]].push_back(edge{b[i], c[i], i}); rg[b[i]].push_back(edge{a[i], c[i], i}); } vector<long long> ds = shortest_path(g, 0); vector<long long> dt = shortest_path(rg, 1); vector<bool> ok(M); vector<vector<edge2>> sg(N), sr(N); for (int i = 0; i < M; i++) { if (ds[a[i]] + c[i] + dt[b[i]] == ds[1]) { sg[a[i]].push_back(edge2{b[i], i}); sr[b[i]].push_back(edge2{a[i], i}); ok[i] = true; } } fill(vis1, vis1 + N, false); fill(vis2, vis2 + N, false); fill(dp, dp + N, 0); fill(dp2, dp2 + N, 0); vector<int> dpm1(M), dpm2(M); priority_queue<state> que; que.push(state{0, 0}); dp[0] = 1; while (!que.empty()) { int u = que.top().pos; que.pop(); if (!vis1[u]) { vis1[u] = true; for (edge2 i : sg[u]) { dp[i.to] += dp[u]; dpm1[i.id] = dp[u]; if (dp[i.to] >= mod) dp[i.to] -= mod; que.push(state{i.to, ds[i.to]}); } } } que.push(state{1, 0}); dp2[1] = 1; while (!que.empty()) { int u = que.top().pos; que.pop(); if (!vis2[u]) { vis2[u] = true; for (edge2 i : sr[u]) { dp2[i.to] += dp2[u]; dpm2[i.id] = dp2[u]; if (dp2[i.to] >= mod) dp2[i.to] -= mod; que.push(state{i.to, dt[i.to]}); } } } for (int i = 0; i < N; i++) va[i] = 1LL * dp[i] * dp2[i] % mod; map<tuple<int, int, int>, int> cnts; for (int i = 0; i < M; i++) { cnts[make_tuple(a[i], b[i], c[i])]++; } vector<int> ret(M); for (int i = 0; i < M; i++) { if (!ok[i]) { ret[i] = (ds[b[i]] + dt[a[i]] + c[i] < ds[1] ? 2 : 1); } else { if (ds[b[i]] + dt[a[i]] + c[i] < ds[1]) ret[i] = 2; else if (ds[b[i]] + dt[a[i]] + c[i] == ds[1]) ret[i] = 1; else { if (1LL * dpm1[i] * dpm2[i] % mod == va[0] && cnts[make_tuple(a[i], b[i], c[i])] == 1) ret[i] = 0; else ret[i] = 1; } } } return ret; } vector<int> brute_force() { vector<int> ret(M); vector<vector<edge>> ig(N); for (int i = 0; i < M; i++) { ig[a[i]].push_back(edge{b[i], c[i]}); } long long res = shortest_path(ig, 0)[1]; if (res == inf) return {-1}; for (int i = 0; i < M; i++) { vector<vector<edge>> g(M); for (int j = 0; j < M; j++) { if (i != j) g[a[j]].push_back(edge{b[j], c[j]}); else g[b[j]].push_back(edge{a[j], c[j]}); } long long re = shortest_path(g, 0)[1]; if (re < res) ret[i] = 2; if (re == res) ret[i] = 1; if (re > res) ret[i] = 0; } return ret; } int rand_rng(int l, int r) { long long seed = rand() * 123456789LL + rand() * 3456789LL + rand() * 12345LL; return l + (seed) % (r - l); } void random_test() { N = 7; M = 7; for (int i = 0; i < 10000; i++) { a = vector<int>(M); b = vector<int>(M); c = vector<int>(M); for (int j = 0; j < M; j++) { while (a[j] == b[j]) { a[j] = rand_rng(0, N); b[j] = rand_rng(0, N); } c[j] = rand_rng(1, 10); } vector<int> ret1 = brute_force(); if (ret1[0] != -1) { vector<int> ret2 = solve(); if (ret1 != ret2) { cout << "BUG" << endl; solve(); } if (i % 100 == 99) cout << i + 1 << endl; } else { i--; continue; } } } int main() { random_test(); ios::sync_with_stdio(false); cin >> N >> M; a = vector<int>(M); b = vector<int>(M); c = vector<int>(M); for (int i = 0; i < M; i++) { cin >> a[i] >> b[i] >> c[i]; a[i]--, b[i]--; } vector<int> ret = solve(); for (int i = 0; i < M; i++) { if (ret[i] == 2) cout << "HAPPY\n"; else if (ret[i] == 1) cout << "SOSO\n"; else cout << "SAD\n"; } return 0; }
#include <algorithm> #include <iostream> #include <map> #include <queue> #include <vector> using namespace std; const int mod = 1000000021; const long long inf = 1LL << 61; struct edge { int to, cost, id; }; struct edge2 { int to, id; }; struct state { int pos; long long cost; }; bool operator<(const state &s1, const state &s2) { return s1.cost > s2.cost; } int N, M, dp[100009], dp2[100009], va[100009]; bool vis1[100009], vis2[100009]; vector<int> a, b, c; vector<long long> shortest_path(vector<vector<edge>> g, int src) { vector<long long> ret(g.size(), inf); ret[src] = 0; priority_queue<state> que; que.push(state{src, 0}); while (!que.empty()) { int u = que.top().pos; que.pop(); for (edge e : g[u]) { long long nd = ret[u] + e.cost; if (ret[e.to] > nd) { ret[e.to] = nd; que.push(state{e.to, nd}); } } } return ret; } vector<int> solve() { vector<vector<edge>> g(N); vector<vector<edge>> rg(N); for (int i = 0; i < M; i++) { g[a[i]].push_back(edge{b[i], c[i], i}); rg[b[i]].push_back(edge{a[i], c[i], i}); } vector<long long> ds = shortest_path(g, 0); vector<long long> dt = shortest_path(rg, 1); vector<bool> ok(M); vector<vector<edge2>> sg(N), sr(N); for (int i = 0; i < M; i++) { if (ds[a[i]] + c[i] + dt[b[i]] == ds[1]) { sg[a[i]].push_back(edge2{b[i], i}); sr[b[i]].push_back(edge2{a[i], i}); ok[i] = true; } } fill(vis1, vis1 + N, false); fill(vis2, vis2 + N, false); fill(dp, dp + N, 0); fill(dp2, dp2 + N, 0); vector<int> dpm1(M), dpm2(M); priority_queue<state> que; que.push(state{0, 0}); dp[0] = 1; while (!que.empty()) { int u = que.top().pos; que.pop(); if (!vis1[u]) { vis1[u] = true; for (edge2 i : sg[u]) { dp[i.to] += dp[u]; dpm1[i.id] = dp[u]; if (dp[i.to] >= mod) dp[i.to] -= mod; que.push(state{i.to, ds[i.to]}); } } } que.push(state{1, 0}); dp2[1] = 1; while (!que.empty()) { int u = que.top().pos; que.pop(); if (!vis2[u]) { vis2[u] = true; for (edge2 i : sr[u]) { dp2[i.to] += dp2[u]; dpm2[i.id] = dp2[u]; if (dp2[i.to] >= mod) dp2[i.to] -= mod; que.push(state{i.to, dt[i.to]}); } } } for (int i = 0; i < N; i++) va[i] = 1LL * dp[i] * dp2[i] % mod; map<tuple<int, int, int>, int> cnts; for (int i = 0; i < M; i++) { cnts[make_tuple(a[i], b[i], c[i])]++; } vector<int> ret(M); for (int i = 0; i < M; i++) { if (!ok[i]) { ret[i] = (ds[b[i]] + dt[a[i]] + c[i] < ds[1] ? 2 : 1); } else { if (ds[b[i]] + dt[a[i]] + c[i] < ds[1]) ret[i] = 2; else if (ds[b[i]] + dt[a[i]] + c[i] == ds[1]) ret[i] = 1; else { if (1LL * dpm1[i] * dpm2[i] % mod == va[0] && cnts[make_tuple(a[i], b[i], c[i])] == 1) ret[i] = 0; else ret[i] = 1; } } } return ret; } vector<int> brute_force() { vector<int> ret(M); vector<vector<edge>> ig(N); for (int i = 0; i < M; i++) { ig[a[i]].push_back(edge{b[i], c[i]}); } long long res = shortest_path(ig, 0)[1]; if (res == inf) return {-1}; for (int i = 0; i < M; i++) { vector<vector<edge>> g(M); for (int j = 0; j < M; j++) { if (i != j) g[a[j]].push_back(edge{b[j], c[j]}); else g[b[j]].push_back(edge{a[j], c[j]}); } long long re = shortest_path(g, 0)[1]; if (re < res) ret[i] = 2; if (re == res) ret[i] = 1; if (re > res) ret[i] = 0; } return ret; } int rand_rng(int l, int r) { long long seed = rand() * 123456789LL + rand() * 3456789LL + rand() * 12345LL; return l + (seed) % (r - l); } void random_test() { N = 7; M = 7; for (int i = 0; i < 10000; i++) { a = vector<int>(M); b = vector<int>(M); c = vector<int>(M); for (int j = 0; j < M; j++) { while (a[j] == b[j]) { a[j] = rand_rng(0, N); b[j] = rand_rng(0, N); } c[j] = rand_rng(1, 10); } vector<int> ret1 = brute_force(); if (ret1[0] != -1) { vector<int> ret2 = solve(); if (ret1 != ret2) { cout << "BUG" << endl; solve(); } if (i % 100 == 99) cout << i + 1 << endl; } else { i--; continue; } } } int main() { // random_test(); ios::sync_with_stdio(false); cin >> N >> M; a = vector<int>(M); b = vector<int>(M); c = vector<int>(M); for (int i = 0; i < M; i++) { cin >> a[i] >> b[i] >> c[i]; a[i]--, b[i]--; } vector<int> ret = solve(); for (int i = 0; i < M; i++) { if (ret[i] == 2) cout << "HAPPY\n"; else if (ret[i] == 1) cout << "SOSO\n"; else cout << "SAD\n"; } return 0; }
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
1
1,837
#include <algorithm> #include <cmath> #include <iostream> #include <vector> using namespace std; using ll = long long; int main() { string s1, s2; double d1, d2; double l1, l2; cin >> s1 >> d1 >> l1; cin >> s2 >> d2 >> l2; if (s1 == "CD") { d1 += 60.0; } if (s2 == "CD") { d2 += 60.0; } if (s1 == "DB") { d1 += 120.0; } if (s2 == "DB") { d2 += 120.0; } double x1, x2, y1, y2; x1 = l1 * cos(d1 / 180.0 * M_PI); x2 = l2 * cos(d2 / 180.0 * M_PI); y1 = l1 * sin(d1 / 180.0 * M_PI); y2 = l2 * sin(d2 / 180.0 * M_PI); double p1, p2, q1, q2; q1 = 2 * y1 / sqrt(3); q2 = 2 * y2 / sqrt(3); p1 = x1 - q1 / 2; p2 = x2 - q2 / 2; while (!(0 <= q1 && q1 <= 2)) { if (q1 < 0) { q1 += 2; } else { q1 -= 2; } } while (!(0 <= q2 && q2 <= 2)) { if (q2 < 0) { q2 += 2; } else { q2 -= 2; } } while (!(0 <= p1 && p1 <= 2)) { if (p1 < 0) { p1 += 2; } else { p1 -= 2; } } while (!(0 <= p2 && p2 <= 2)) { if (p2 < 0) { p2 += 2; } else { p2 -= 2; } } if (p1 + q1 > 2) { p1 = 2.0 - p1; q1 = 2.0 - q1; } if (p2 + q2 > 2) { p2 = 2.0 - p2; q2 = 2.0 - q2; } int label1 = 0; int label2 = 0; if (p1 + q1 < 1) { label1 = 1; } if (q1 > 1) { label1 = 2; } if (p1 > 1) { label1 = 3; } if (p2 + q2 < 1) { label2 = 1; } if (q2 > 1) { label2 = 2; } if (p2 > 1) { label1 = 3; } // cout << p1 << " " << q1 << " " << p2 << " " << q2 << endl; if (label1 == label2) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <vector> using namespace std; using ll = long long; int main() { string s1, s2; double d1, d2; double l1, l2; cin >> s1 >> d1 >> l1; cin >> s2 >> d2 >> l2; if (s1 == "CD") { d1 += 60.0; } if (s2 == "CD") { d2 += 60.0; } if (s1 == "DB") { d1 += 120.0; } if (s2 == "DB") { d2 += 120.0; } double x1, x2, y1, y2; x1 = l1 * cos(d1 / 180.0 * M_PI); x2 = l2 * cos(d2 / 180.0 * M_PI); y1 = l1 * sin(d1 / 180.0 * M_PI); y2 = l2 * sin(d2 / 180.0 * M_PI); double p1, p2, q1, q2; q1 = 2 * y1 / sqrt(3); q2 = 2 * y2 / sqrt(3); p1 = x1 - q1 / 2; p2 = x2 - q2 / 2; while (!(0 <= q1 && q1 <= 2)) { if (q1 < 0) { q1 += 2; } else { q1 -= 2; } } while (!(0 <= q2 && q2 <= 2)) { if (q2 < 0) { q2 += 2; } else { q2 -= 2; } } while (!(0 <= p1 && p1 <= 2)) { if (p1 < 0) { p1 += 2; } else { p1 -= 2; } } while (!(0 <= p2 && p2 <= 2)) { if (p2 < 0) { p2 += 2; } else { p2 -= 2; } } if (p1 + q1 > 2) { p1 = 2.0 - p1; q1 = 2.0 - q1; } if (p2 + q2 > 2) { p2 = 2.0 - p2; q2 = 2.0 - q2; } int label1 = 0; int label2 = 0; if (p1 + q1 < 1) { label1 = 1; } if (q1 > 1) { label1 = 2; } if (p1 > 1) { label1 = 3; } if (p2 + q2 < 1) { label2 = 1; } if (q2 > 1) { label2 = 2; } if (p2 > 1) { label2 = 3; } // cout << p1 << " " << q1 << " " << p2 << " " << q2 << endl; if (label1 == label2) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; }
[["-", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22]]
1
516
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <set> #include <string> #include <vector> using namespace std; const double DTR = (2 * acos(-1)) / 360; double myfmod(double x, double y) { return y - (int)(x / y) * y; } enum ans { ABC, ACD, ADB, BCD, }; int solve() { string xy; cin >> xy; int d, l; scanf("%d%d", &d, &l); double base = xy == "BC" ? -60 : xy == "CD" ? 0 : xy == "DB" ? 60 : 0; double theta = (base + d) * DTR; double y = l * sin(theta); double x = l * cos(theta); double z60 = x + sqrt(3) / 3.0 * y; double z120 = -x + sqrt(3) / 3.0 * y; z60 = myfmod(myfmod(z60, 2.0) + 2.0 + 1e-8, 2.0); z120 = myfmod(myfmod(z120, 2.0) + 2.0 + 1e-8, 2.0); y = (z60 + z120) * sqrt(3) / 2.0; if (z60 < 1.0) { if (z120 < 1.0) { if (y < sqrt(3) / 2.0) { return ADB; } else { return BCD; } } else { if (y < sqrt(3)) { return ABC; } else { return ACD; } } } else { if (z120 < 1.0) { if (y < sqrt(3)) { return ACD; } else { return ABC; } } else { if (y < 3.0 * sqrt(3) / 2.0) { return BCD; } else { return ADB; } } } } int main() { int a = solve(), b = solve(); puts(a == b ? "YES" : "NO"); return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <set> #include <string> #include <vector> using namespace std; const double DTR = (2 * acos(-1)) / 360; double myfmod(double x, double y) { return x - (int)(x / y) * y; } enum ans { ABC, ACD, ADB, BCD, }; int solve() { string xy; cin >> xy; int d, l; scanf("%d%d", &d, &l); double base = xy == "BC" ? -60 : xy == "CD" ? 0 : xy == "DB" ? 60 : 0; double theta = (base + d) * DTR; double y = l * sin(theta); double x = l * cos(theta); double z60 = x + sqrt(3) / 3.0 * y; double z120 = -x + sqrt(3) / 3.0 * y; z60 = myfmod(myfmod(z60, 2.0) + 2.0 + 1e-8, 2.0); z120 = myfmod(myfmod(z120, 2.0) + 2.0 + 1e-8, 2.0); y = (z60 + z120) * sqrt(3) / 2.0; if (z60 < 1.0) { if (z120 < 1.0) { if (y < sqrt(3) / 2.0) { return ADB; } else { return BCD; } } else { if (y < sqrt(3)) { return ABC; } else { return ACD; } } } else { if (z120 < 1.0) { if (y < sqrt(3)) { return ACD; } else { return ABC; } } else { if (y < 3.0 * sqrt(3) / 2.0) { return BCD; } else { return ADB; } } } } int main() { int a = solve(), b = solve(); puts(a == b ? "YES" : "NO"); return 0; }
[["-", 0, 14, 8, 9, 0, 37, 0, 16, 31, 22], ["+", 0, 14, 8, 9, 0, 37, 0, 16, 31, 22]]
1
400
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; int n, l, r, imos[100007], ans1, ans2, sum; vector<P> v; vector<int> v1, v2; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> l >> r; v.push_back(P(l, r)); v1.push_back(l); v2.push_back(r); imos[l]++; imos[r]--; } sort(v1.begin(), v1.end()); sort(v2.begin(), v2.end()); for (int i = 0; i < n; i++) { int sum1 = lower_bound(v2.begin(), v2.end(), v[i].first) - v2.begin(); int sum2 = v1.end() - lower_bound(v1.begin(), v1.end(), v[i].second); ans1 = max(ans1, n - sum1 - sum2); } for (int i = 0; i < 100007; i++) { sum += imos[i]; ans2 = max(ans2, sum); } cout << ans1 << ' ' << ans2 << endl; }
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; int n, l, r, imos[100007], ans1, ans2, sum; vector<P> v; vector<int> v1, v2; int main() { cin >> n; for (int i = 0; i < n; i++) { cin >> l >> r; v.push_back(P(l, r)); v1.push_back(l); v2.push_back(r); imos[l]++; imos[r]--; } sort(v1.begin(), v1.end()); sort(v2.begin(), v2.end()); for (int i = 0; i < n; i++) { int sum1 = upper_bound(v2.begin(), v2.end(), v[i].first) - v2.begin(); int sum2 = v1.end() - lower_bound(v1.begin(), v1.end(), v[i].second); ans1 = max(ans1, n - sum1 - sum2); } for (int i = 0; i < 100007; i++) { sum += imos[i]; ans2 = max(ans2, sum); } cout << ans1 << ' ' << ans2 << endl; }
[["-", 0, 43, 49, 50, 51, 16, 31, 2, 63, 22], ["+", 0, 43, 49, 50, 51, 16, 31, 2, 63, 22]]
1
282
#include <bits/stdc++.h> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define HUGE_NUM 99999999999999999 #define MOD 1000000007 #define EPS 0.000000001 using namespace std; #define NUM 500000 int N; int bean[100005]; vector<int> V[NUM]; void init(int first_N) { while (N < first_N) N *= 2; } void update(int loc, int value) { loc += N - 1; V[loc].push_back(value); if (N == 1) return; int parent = (loc - 1) / 2; while (true) { V[parent].push_back(value); if (parent == 0) break; else { parent = (parent - 1) / 2; } } } int query(int search_left, int search_right, int node_id, int node_left, int node_right, int D) { if (search_right < node_left || search_left > node_right) return BIG_NUM; if (search_left <= node_left && search_right >= node_right) { if (V[node_id][0] > D) { // Dが最小値より小さい return V[node_id][0] - D; } else if (V[node_id][V[node_id].size() - 1] < D) { // Dが最大値より大きい return D - V[node_id][V[node_id].size() - 1]; } int small, big, L, R, mid; // D以下の最大の数字を二分探索で検索 L = 0, R = V[node_id].size() - 1, mid = (L + R) / 2; while (L <= R) { if (V[node_id][mid] <= D) { small = V[node_id][mid]; L = mid + 1; } else { R = mid - 1; } mid = (L + R) / 2; } // Dより大きい最小の数を、二分探索で検索 L = 0, R = V[node_id].size() - 1, mid = (L + R) / 2; while (L <= R) { if (V[node_id][mid] > D) { big = V[node_id][mid]; R = mid - 1; } else { L = mid + 1; } mid = (L + R) / 2; } return min(big - D, D - small); } //今回のノードの区間に、一部検索区間と重なっている区間がある場合→再帰的に子どもに尋ねる int left_min = query(search_left, search_right, 2 * node_id + 1, node_left, (node_left + node_right) / 2, D); int right_min = query(search_left, search_right, 2 * node_id + 2, (node_left + node_right) / 2 + 1, node_right, D); return min(left_min, right_min); } int main() { int first_N; scanf("%d", &first_N); for (int i = 0; i < first_N; i++) { scanf("%d", &bean[i]); } N = 1; init(first_N); for (int i = 0; i < first_N; i++) { update(i, bean[i]); } for (int i = 0; i < N; i++) { sort(V[i].begin(), V[i].end()); } int num_query, left, right, D; scanf("%d", &num_query); for (int loop = 0; loop < num_query; loop++) { scanf("%d %d %d", &left, &right, &D); printf("%d\n", query(left, right, 0, 0, N - 1, D)); } return 0; }
#include <bits/stdc++.h> typedef long long int ll; typedef unsigned long long int ull; #define BIG_NUM 2000000000 #define HUGE_NUM 99999999999999999 #define MOD 1000000007 #define EPS 0.000000001 using namespace std; #define NUM 500000 int N; int bean[100005]; vector<int> V[NUM]; void init(int first_N) { while (N < first_N) N *= 2; } void update(int loc, int value) { loc += N - 1; V[loc].push_back(value); if (N == 1) return; int parent = (loc - 1) / 2; while (true) { V[parent].push_back(value); if (parent == 0) break; else { parent = (parent - 1) / 2; } } } int query(int search_left, int search_right, int node_id, int node_left, int node_right, int D) { if (search_right < node_left || search_left > node_right) return BIG_NUM; if (search_left <= node_left && search_right >= node_right) { if (V[node_id][0] >= D) { // Dが最小値より小さい return V[node_id][0] - D; } else if (V[node_id][V[node_id].size() - 1] < D) { // Dが最大値より大きい return D - V[node_id][V[node_id].size() - 1]; } int small, big, L, R, mid; // D以下の最大の数字を二分探索で検索 L = 0, R = V[node_id].size() - 1, mid = (L + R) / 2; while (L <= R) { if (V[node_id][mid] <= D) { small = V[node_id][mid]; L = mid + 1; } else { R = mid - 1; } mid = (L + R) / 2; } // Dより大きい最小の数を、二分探索で検索 L = 0, R = V[node_id].size() - 1, mid = (L + R) / 2; while (L <= R) { if (V[node_id][mid] >= D) { big = V[node_id][mid]; R = mid - 1; } else { L = mid + 1; } mid = (L + R) / 2; } return min(big - D, D - small); } //今回のノードの区間に、一部検索区間と重なっている区間がある場合→再帰的に子どもに尋ねる int left_min = query(search_left, search_right, 2 * node_id + 1, node_left, (node_left + node_right) / 2, D); int right_min = query(search_left, search_right, 2 * node_id + 2, (node_left + node_right) / 2 + 1, node_right, D); return min(left_min, right_min); } int main() { int first_N; scanf("%d", &first_N); for (int i = 0; i < first_N; i++) { scanf("%d", &bean[i]); } N = 1; init(first_N); for (int i = 0; i < first_N; i++) { update(i, bean[i]); } for (int i = 0; i < N; i++) { sort(V[i].begin(), V[i].end()); } int num_query, left, right, D; scanf("%d", &num_query); for (int loop = 0; loop < num_query; loop++) { scanf("%d %d %d", &left, &right, &D); printf("%d\n", query(left, right, 0, 0, N - 1, D)); } return 0; }
[["-", 64, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
1
731
var input = require('fs').readFileSync('/dev/stdin', 'utf8'); input = ''; var n = input.trim() - 0; var ans = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]; var i = 0; while (true) { i++; var cnt = 0; for (var j = i; j >= 1; j--) { if (i % j == 0) cnt++; } if (ans[cnt - 1] == 0) { ans[cnt - 1] = i; if (!ans.includes(0)) break; } } console.log(ans[n - 1]);
var input = require('fs').readFileSync('/dev/stdin', 'utf8'); var n = input.trim() - 0; var ans = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]; var i = 0; while (true) { i++; var cnt = 0; for (var j = i; j >= 1; j--) { if (i % j == 0) cnt++; } if (ans[cnt - 1] == 0) { ans[cnt - 1] = i; if (!ans.includes(0)) break; } } console.log(ans[n - 1]);
[["-", 36, 36, 0, 493, 0, 1, 0, 11, 31, 22], ["-", 36, 36, 0, 493, 0, 1, 0, 11, 0, 32], ["-", 0, 493, 0, 1, 0, 11, 12, 557, 0, 104], ["-", 36, 36, 36, 36, 0, 493, 0, 1, 0, 35]]
2
158
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int res = 0; for (int i = 0; !res && i <= 12 * 12; i++) { int c = 0; for (int j = 1; j <= i; j++) { if (i % j == 0) { c++; } } if (c == N) res = i; } cout << res << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int res = 0; for (int i = 1; !res && i <= 1 << 12; i++) { int c = 0; for (int j = 1; j <= i; j++) { if (i % j == 0) { c++; } } if (c == N) res = i; } cout << res << endl; return 0; }
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["-", 0, 7, 15, 16, 12, 16, 12, 16, 31, 13], ["-", 0, 7, 15, 16, 12, 16, 12, 16, 17, 48], ["+", 0, 7, 15, 16, 12, 16, 12, 16, 31, 13], ["+", 0, 7, 15, 16, 12, 16, 12, 16, 17, 151]]
1
98
#include <bits/stdc++.h> #define REP(x, y, z) for (int x = y; x <= z; x++) #define FORD(x, y, z) for (int x = y; x >= z; x--) #define MSET(x, y) memset(x, y, sizeof(x)) #define FOR(x, y) for (__typeof(y.begin()) x = y.begin(); x != y.end(); x++) #define F first #define S second #define MP make_pair #define PB push_back #define SZ size() #define M void RI() {} template <typename... T> void RI(int &head, T &...tail) { scanf("%d", &head); RI(tail...); } using namespace std; typedef long long LL; int cnt(int x) { int re = 0; REP(i, 1, x) if (x % i == 0) re++; return re; } int main() { int n; RI(n); REP(i, 1, 1000) if (cnt(i) == n) { printf("%d\n", i); break; } return 0; }
#include <bits/stdc++.h> #define REP(x, y, z) for (int x = y; x <= z; x++) #define FORD(x, y, z) for (int x = y; x >= z; x--) #define MSET(x, y) memset(x, y, sizeof(x)) #define FOR(x, y) for (__typeof(y.begin()) x = y.begin(); x != y.end(); x++) #define F first #define S second #define MP make_pair #define PB push_back #define SZ size() #define M void RI() {} template <typename... T> void RI(int &head, T &...tail) { scanf("%d", &head); RI(tail...); } using namespace std; typedef long long LL; int cnt(int x) { int re = 0; REP(i, 1, x) if (x % i == 0) re++; return re; } int main() { int n; RI(n); REP(i, 1, 5000) if (cnt(i) == n) { printf("%d\n", i); break; } return 0; }
[["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13]]
1
191
#include <algorithm> #include <complex> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define REP(i, m, n) for (int i = int(m); i < int(n); i++) #define EACH(i, c) for (auto &(i) : c) #define all(c) begin(c), end(c) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort(begin(c), end(c)) #define pb emplace_back #define MP make_pair #define SZ(a) int((a).size()) #ifdef LOCAL #define DEBUG(s) cout << (s) << endl; #define dump(x) cerr << #x << " = " << (x) << endl; #define BR cout << endl; #else #define DEBUG(s) #define dump(x) #define BR #endif using namespace std; typedef unsigned int UI; typedef unsigned long UL; typedef long long LL; typedef unsigned long long ULL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<LL> VLL; typedef vector<string> VS; typedef pair<int, int> PII; const double EPS = 1e-10; const double PI = acos(-1.0); template <class T> inline T sqr(T x) { return x * x; } int main() { int n, cnt = 1; cin >> n; switch (n) { case 4: cnt = 2 * 3; break; case 6: cnt = 2 * 2 * 3; break; case 8: cnt = 2 * 3 * 5; break; case 9: cnt = 2 * 2 * 3 * 3; break; case 10: cnt = 2 * 2 * 2 * 2 * 3; break; case 12: cnt = 2 * 2 * 3 * 5; break; default: REP(i, 1, n) cnt *= 2; break; } cout << cnt << endl; return 0; }
#include <algorithm> #include <complex> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define REP(i, m, n) for (int i = int(m); i < int(n); i++) #define EACH(i, c) for (auto &(i) : c) #define all(c) begin(c), end(c) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort(begin(c), end(c)) #define pb emplace_back #define MP make_pair #define SZ(a) int((a).size()) #ifdef LOCAL #define DEBUG(s) cout << (s) << endl; #define dump(x) cerr << #x << " = " << (x) << endl; #define BR cout << endl; #else #define DEBUG(s) #define dump(x) #define BR #endif using namespace std; typedef unsigned int UI; typedef unsigned long UL; typedef long long LL; typedef unsigned long long ULL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<LL> VLL; typedef vector<string> VS; typedef pair<int, int> PII; const double EPS = 1e-10; const double PI = acos(-1.0); template <class T> inline T sqr(T x) { return x * x; } int main() { int n, cnt = 1; cin >> n; switch (n) { case 4: cnt = 2 * 3; break; case 6: cnt = 2 * 2 * 3; break; case 8: cnt = 24; break; case 9: cnt = 2 * 2 * 3 * 3; break; case 10: cnt = 2 * 2 * 2 * 2 * 3; break; case 12: cnt = 2 * 2 * 3 * 5; break; default: REP(i, 1, n) cnt *= 2; break; } cout << cnt << endl; return 0; }
[["-", 0, 1, 0, 11, 12, 16, 31, 16, 31, 13], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 17, 48], ["-", 0, 1, 0, 11, 12, 16, 31, 16, 12, 13], ["-", 0, 100, 0, 1, 0, 11, 12, 16, 17, 48], ["-", 0, 100, 0, 1, 0, 11, 12, 16, 12, 13], ["+", 8, 9, 0, 100, 0, 1, 0, 11, 12, 13]]
1
337
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <time.h> #include <vector> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define FFOR(i, a, b) for (int i = (a); i <= (b); i++) #define REP(i, b) FOR(i, 0, b) #define RREP(i, b) FFOR(i, 1, b) #define PB push_back #define F first #define S second #define BE(c) c.begin(), c.end() using namespace std; typedef long long LL; typedef double ut; typedef long double ld; typedef pair<ut, ut> pr; typedef vector<pr> Vpr; typedef vector<ut> VI; typedef pair<ut, pr> ppr; typedef priority_queue<pr, Vpr, greater<pr>> PQ; const int SIZE = 5 + 3 * 1e+4; const ut INF = 1 << 30; const ld eps = 1e-6; const LL mod = 1e+9 + 7; int main() { int n; cin >> n; FOR(i, 1, 101) { int cnt = 0; for (int j = 1; j <= i; ++j) { if (i % j == 0) cnt++; } if (cnt == n) { cout << i << endl; break; } } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <time.h> #include <vector> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define FFOR(i, a, b) for (int i = (a); i <= (b); i++) #define REP(i, b) FOR(i, 0, b) #define RREP(i, b) FFOR(i, 1, b) #define PB push_back #define F first #define S second #define BE(c) c.begin(), c.end() using namespace std; typedef long long LL; typedef double ut; typedef long double ld; typedef pair<ut, ut> pr; typedef vector<pr> Vpr; typedef vector<ut> VI; typedef pair<ut, pr> ppr; typedef priority_queue<pr, Vpr, greater<pr>> PQ; const int SIZE = 5 + 3 * 1e+4; const ut INF = 1 << 30; const ld eps = 1e-6; const LL mod = 1e+9 + 7; int main() { int n; cin >> n; FOR(i, 1, 100001) { int cnt = 0; for (int j = 1; j <= i; ++j) { if (i % j == 0) cnt++; } if (cnt == n) { cout << i << endl; break; } } return 0; }
[["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13]]
1
244
#include <iostream> using namespace std; int main() { int a; cin >> a; if (a == 1) cout << "1" << endl; else if (a == 2) cout << "2" << endl; else if (a == 3) cout << "4" << endl; else if (a == 4) cout << "6" << endl; else if (a == 5) cout << "12" << endl; else if (a == 6) cout << "12" << endl; else if (a == 7) cout << "24" << endl; else if (a == 8) cout << "24" << endl; else if (a == 9) cout << "36" << endl; else if (a == 10) cout << "48" << endl; else if (a == 11) cout << "60" << endl; else if (a == 12) cout << "60" << endl; }
#include <iostream> using namespace std; int main() { int a; cin >> a; if (a == 1) cout << "1" << endl; else if (a == 2) cout << "2" << endl; else if (a == 3) cout << "4" << endl; else if (a == 4) cout << "6" << endl; else if (a == 5) cout << "16" << endl; else if (a == 6) cout << "12" << endl; else if (a == 7) cout << "64" << endl; else if (a == 8) cout << "24" << endl; else if (a == 9) cout << "36" << endl; else if (a == 10) cout << "48" << endl; else if (a == 11) cout << "1024" << endl; else if (a == 12) cout << "60" << endl; }
[["-", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 64, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
198
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int count = 0; for (int n = 1; n < 10000; n++) { for (int i = 1; i < 1000; i++) { if (n % i == 0) count++; } if (N == count) { cout << n << endl; return 0; } count = 0; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int count = 0; for (int n = 1; n < 10000; n++) { for (int i = 1; i < 10000; i++) { if (n % i == 0) count++; } if (N == count) { cout << n << endl; return 0; } count = 0; } return 0; }
[["-", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 7, 8, 9, 0, 7, 15, 16, 12, 13]]
1
91
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i = 0; cin >> n; while (1) { m = 0; i++; for (int j = 1; j < 13; j++) { if (i % j == 0) { m++; } } if (m == n) { cout << i << endl; break; } } }
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i = 0; cin >> n; while (1) { m = 0; i++; for (int j = 1; j < 100000; j++) { if (i % j == 0) { m++; } } if (m == n) { cout << i << endl; break; } } }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 12, 13]]
1
83
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; if (N == 1) cout << 1 << endl; else if (N == 2) cout << 2 << endl; else if (N == 3) cout << 4 << endl; else if (N == 4) cout << 6 << endl; else if (N == 5) cout << 16 << endl; else if (N == 6) cout << 12 << endl; else if (N == 7) cout << 64 << endl; else if (N == 8) cout << 24 << endl; else if (N == 9) cout << 36 << endl; else if (N == 10) cout << 48 << endl; else if (N == 11) cout << 1024 << endl; else if (N == 12) cout << 72 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; if (N == 1) cout << 1 << endl; else if (N == 2) cout << 2 << endl; else if (N == 3) cout << 4 << endl; else if (N == 4) cout << 6 << endl; else if (N == 5) cout << 16 << endl; else if (N == 6) cout << 12 << endl; else if (N == 7) cout << 64 << endl; else if (N == 8) cout << 24 << endl; else if (N == 9) cout << 36 << endl; else if (N == 10) cout << 48 << endl; else if (N == 11) cout << 1024 << endl; else if (N == 12) cout << 60 << endl; }
[["-", 0, 57, 64, 1, 0, 16, 31, 16, 12, 13], ["+", 0, 57, 64, 1, 0, 16, 31, 16, 12, 13]]
1
174
require "prime" def num(x) Prime.prime_division(x).inject(1) { |s, x| s * (x[1] + 1) } end n = gets.to_i puts (1..1000).find { |x| num(x) == n }
require "prime" def num(x) Prime.prime_division(x).inject(1) { |s, x| s * (x[1] + 1) } end n = gets.to_i puts (1..10000).find { |x| num(x) == n }
[["-", 3, 4, 0, 652, 486, 739, 0, 475, 444, 612], ["+", 3, 4, 0, 652, 486, 739, 0, 475, 444, 612]]
4
62
h = { 1 => 1, 2 => 2, 3 => 2 ** 2, 4 => 2 * 3, 5 => 2 ** 4, 6 => 2 ** 2 * 3, 7 => 2 ** 6, 8 => 2 ** 3 * 3, 9 => 2 ** 2 * 3 ** 2, 10 => 2 ** 4 ** 3, 11 => 2 ** 10, 12 => 2 ** 2 * 3 * 5, } p h[gets.to_i]
h = { 1 => 1, 2 => 2, 3 => 2 ** 2, 4 => 2 * 3, 5 => 2 ** 4, 6 => 2 ** 2 * 3, 7 => 2 ** 6, 8 => 2 ** 3 * 3, 9 => 2 ** 2 * 3 ** 2, 10 => 2 ** 4 * 3, 11 => 2 ** 10, 12 => 2 ** 2 * 3 * 5, } p h[gets.to_i]
[["-", 12, 767, 0, 569, 51, 738, 12, 738, 17, 578], ["+", 0, 662, 12, 767, 0, 569, 51, 738, 17, 48]]
4
93
def solve(n): for i in range(1,100): cnt=0 for j in range(1,100): if i%j==0: cnt+=1 if cnt==n: return(i) while True: try: n=int(input()) print(solve(n)) except EOFError:break
def solve(n): for i in range(1,10000): cnt=0 for j in range(1,i+1): if i%j==0: cnt+=1 if cnt==n: return(i) while True: try: n=int(input()) print(solve(n)) except EOFError: break
[["-", 8, 196, 0, 7, 12, 652, 3, 4, 0, 612], ["+", 8, 196, 0, 7, 12, 652, 3, 4, 0, 612], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 31, 22], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612]]
5
72
print([0,1,2,4,6,16,12,64,30,36,48,1024,60][int(input())])
print([0,1,2,4,6,16,12,64,24,36,48,1024,60][int(input())])
[["-", 0, 652, 3, 4, 0, 206, 51, 634, 0, 612], ["+", 0, 652, 3, 4, 0, 206, 51, 634, 0, 612]]
5
38
#include <iostream> using namespace std; #define rep(i, a) for (int i = 0; i < a; i++) int main(void) { int M[10][3]; int n, a, d, m, k; cin >> n >> a >> d >> m; rep(i, m) { rep(j, 3) cin >> M[i][j]; } cin >> k; for (int i = m - 1; i >= 0; i--) { // rep(j,3)cout<<M[i][j]<<" "; // cout<<endl; if (M[i][1] == k || M[i][2] == k) { if (M[i][0] == 0) { // 1 true k = M[i][2]; } else { // 0 false if (M[i][1] == k) { k = M[i][2]; } else { k = M[i][1]; } } } //*/ } cout << a + d * (k - 1) << endl; }
#include <iostream> using namespace std; #define rep(i, a) for (int i = 0; i < a; i++) int main(void) { int M[10][3]; int n, a, d, m, k; cin >> n >> a >> d >> m; rep(i, m) { rep(j, 3) cin >> M[i][j]; } cin >> k; for (int i = m - 1; i >= 0; i--) { // rep(j,3)cout<<M[i][j]<<" "; // cout<<endl; if (M[i][1] == k || M[i][2] == k) { if (M[i][0]) { // 1 true k = M[i][2]; } else { // 0 false if (M[i][1] == k) { k = M[i][2]; } else { k = M[i][1]; } } } //*/ } cout << a + d * (k - 1) << endl; }
[["-", 64, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["-", 64, 9, 0, 57, 15, 339, 51, 16, 12, 13]]
1
204
#include <bits/stdc++.h> using namespace std; int N, a, d, M; int F(int x) { return (a + (x - 1) * d); } int main() { cin >> N; cin >> a >> d; cin >> M; // ????????°???????????¬??? an = a + (n - 1)d map<int, int> foo; for (int i = 0; i < M; i++) { int x, y, z; cin >> x >> y >> z; map<int, int>::iterator A; int val1, val2; if ((A = foo.find(y)) == foo.end()) val1 = F(y); else val1 = A->second; if ((A = foo.find(z)) == foo.end()) val2 = F(z); else val2 = A->second; if (x == 0) { foo[y] = val2; foo[x] = val1; } else { foo[y] = val2; } } int K; cin >> K; map<int, int>::iterator A; int val1; if ((A = foo.find(K)) == foo.end()) val1 = F(K); else val1 = A->second; cout << val1 << endl; }
#include <bits/stdc++.h> using namespace std; int N, a, d, M; int F(int x) { return (a + (x - 1) * d); } int main() { cin >> N; cin >> a >> d; cin >> M; // ????????°???????????¬??? an = a + (n - 1)d map<int, int> foo; for (int i = 0; i < M; i++) { int x, y, z; cin >> x >> y >> z; map<int, int>::iterator A; int val1, val2; if ((A = foo.find(y)) == foo.end()) val1 = F(y); else val1 = A->second; if ((A = foo.find(z)) == foo.end()) val2 = F(z); else val2 = A->second; if (x == 0) { foo[y] = val2; foo[z] = val1; } else { foo[y] = val2; } } int K; cin >> K; map<int, int>::iterator A; int val1; if ((A = foo.find(K)) == foo.end()) val1 = F(K); else val1 = A->second; cout << val1 << endl; }
[["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22]]
1
268
#include <bits/stdc++.h> #define int long long using namespace std; string s, str; int p, ans, flag; char c[8] = {'0', '1', '+', '-', '*', '(', ')', '='}; char memo[400]; bool isalph(char ch) { return (('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z')); } int bnf(); int bnf3() { if (s[p] == ')') flag = 1; if (s[p] == '*' || s[p] == '+') flag = 1; if (s[p] == '(') { p++; if (p < s.size() && (s[p] == '*' || s[p] == '+')) flag = 1; if (p < s.size() && s[p] == ')') flag = 1; int r = bnf(); if (p >= s.size() || s[p] != ')') flag = 1; p++; if (p < s.size() && s[p] == '(') flag = 1; if (p < s.size() && '0' <= s[p] && s[p] <= '1') flag = 1; return r; } int res = 0, minu = 0; if (s[p] == '0' && p + 1 < s.size() && (s[p + 1] == '0' || s[p + 1] == '1')) flag = 1; if (s[p] == '-') { while (s[p] == '-') minu++, p++; if (s[p] == '(') { p++; int r = bnf(); p++; if (minu % 2) r *= -1; return r; } else if (!('0' <= s[p] && s[p] <= '1')) flag = 1; } else if (!('0' <= s[p] && s[p] <= '1')) flag = 1; while ('0' <= s[p] && s[p] <= '1') res = res * 2 + s[p] - '0', p++; if (s[p] == '(') flag = 1; if (minu % 2) res *= -1; return res; } int bnf2() { int res = bnf3(); while (p < s.size()) { if (s[p] == '*') { p++; if (s[p] == ')' || s[p] == '*' || s[p] == '+') flag = 1; int r = bnf3(); res *= r; } else break; } return res; } int bnf() { int res = bnf2(); while (p < s.size()) { if (s[p] == '+') { p++; if (s[p] == ')' || s[p] == '+' || s[p] == '*') flag = 1; int r = bnf2(); res += r; } else if (s[p] == '-') { p++; if (s[p] == ')' || s[p] == '*' || s[p] == '+') flag = 1; int r = bnf2(); res -= r; } else break; } return res; } void check() { int cnt = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == '(') cnt++; if (s[i] == ')') { if (cnt == 0) { flag = 1; return; } else cnt--; } } if (cnt) flag = 1; } set<string> me; void solve() { set<char> S; for (int i = 0; i < s.size(); i++) if (isalph(s[i])) S.insert(s[i]); set<char>::iterator ite = S.begin(); vector<char> al; while (ite != S.end()) { al.push_back((*ite)); ite++; } if (al.size() > 8) { cout << 0 << endl; return; } int idx[8]; for (int i = 0; i < 8; i++) idx[i] = i; do { for (int i = 0; i < al.size(); i++) memo[al[i]] = c[idx[i]]; s = ""; for (int i = 0; i < str.size(); i++) { if (S.count(str[i])) s += memo[str[i]]; else s += str[i]; } if (me.count(s)) continue; me.insert(s); int cnt = 0; for (int i = 0; i < s.size(); i++) if (s[i] == '=') cnt++; if (cnt != 1) continue; string s1, s2; for (int i = 0; i < s.size(); i++) { if (s[i] == '=') break; s1 += s[i]; } int f = 0; for (int i = 0; i < s.size(); i++) { if (f) s2 += s[i]; if (s[i] == '=') f = 1; } flag = 0; s = s1; p = 0; int r1 = bnf(); if (p != s.size()) flag = 1; check(); s = s2; p = 0; int r2 = bnf(); if (p != s.size()) flag = 1; check(); if (!flag && s1.size() && s2.size() && r1 == r2) { // cout<<s1<<' '<<s2<<endl; ans++; } } while (next_permutation(idx, idx + 8)); } main() { cin >> s; str = s; solve(); cout << ans << endl; }
#include <bits/stdc++.h> #define int long long using namespace std; string s, str; int p, ans, flag; char c[8] = {'0', '1', '+', '-', '*', '(', ')', '='}; char memo[400]; bool isalph(char ch) { return (('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z')); } int bnf(); int bnf3() { if (s[p] == ')') flag = 1; if (s[p] == '*' || s[p] == '+') flag = 1; if (s[p] == '(') { p++; if (p < s.size() && (s[p] == '*' || s[p] == '+')) flag = 1; if (p < s.size() && s[p] == ')') flag = 1; int r = bnf(); if (p >= s.size() || s[p] != ')') flag = 1; p++; if (p < s.size() && s[p] == '(') flag = 1; if (p < s.size() && '0' <= s[p] && s[p] <= '1') flag = 1; return r; } int res = 0, minu = 0; if (s[p] == '0' && p + 1 < s.size() && (s[p + 1] == '0' || s[p + 1] == '1')) flag = 1; if (s[p] == '-') { while (s[p] == '-') minu++, p++; if (s[p] == '(') { p++; int r = bnf(); p++; if (minu % 2) r *= -1; return r; } else if (!('0' <= s[p] && s[p] <= '1')) flag = 1; } else if (!('0' <= s[p] && s[p] <= '1')) flag = 1; while ('0' <= s[p] && s[p] <= '1') res = res * 2 + s[p] - '0', p++; if (s[p] == '(') flag = 1; if (minu % 2) res *= -1; return res; } int bnf2() { int res = bnf3(); while (p < s.size()) { if (s[p] == '*') { p++; if (s[p] == ')' || s[p] == '*' || s[p] == '+') flag = 1; int r = bnf3(); res *= r; } else break; } return res; } int bnf() { int res = bnf2(); while (p < s.size()) { if (s[p] == '+') { p++; if (s[p] == ')' || s[p] == '+' || s[p] == '*') flag = 1; int r = bnf2(); res += r; } else if (s[p] == '-') { p++; if (s[p] == ')' || s[p] == '*' || s[p] == '+') flag = 1; int r = bnf2(); res -= r; } else break; } return res; } void check() { int cnt = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == '(') cnt++; if (s[i] == ')') { if (cnt == 0) { flag = 1; return; } else cnt--; } } if (cnt) flag = 1; } set<string> me; void solve() { set<char> S; for (int i = 0; i < s.size(); i++) if (isalph(s[i])) S.insert(s[i]); set<char>::iterator ite = S.begin(); vector<char> al; while (ite != S.end()) { al.push_back((*ite)); ite++; } if (al.size() > 8) { cout << 0 << endl; exit(0); } int idx[8]; for (int i = 0; i < 8; i++) idx[i] = i; do { for (int i = 0; i < al.size(); i++) memo[al[i]] = c[idx[i]]; s = ""; for (int i = 0; i < str.size(); i++) { if (S.count(str[i])) s += memo[str[i]]; else s += str[i]; } if (me.count(s)) continue; me.insert(s); int cnt = 0; for (int i = 0; i < s.size(); i++) if (s[i] == '=') cnt++; if (cnt != 1) continue; string s1, s2; for (int i = 0; i < s.size(); i++) { if (s[i] == '=') break; s1 += s[i]; } int f = 0; for (int i = 0; i < s.size(); i++) { if (f) s2 += s[i]; if (s[i] == '=') f = 1; } flag = 0; s = s1; p = 0; int r1 = bnf(); if (p != s.size()) flag = 1; check(); s = s2; p = 0; int r2 = bnf(); if (p != s.size()) flag = 1; check(); if (!flag && s1.size() && s2.size() && r1 == r2) { // cout<<s1<<' '<<s2<<endl; ans++; } } while (next_permutation(idx, idx + 8)); } main() { cin >> s; str = s; solve(); cout << ans << endl; }
[["-", 8, 9, 0, 57, 64, 9, 0, 37, 0, 38], ["+", 0, 57, 64, 9, 0, 1, 0, 2, 63, 22], ["+", 64, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 64, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 64, 9, 0, 1, 0, 2, 3, 4, 0, 25]]
1
1,427
#include <bits/stdc++.h> using namespace std; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; typedef pair<LL, LL> PLL; #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define EB emplace_back #define MP make_pair #define SZ(a) int((a).size()) #define SORT(c) sort((c).begin(), (c).end()) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define FF first #define SS second template <class S, class T> istream &operator>>(istream &is, pair<S, T> &p) { return is >> p.FF >> p.SS; } const double EPS = 1e-10; const double PI = acos(-1.0); const LL MOD = 1e9 + 7; void pl(set<int> &s, int i, int &lb) { while (true) { if (!s.count(i)) { s.insert(i); break; } s.erase(i); --i; } if (SZ(s) == 1 && s.count(0)) lb = 1e9 + 10; else while (s.count(lb)) ++lb; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); int N; cin >> N; int lb = 1; set<int> xs; REP(i, N) { int x; cin >> x; if (x < lb - 2 || (x == lb - 1 && SZ(xs) > lb - 1)) cout << "No" << endl; else { cout << "Yes" << endl; pl(xs, x, lb); } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; typedef pair<LL, LL> PLL; #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define EB emplace_back #define MP make_pair #define SZ(a) int((a).size()) #define SORT(c) sort((c).begin(), (c).end()) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define FF first #define SS second template <class S, class T> istream &operator>>(istream &is, pair<S, T> &p) { return is >> p.FF >> p.SS; } const double EPS = 1e-10; const double PI = acos(-1.0); const LL MOD = 1e9 + 7; void pl(set<int> &s, int i, int &lb) { while (true) { if (!s.count(i)) { s.insert(i); break; } s.erase(i); --i; } if (SZ(s) == 1 && s.count(0)) lb = 1e9 + 10; else while (s.count(lb)) ++lb; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); int N; cin >> N; int lb = 1; set<int> xs; REP(i, N) { int x; cin >> x; if (x < lb - 1 || (x == lb - 1 && SZ(xs) != lb - 1)) cout << "No" << endl; else { cout << "Yes" << endl; pl(xs, x, lb); } } return 0; }
[["-", 15, 339, 51, 16, 31, 16, 12, 16, 12, 13], ["+", 15, 339, 51, 16, 31, 16, 12, 16, 12, 13], ["-", 51, 16, 12, 23, 0, 16, 12, 16, 17, 47], ["+", 51, 16, 12, 23, 0, 16, 12, 16, 17, 79]]
1
369
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { int n; cin >> n; int x[n]; for (int i = 0; i < n; i++) scanf("%lld", x + i); set<int> s, u; for (int i = 0; i < n; i++) { if (s.count(0)) { cout << "No" << endl; continue; } int k = x[i], c = 0; while (s.count(k) && !u.count(k)) k--, c++; if (u.count(k)) { if ((int)s.size() == (int)u.size() + c) { s.insert(0); puts("Yes"); } else { puts("No"); for (int j = k; j <= x[i]; j++) u.insert(j); } continue; } if (k == 0) { if ((int)s.size() == c) { s.insert(0); puts("Yes"); } else { puts("No"); for (int j = k; j <= x[i]; j++) u.insert(j); } continue; } s.insert(k); puts("Yes"); for (int j = x[i]; j > k; j--) s.erase(j); } return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { int n; cin >> n; int x[n]; for (int i = 0; i < n; i++) scanf("%lld", x + i); set<int> s, u; for (int i = 0; i < n; i++) { if (s.count(0)) { cout << "No" << endl; continue; } int k = x[i], c = 0; while (s.count(k) && !u.count(k)) k--, c++; if (u.count(k)) { if ((int)s.size() == (int)u.size() + c - 1) { s.insert(0); puts("Yes"); } else { puts("No"); for (int j = k; j <= x[i]; j++) u.insert(j); } continue; } if (k == 0) { if ((int)s.size() == c) { s.insert(0); puts("Yes"); } else { puts("No"); for (int j = k; j <= x[i]; j++) u.insert(j); } continue; } s.insert(k); puts("Yes"); for (int j = x[i]; j > k; j--) s.erase(j); } return 0; }
[["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
1
332
#include <bits/stdc++.h> using namespace std; const int maxn = 5 * 1e5 + 12345; int num[maxn]; set<int> s; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &num[i]); int max_dep = 1; for (int i = 1; i <= n; i++) { if (s.count(0) >= 1) { printf("No\n"); continue; } int tmp_num = num[i]; while (s.count(max_dep)) { max_dep++; } if (max_dep - 1 < tmp_num) { printf("Yes\n"); } else if (max_dep - 1 > tmp_num) { printf("No\n"); continue; } else if (max_dep - 1 == tmp_num) { if (s.size() != max_dep - 1) { printf("No\n"); continue; } else { printf("Yes\n"); } } while (s.count(tmp_num)) s.erase(tmp_num--); s.insert(num[i]); } }
#include <bits/stdc++.h> using namespace std; const int maxn = 5 * 1e5 + 12345; int num[maxn]; set<int> s; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &num[i]); int max_dep = 1; for (int i = 1; i <= n; i++) { if (s.count(0) >= 1) { printf("No\n"); continue; } int tmp_num = num[i]; while (s.count(max_dep)) { max_dep++; } if (max_dep - 1 < tmp_num) { printf("Yes\n"); } else if (max_dep - 1 > tmp_num) { printf("No\n"); continue; } else if (max_dep - 1 == tmp_num) { if (s.size() != max_dep - 1) { printf("No\n"); continue; } else { printf("Yes\n"); } } while (s.count(tmp_num)) s.erase(tmp_num--); s.insert(tmp_num); } }
[["-", 0, 1, 0, 2, 3, 4, 0, 69, 28, 22], ["-", 0, 2, 3, 4, 0, 69, 341, 342, 0, 70], ["-", 0, 2, 3, 4, 0, 69, 341, 342, 0, 22], ["-", 0, 2, 3, 4, 0, 69, 341, 342, 0, 73], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
1
252
c=p=0;b=[0]*1000000 for _ in range(int(input())): x=int(input()) if (c==x and p!=x) or b[0]==1 or c>x:print('NO');continue print('YES') if x>=1000000:continue p+=1;b[x]+=1 while b[x]>1:p-=1;b[x]-=2;b[x-1]+=1;x-=1 while b[c+1]==1 and c<999999:c+=1
c=p=0;b=[0]*1000000 for _ in range(int(input())): x=int(input()) if (c==x and p!=x) or b[0]==1 or c>x:print('No');continue print('Yes') if x>=1000000:continue p+=1;b[x]+=1 while b[x]>1:p-=1;b[x]-=2;b[x-1]+=1;x-=1 while b[c+1]==1 and c<999999:c+=1
[["-", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6], ["+", 0, 1, 0, 652, 3, 4, 0, 557, 0, 6]]
5
134
import java.util.Scanner; public class Main { static final int MAX_L = 100; void run() { Scanner scan = new Scanner(System.in); int l = scan.nextInt(); int k = scan.nextInt(); long[] dp = new long[MAX_L + 1]; dp[0] = dp[1] = 1; for (int i = 2; i < l; i++) { long num = i - k - 1 < 0 ? 0 : dp[i - k - 1]; dp[i] = dp[i - 2] + num + 1; } dp[l] = dp[l - 1] + (l > k ? dp[l - k] : 0); System.out.println(dp[l]); } public static void main(String[] args) { new Main().run(); } }
import java.util.Scanner; public class Main { static final int MAX_L = 100; void run() { Scanner scan = new Scanner(System.in); int l = scan.nextInt(); int k = scan.nextInt(); long[] dp = new long[MAX_L + 1]; dp[0] = dp[1] = 1; for (int i = 2; i < l; i++) { long num = i - k - 1 < 0 ? 0 : dp[i - k - 1]; dp[i] = dp[i - 2] + num + 1; } dp[l] = dp[l - 1] + (l >= k ? dp[l - k] : 0); System.out.println(dp[l]); } public static void main(String[] args) { new Main().run(); } }
[["-", 12, 16, 12, 23, 0, 510, 15, 16, 17, 47], ["+", 12, 16, 12, 23, 0, 510, 15, 16, 17, 20]]
3
193
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <stack> #include <vector> using namespace std; const int maxN = 110; #define FORU(i, l, r) for (int i = l; i <= r; ++i) #define FORD(i, r, l) for (int i = r; i >= l; --i) #define REPU(i, r) for (int i = 0; i < r; ++i) #define F first #define S second #define PB push_back #define LL long long int f[maxN][2], res, l, k; int main() { cin >> l >> k; res = 0; f[0][0] = 1; FORU(i, 1, l) REPU(j, 2) { f[i][j] = f[i - 1][1 - j]; if (j && i >= k) f[i][j] += f[i - k][1 - j]; if (j) res += f[i][j]; } cout << res << endl; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <stack> #include <vector> using namespace std; const int maxN = 110; #define FORU(i, l, r) for (int i = l; i <= r; ++i) #define FORD(i, r, l) for (int i = r; i >= l; --i) #define REPU(i, r) for (int i = 0; i < r; ++i) #define F first #define S second #define PB push_back #define LL long long LL f[maxN][2], res; int l, k; int main() { cin >> l >> k; res = 0; f[0][0] = 1; FORU(i, 1, l) REPU(j, 2) { f[i][j] = f[i - 1][1 - j]; if (j && i >= k) f[i][j] += f[i - k][1 - j]; if (j) res += f[i][j]; } cout << res << endl; }
[["-", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40], ["+", 36, 36, 36, 36, 0, 30, 0, 43, 39, 78], ["-", 36, 36, 36, 36, 0, 30, 0, 43, 0, 21], ["+", 36, 36, 36, 36, 0, 30, 0, 43, 0, 35], ["+", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40]]
1
193
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; int l, k; unsigned long long int n = 0; unsigned long long int permutation(int n, int s, int t); int main() { scanf("%d %d", &l, &k); int thin = 2; int thick = k + 1; if (l == 1) { printf("1\n"); return 0; } n++; for (int i = 1; i <= l; i++) { int s = l - 1 - thin * i; if (s < 0) { break; } n++; } if (k > l) { printf("%llu\n", n); return 0; } n++; for (int i = 1; i <= l; i++) { int s = l - k - thick * i; if (s < 0) { break; } n++; } for (int i = 1; i <= l; i++) { int s = l - thick * i + 1; if (s < 0) { break; } for (int j = 1; j <= l; j++) { int t = s - thin * j; if (t < 0) { break; } n += permutation(i + j, i, j); } } printf("%llu\n", n); return 0; } unsigned long long int permutation(int n, int s, int t) { unsigned long long int sum = 1; double dsum = 0.000000000001; int mx = s - t > 0 ? s : t; int mn = t - s < 0 ? t : s; // printf("mx:%d, mn%d\n", mx, mn); for (int i = n; i >= mx + 1; i--) { dsum *= i; } if (mn < 2) { return (unsigned long long int)(dsum * 1000000000000); } for (int i = mn; i >= 2; i--) { dsum /= i; } sum = dsum * 1000000000000; // if (sum == 0) { // printf("i:%d, j:%d, %llu\n", s, t, sum); // } return sum; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; int l, k; unsigned long long int n = 0; unsigned long long int permutation(int n, int s, int t); int main() { scanf("%d %d", &l, &k); int thin = 2; int thick = k + 1; if (l == 1) { printf("1\n"); return 0; } n++; for (int i = 1; i <= l; i++) { int s = l - 1 - thin * i; if (s < 0) { break; } n++; } if (k > l) { printf("%llu\n", n); return 0; } n++; for (int i = 1; i <= l; i++) { int s = l - k - thick * i; if (s < 0) { break; } n++; } for (int i = 1; i <= l; i++) { int s = l - thick * i + 1; if (s < 0) { break; } for (int j = 1; j <= l; j++) { int t = s - thin * j; if (t < 0) { break; } n += permutation(i + j, i, j); } } printf("%llu\n", n); return 0; } unsigned long long int permutation(int n, int s, int t) { unsigned long long int sum = 1; long double dsum = 0.0000000001; int mx = s - t > 0 ? s : t; int mn = t - s < 0 ? t : s; // printf("mx:%d, mn%d\n", mx, mn); for (int i = n; i >= mx + 1; i--) { dsum *= i; } if (mn < 2) { return (unsigned long long int)(dsum * 10000000000); } for (int i = mn; i >= 2; i--) { dsum /= i; } sum = dsum * 10000000000; // if (sum == 0) { // printf("i:%d, j:%d, %llu\n", s, t, sum); // } return sum; }
[["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96], ["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 0, 37, 0, 74, 51, 23, 0, 16, 12, 13], ["+", 0, 37, 0, 74, 51, 23, 0, 16, 12, 13], ["-", 8, 9, 0, 1, 0, 11, 12, 16, 12, 13], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 12, 13]]
1
438
#include <iostream> using namespace std; int main(void) { int l, k; cin >> l; cin >> k; long long int b[l + 1]; long long int w[l + 1]; // b[i] : ちょうど高さが i で黒いチョコが一番上のものの場合の数 // w[i] : ちょうど高さが i で白いチョコが一番上のものの場合の数 b[1] = 1; w[1] = 0; if (k < l) { for (int i = 2; i <= k; i++) { b[i] = w[i - 1]; w[i] = b[i - 1]; } b[k] += 1; for (int i = k + 1; i <= l; i++) { b[i] = w[i - 1] + w[i - k]; w[i] = b[i - 1]; } } else { for (int i = 2; i <= l; i++) { b[i] = w[i - 1]; w[i] = b[i - 1]; } } long long int ans = 0; for (int i = 1; i <= l; i++) { ans += b[i]; } cout << ans << endl; }
#include <iostream> using namespace std; int main(void) { int l, k; cin >> l; cin >> k; long long int b[l + 1]; long long int w[l + 1]; b[1] = 1; w[1] = 0; if (k <= l) { for (int i = 2; i <= k; i++) { b[i] = w[i - 1]; w[i] = b[i - 1]; } b[k] += 1; for (int i = k + 1; i <= l; i++) { b[i] = w[i - 1] + w[i - k]; w[i] = b[i - 1]; } } else { for (int i = 2; i <= l; i++) { b[i] = w[i - 1]; w[i] = b[i - 1]; } } long long int ans = 0; for (int i = 1; i <= l; i++) { ans += b[i]; } cout << ans << endl; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19]]
1
245
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef pair<int, int> P; int x[16], y[16]; vector<P> v; int m; int Max = 0; bool used[16]; void dfs() { if (v.size() == m / 2) { int cnt = 0; rep(i, v.size()) for (int j = i + 1; j < v.size(); j++) { int a = x[v[i].first] - x[v[i].second], b = y[v[i].first] - y[v[i].second], c = x[v[j].first] - x[v[j].second], d = y[v[j].first] - y[v[j].second]; if (a * d == b * c) { cnt++; continue; } a = -a; b = -b; if (a * d == b * c) { cnt++; continue; } a = -a; b = -b; c = -c; d = -d; if (a * d == b * c) { cnt++; continue; } a = -a; b = -b; if (a * d == b * c) { cnt++; continue; } } Max = max(Max, cnt); return; } int i = 0; while (used[i]) i++; for (int j = i + 1; j < 16; j++) { if (!used[j]) { v.push_back(P(i, j)); used[i] = used[j] = true; dfs(); used[i] = used[j] = false; v.pop_back(); } } } int main() { scanf("%d", &m); rep(i, m) cin >> x[i] >> y[i]; dfs(); cout << Max << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef pair<int, int> P; int x[16], y[16]; vector<P> v; int m; int Max = 0; bool used[16]; void dfs() { if (v.size() == m / 2) { int cnt = 0; rep(i, v.size()) for (int j = i + 1; j < v.size(); j++) { int a = x[v[i].first] - x[v[i].second], b = y[v[i].first] - y[v[i].second], c = x[v[j].first] - x[v[j].second], d = y[v[j].first] - y[v[j].second]; if (a * d == b * c) { cnt++; continue; } a = -a; b = -b; if (a * d == b * c) { cnt++; continue; } a = -a; b = -b; c = -c; d = -d; if (a * d == b * c) { cnt++; continue; } a = -a; b = -b; if (a * d == b * c) { cnt++; continue; } } Max = max(Max, cnt); return; } int i = 0; while (used[i]) i++; for (int j = i + 1; j < m; j++) { if (!used[j]) { v.push_back(P(i, j)); used[i] = used[j] = true; dfs(); used[i] = used[j] = false; v.pop_back(); } } } int main() { scanf("%d", &m); rep(i, m) cin >> x[i] >> y[i]; dfs(); cout << Max << endl; }
[["-", 0, 14, 8, 9, 0, 7, 15, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 12, 22]]
1
454
#include <iostream> #include <queue> #include <vector> using namespace std; #define MAX_N 100 int x[MAX_N][MAX_N]; int Q, n; int y[MAX_N][MAX_N]; int z[MAX_N][MAX_N]; void Rotate(int a, int b, int c, int d) { for (int i = 0; i < MAX_N; i++) { for (int j = 0; j < MAX_N; j++) { y[i][j] = 0; z[i][j] = 0; } } for (int i = a; i < a + c; i++) { for (int j = b; j < b + c; j++) { y[i - a][j - b] = x[i][j]; } } for (int i = 0; i < d / 90; i++) { for (int j = 0; j < c; j++) { for (int k = 0; k < c; k++) { z[k][c - 1 - j] = y[j][k]; } } for (int j = 0; j < c; j++) { for (int k = 0; k < c; k++) { y[j][k] = z[j][k]; } } } for (int i = 0; i < c; i++) { for (int j = 0; j < c; j++) { x[i + a][j + b] = y[i][j]; } } } void Reversal(int a, int b, int c) { for (int i = 0; i < MAX_N; i++) { for (int j = 0; j < MAX_N; j++) { y[i][j] = 0; z[i][j] = 0; } } for (int i = a; i < a + c; i++) { for (int j = b; j < b + c; j++) { y[i - a][j - b] = x[i][j]; } } for (int i = 0; i < c; i++) { for (int j = 0; j < c; j++) { if (y[i][j] == 0) { y[i][j] = 1; } else { y[i][j] = 0; } } } for (int i = 0; i < c; i++) { for (int j = 0; j < c; j++) { x[i + a][j + b] = y[i][j]; } } } void Left_Shift(int a) { for (int i = 0; i < MAX_N; i++) { for (int j = 0; j < MAX_N; j++) { y[i][j] = 0; z[i][j] = 0; } } for (int i = 1; i <= n; i++) { y[0][i] = x[a][i]; } for (int i = 2; i <= n; i++) { z[0][i - 1] = y[0][i]; } z[0][n] = y[0][1]; for (int i = 1; i <= n; i++) { y[0][i] = z[0][i]; } for (int i = 1; i <= n; i++) { x[a][i] = y[0][i]; } } void Right_Shift(int a) { for (int i = 0; i < MAX_N; i++) { for (int j = 0; j < MAX_N; j++) { y[i][j] = 0; z[i][j] = 0; } } for (int i = 1; i <= n; i++) { y[0][i] = x[a][i]; } for (int i = 1; i <= n - 1; i++) { z[0][i + 1] = y[0][i]; } z[0][1] = y[0][n]; for (int i = 1; i <= n; i++) { y[0][i] = z[0][i]; } for (int i = 1; i <= n; i++) { x[a][i] = y[0][i]; } } void Island_Reversal(int a, int b) { for (int i = 0; i < MAX_N; i++) { for (int j = 0; j < MAX_N; j++) { y[i][j] = 0; z[i][j] = 0; } } queue<pair<int, int>> Q; while (!Q.empty()) { Q.pop(); } Q.push(make_pair(a, b)); y[a][b] = 1; while (!Q.empty()) { pair<int, int> q = Q.front(); Q.pop(); int c = q.first; int d = q.second; if (c >= 2) { if (x[c][d] == x[c - 1][d] && y[c - 1][d] == 0) { Q.push(make_pair(c - 1, d)); y[c - 1][d] = 1; } } if (d >= 2) { if (x[c][d] == x[c][d - 1] && y[c][d - 1] == 0) { Q.push(make_pair(c, d - 1)); y[c][d - 1] = 1; } } if (c < n) { if (x[c][d] == x[c + 1][d] && y[c + 1][d] == 0) { Q.push(make_pair(c + 1, d)); y[c + 1][d] = 1; } } if (d < n) { if (x[c][d] == x[c][d + 1] && y[c][d + 1] == 0) { Q.push(make_pair(c, d + 1)); y[c][d + 1] = 1; } } } for (int i = 0; i < MAX_N; i++) { for (int j = 0; j < MAX_N; j++) { if (y[i][j] == 1) { if (x[i][j] == 0) { x[i][j] = 1; } else { x[i][j] = 0; } } } } } int main() { cin >> n >> Q; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cin >> x[i][j]; } } for (int i = 0; i < Q; i++) { int E1 = 0, E2 = 0, E3 = 0, E4 = 0, E5 = 0; cin >> E1; if (E1 == 0) { cin >> E2 >> E3 >> E4 >> E5; Rotate(E2, E3, E4, E5); } if (E1 == 1) { cin >> E2 >> E3 >> E4; Reversal(E2, E3, E4); } if (E1 == 2) { cin >> E2; Left_Shift(E2); } if (E1 == 3) { cin >> E2; Right_Shift(E3); } if (E1 == 4) { cin >> E2 >> E3; Island_Reversal(E2, E3); } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (j >= 2) { cout << ' '; } cout << x[i][j]; } cout << endl; } return 0; }
#include <iostream> #include <queue> #include <vector> using namespace std; #define MAX_N 100 int x[MAX_N][MAX_N]; int Q, n; int y[MAX_N][MAX_N]; int z[MAX_N][MAX_N]; void Rotate(int a, int b, int c, int d) { for (int i = 0; i < MAX_N; i++) { for (int j = 0; j < MAX_N; j++) { y[i][j] = 0; z[i][j] = 0; } } for (int i = a; i < a + c; i++) { for (int j = b; j < b + c; j++) { y[i - a][j - b] = x[i][j]; } } for (int i = 0; i < d / 90; i++) { for (int j = 0; j < c; j++) { for (int k = 0; k < c; k++) { z[k][c - 1 - j] = y[j][k]; } } for (int j = 0; j < c; j++) { for (int k = 0; k < c; k++) { y[j][k] = z[j][k]; } } } for (int i = 0; i < c; i++) { for (int j = 0; j < c; j++) { x[i + a][j + b] = y[i][j]; } } } void Reversal(int a, int b, int c) { for (int i = 0; i < MAX_N; i++) { for (int j = 0; j < MAX_N; j++) { y[i][j] = 0; z[i][j] = 0; } } for (int i = a; i < a + c; i++) { for (int j = b; j < b + c; j++) { y[i - a][j - b] = x[i][j]; } } for (int i = 0; i < c; i++) { for (int j = 0; j < c; j++) { if (y[i][j] == 0) { y[i][j] = 1; } else { y[i][j] = 0; } } } for (int i = 0; i < c; i++) { for (int j = 0; j < c; j++) { x[i + a][j + b] = y[i][j]; } } } void Left_Shift(int a) { for (int i = 0; i < MAX_N; i++) { for (int j = 0; j < MAX_N; j++) { y[i][j] = 0; z[i][j] = 0; } } for (int i = 1; i <= n; i++) { y[0][i] = x[a][i]; } for (int i = 2; i <= n; i++) { z[0][i - 1] = y[0][i]; } z[0][n] = y[0][1]; for (int i = 1; i <= n; i++) { y[0][i] = z[0][i]; } for (int i = 1; i <= n; i++) { x[a][i] = y[0][i]; } } void Right_Shift(int a) { for (int i = 0; i < MAX_N; i++) { for (int j = 0; j < MAX_N; j++) { y[i][j] = 0; z[i][j] = 0; } } for (int i = 1; i <= n; i++) { y[0][i] = x[a][i]; } for (int i = 1; i <= n - 1; i++) { z[0][i + 1] = y[0][i]; } z[0][1] = y[0][n]; for (int i = 1; i <= n; i++) { y[0][i] = z[0][i]; } for (int i = 1; i <= n; i++) { x[a][i] = y[0][i]; } } void Island_Reversal(int a, int b) { for (int i = 0; i < MAX_N; i++) { for (int j = 0; j < MAX_N; j++) { y[i][j] = 0; z[i][j] = 0; } } queue<pair<int, int>> Q; while (!Q.empty()) { Q.pop(); } Q.push(make_pair(a, b)); y[a][b] = 1; while (!Q.empty()) { pair<int, int> q = Q.front(); Q.pop(); int c = q.first; int d = q.second; if (c >= 2) { if (x[c][d] == x[c - 1][d] && y[c - 1][d] == 0) { Q.push(make_pair(c - 1, d)); y[c - 1][d] = 1; } } if (d >= 2) { if (x[c][d] == x[c][d - 1] && y[c][d - 1] == 0) { Q.push(make_pair(c, d - 1)); y[c][d - 1] = 1; } } if (c < n) { if (x[c][d] == x[c + 1][d] && y[c + 1][d] == 0) { Q.push(make_pair(c + 1, d)); y[c + 1][d] = 1; } } if (d < n) { if (x[c][d] == x[c][d + 1] && y[c][d + 1] == 0) { Q.push(make_pair(c, d + 1)); y[c][d + 1] = 1; } } } for (int i = 0; i < MAX_N; i++) { for (int j = 0; j < MAX_N; j++) { if (y[i][j] == 1) { if (x[i][j] == 0) { x[i][j] = 1; } else { x[i][j] = 0; } } } } } int main() { cin >> n >> Q; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cin >> x[i][j]; } } for (int i = 0; i < Q; i++) { int E1 = 0, E2 = 0, E3 = 0, E4 = 0, E5 = 0; cin >> E1; if (E1 == 0) { cin >> E2 >> E3 >> E4 >> E5; Rotate(E2, E3, E4, E5); } if (E1 == 1) { cin >> E2 >> E3 >> E4; Reversal(E2, E3, E4); } if (E1 == 2) { cin >> E2; Left_Shift(E2); } if (E1 == 3) { cin >> E2; Right_Shift(E2); } if (E1 == 4) { cin >> E2 >> E3; Island_Reversal(E2, E3); } } for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (j >= 2) { cout << ' '; } cout << x[i][j]; } cout << endl; } return 0; }
[["-", 64, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["+", 64, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
1
1,777
#include <stdio.h> #pragma warning(disable : 4996) int n, q, a[16][16], b[16][16], com, r, c, s, z; void rec(int r_, int c_) { a[r_][c_] ^= 1; for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if (i * j == 0 && i + j && 0 <= r_ + i && r_ + i < n && 0 <= c_ + j && c_ + j < n && a[r_ + i][c_ + j] != a[r_][c_]) rec(r_ + i, c_ + j); } } } int main() { scanf("%d%d", &n, &q); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) scanf("%d", &a[i][j]); } for (int i = 0; i < q; i++) { scanf("%d%d", &com, &r), r--; switch (com) { case 0: scanf("%d%d%d", &c, &s, &z), c--; for (int i = 0; i < z / 90; i++) { for (int j = r; j < r + s; j++) { for (int k = c; k < c + s; k++) { b[j][k] = a[(s - 1 - (k - c) + r)][(j - r)]; } } for (int j = r; j < r + s; j++) { for (int k = c; k < c + s; k++) a[j][k] = b[j][k]; } } break; case 1: scanf("%d%d", &c, &s), c--; for (int i = r; i < r + s; i++) { for (int j = c; j < c + s; j++) a[i][j] ^= 1; } break; case 2: for (int i = 0; i < n; i++) b[r][i] = a[r][(i + 1) % n]; for (int i = 0; i < n; i++) a[r][i] = b[r][i]; break; case 3: for (int i = 0; i < n; i++) b[r][(i + 1) % n] = a[r][i]; for (int i = 0; i < n; i++) a[r][i] = b[r][i]; break; case 4: scanf("%d", &c), c--; rec(r, c); break; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) printf(j ? " %d" : "%d", a[i][j]); printf("\n"); } }
#include <stdio.h> #pragma warning(disable : 4996) int n, q, a[16][16], b[16][16], com, r, c, s, z; void rec(int r_, int c_) { a[r_][c_] ^= 1; for (int i = -1; i <= 1; i++) { for (int j = -1; j <= 1; j++) { if (i * j == 0 && i + j && 0 <= r_ + i && r_ + i < n && 0 <= c_ + j && c_ + j < n && a[r_ + i][c_ + j] != a[r_][c_]) rec(r_ + i, c_ + j); } } } int main() { scanf("%d%d", &n, &q); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) scanf("%d", &a[i][j]); } for (int i = 0; i < q; i++) { scanf("%d%d", &com, &r), r--; switch (com) { case 0: scanf("%d%d%d", &c, &s, &z), c--; for (int i = 0; i < z / 90; i++) { for (int j = r; j < r + s; j++) { for (int k = c; k < c + s; k++) { b[j][k] = a[(s - 1 - (k - c) + r)][(j - r) + c]; } } for (int j = r; j < r + s; j++) { for (int k = c; k < c + s; k++) a[j][k] = b[j][k]; } } break; case 1: scanf("%d%d", &c, &s), c--; for (int i = r; i < r + s; i++) { for (int j = c; j < c + s; j++) a[i][j] ^= 1; } break; case 2: for (int i = 0; i < n; i++) b[r][i] = a[r][(i + 1) % n]; for (int i = 0; i < n; i++) a[r][i] = b[r][i]; break; case 3: for (int i = 0; i < n; i++) b[r][(i + 1) % n] = a[r][i]; for (int i = 0; i < n; i++) a[r][i] = b[r][i]; break; case 4: scanf("%d", &c), c--; rec(r, c); break; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) printf(j ? " %d" : "%d", a[i][j]); printf("\n"); } }
[["+", 0, 11, 12, 69, 341, 342, 0, 16, 17, 72], ["+", 0, 11, 12, 69, 341, 342, 0, 16, 12, 22]]
1
708
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i)) #define each(itr, c) \ for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); ++itr) #define all(x) (x).begin(), (x).end() #define mp make_pair #define pb push_back #define fi first #define se second typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pi; int main() { int n, m; cin >> n >> m; vvi a(n, vi(n)); rep(i, n) rep(j, n) cin >> a[i][j]; // query rep(M, m) { int op; scanf(" %d", &op); vvi b(a); if (op == 0) { int r, c, size, angle; scanf(" %d %d %d %d", &r, &c, &size, &angle); --r; --c; rep(T, angle / 90) { vvi t(b); for (int i = r; i < r + size; ++i) for (int j = c; j < c + size; ++j) t[r + (j - c)][r + size - 1 - (i - r)] = b[i][j]; for (int i = r; i < r + size; ++i) for (int j = c; j < c + size; ++j) b[i][j] = t[i][j]; } } else if (op == 1) { int r, c, size; scanf(" %d %d %d", &r, &c, &size); --r; --c; for (int i = r; i < r + size; ++i) for (int j = c; j < c + size; ++j) b[i][j] = !b[i][j]; } else if (op == 2) { int r; scanf(" %d", &r); --r; int tmp = b[r][0]; rep(i, n - 1) b[r][i] = b[r][i + 1]; b[r][n - 1] = tmp; } else if (op == 3) { int r; scanf(" %d", &r); --r; int tmp = b[r][n - 1]; for (int i = n - 1; i > 0; --i) b[r][i] = b[r][i - 1]; b[r][0] = tmp; } else { int r, c; scanf(" %d %d", &r, &c); --r; --c; int dr[4] = {1, -1, 0, 0}, dc[4] = {0, 0, 1, -1}; vvi vis(n, vi(n, 0)); vis[r][c] = 1; queue<pi> que; que.push(pi(r, c)); while (!que.empty()) { pi v = que.front(); que.pop(); rep(i, 4) { int nr = v.fi + dr[i], nc = v.se + dc[i]; if (0 <= nr && nr < n && 0 <= nc && nc < n) { if (!vis[nr][nc] && b[nr][nc] == b[r][c]) { vis[nr][nc] = 1; que.push(pi(nr, nc)); } } } } rep(i, n) rep(j, n) { if (vis[i][j]) b[i][j] = !b[i][j]; } } a = b; } // output rep(i, n) { rep(j, n) { if (j) printf(" "); printf("%d", a[i][j]); } printf("\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i)) #define each(itr, c) \ for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); ++itr) #define all(x) (x).begin(), (x).end() #define mp make_pair #define pb push_back #define fi first #define se second typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pi; int main() { int n, m; cin >> n >> m; vvi a(n, vi(n)); rep(i, n) rep(j, n) cin >> a[i][j]; // query rep(M, m) { int op; scanf(" %d", &op); vvi b(a); if (op == 0) { int r, c, size, angle; scanf(" %d %d %d %d", &r, &c, &size, &angle); --r; --c; rep(T, angle / 90) { vvi t(b); for (int i = r; i < r + size; ++i) for (int j = c; j < c + size; ++j) t[r + (j - c)][c + size - 1 - (i - r)] = b[i][j]; for (int i = r; i < r + size; ++i) for (int j = c; j < c + size; ++j) b[i][j] = t[i][j]; } } else if (op == 1) { int r, c, size; scanf(" %d %d %d", &r, &c, &size); --r; --c; for (int i = r; i < r + size; ++i) for (int j = c; j < c + size; ++j) b[i][j] = !b[i][j]; } else if (op == 2) { int r; scanf(" %d", &r); --r; int tmp = b[r][0]; rep(i, n - 1) b[r][i] = b[r][i + 1]; b[r][n - 1] = tmp; } else if (op == 3) { int r; scanf(" %d", &r); --r; int tmp = b[r][n - 1]; for (int i = n - 1; i > 0; --i) b[r][i] = b[r][i - 1]; b[r][0] = tmp; } else { int r, c; scanf(" %d %d", &r, &c); --r; --c; int dr[4] = {1, -1, 0, 0}, dc[4] = {0, 0, 1, -1}; vvi vis(n, vi(n, 0)); vis[r][c] = 1; queue<pi> que; que.push(pi(r, c)); while (!que.empty()) { pi v = que.front(); que.pop(); rep(i, 4) { int nr = v.fi + dr[i], nc = v.se + dc[i]; if (0 <= nr && nr < n && 0 <= nc && nc < n) { if (!vis[nr][nc] && b[nr][nc] == b[r][c]) { vis[nr][nc] = 1; que.push(pi(nr, nc)); } } } } rep(i, n) rep(j, n) { if (vis[i][j]) b[i][j] = !b[i][j]; } } a = b; } // output rep(i, n) { rep(j, n) { if (j) printf(" "); printf("%d", a[i][j]); } printf("\n"); } return 0; }
[["-", 341, 342, 0, 16, 31, 16, 31, 16, 31, 22], ["+", 341, 342, 0, 16, 31, 16, 31, 16, 31, 22]]
1
890
#include <iostream> #include <string> using namespace std; char C[63] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; int convert(int p, string S) { int power[20]; power[0] = 0; for (int i = 1; i <= S.size(); i++) power[i] = power[i - 1] * p; int cnt = 0; for (int i = 0; i < S.size(); i++) { for (int j = 0; j < p; j++) { if (C[j] != S[i]) continue; cnt += power[S.size() - 1 - i] * j; } } return cnt; } int main() { int n; cin >> n; int W = 0; for (int i = 0; i < n; i++) { string U; int a; cin >> a >> U; a = convert(a, U); W ^= a; } if (W == 0) cout << "lose" << endl; else cout << "win" << endl; return 0; }
#include <iostream> #include <string> using namespace std; char C[63] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; int convert(int p, string S) { int power[20]; power[0] = 1; for (int i = 1; i <= S.size(); i++) power[i] = power[i - 1] * p; int cnt = 0; for (int i = 0; i < S.size(); i++) { for (int j = 0; j < p; j++) { if (C[j] != S[i]) continue; cnt += power[S.size() - 1 - i] * j; } } return cnt; } int main() { int n; cin >> n; int W = 0; for (int i = 0; i < n; i++) { string U; int a; cin >> a >> U; a = convert(a, U); W ^= a; } if (W == 0) cout << "lose" << endl; else cout << "win" << endl; return 0; }
[["-", 0, 14, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 12, 13]]
1
234
#include <bits/stdc++.h> using namespace std; long long po(long long p, long long n) { long long res = 1; for (int i = 0; i < n; i++) { res *= p; } return res; } int main() { long long n; cin >> n; vector<long long> a(n); for (int ii = 0; ii < n; ii++) { int p; cin >> p; string m; cin >> m; long long num = 0; int len = (int)m.size(); for (int i = 0; i < len; i++) { int idx = len - 1 - i; char c = m[idx]; long long aa; if ('A' <= c && c <= 'Z') aa = (long long)(10 + c - 'A'); else if ('a' <= c && c <= 'Z') aa = (long long)(36 + c - 'Z'); else aa = (long long)(c - '0'); a[ii] += aa * po(p, i); } } /*for(int i = 0; i < n; i++){ cout << a[i] << endl; }*/ int num = 0; for (int i = 0; i < n; i++) { bool is_pre = false; while (a[i] != 0) { if (a[i] % 2 == 1) { num++; if (is_pre == true) { cout << "win" << endl; return 0; } a[i] /= 2; is_pre = true; } else { is_pre = false; a[i] /= 2; } } } if (num % 2 == 1) cout << "win" << endl; else cout << "no" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long po(long long p, long long n) { long long res = 1; for (int i = 0; i < n; i++) { res *= p; } return res; } int main() { long long n; cin >> n; vector<long long> a(n); for (int ii = 0; ii < n; ii++) { int p; cin >> p; string m; cin >> m; long long num = 0; int len = (int)m.size(); for (int i = 0; i < len; i++) { int idx = len - 1 - i; char c = m[idx]; long long aa; if ('A' <= c && c <= 'Z') aa = (long long)(10 + c - 'A'); else if ('a' <= c && c <= 'Z') aa = (long long)(36 + c - 'Z'); else aa = (long long)(c - '0'); a[ii] += aa * po(p, i); } } /*for(int i = 0; i < n; i++){ cout << a[i] << endl; }*/ int num = 0; for (int i = 0; i < n; i++) { bool is_pre = false; while (a[i] != 0) { if (a[i] % 2 == 1) { num++; if (is_pre == true) { cout << "win" << endl; return 0; } a[i] /= 2; is_pre = true; } else { is_pre = false; a[i] /= 2; } } } if (num % 2 == 1) cout << "win" << endl; else cout << "lose" << endl; return 0; }
[["-", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6], ["+", 0, 1, 0, 16, 31, 16, 12, 5, 0, 6]]
1
374
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; ll N, Q, x, y, z; P s, t; char str[20]; P a[300005]; ll b[300005]; ll C; P find(ll x) { if (a[x].first == -1) return P(x, 0); P res = find(a[x].first); res.second += a[x].second; return a[x] = res; } void init() { for (int i = 0; i < 300005; i++) { a[i] = P(-1, 0); b[i] = i; } C = 100001; } int main() { init(); cin >> N >> Q; for (int i = 0; i < Q; i++) { scanf("%s", str); if (str[0] == 'C') { scanf("%lld %lld", &x, &y); x = b[x]; y = b[y]; s = find(x); t = find(y); if (s.first != t.first) printf("WORNING\n"); else { printf("%lld\n", s.second - t.second); } } else { scanf("%lld %lld %lld", &x, &y, &z); a[C] = a[b[x]]; if (a[C].first != -1) a[C].second -= z; a[b[x]] = P(C, z); b[x] = C++; a[C] = a[b[y]]; if (a[C].first != -1) a[C].second -= z; a[b[y]] = P(C, z); b[y] = C++; x = b[x]; y = b[y]; s = find(x); t = find(y); if (s.first != t.first) { a[s.first].first = t.first; a[s.first].second = z + t.second - s.second; } } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; ll N, Q, x, y, z; P s, t; char str[20]; P a[300005]; ll b[300005]; ll C; P find(ll x) { if (a[x].first == -1) return P(x, 0); P res = find(a[x].first); res.second += a[x].second; return a[x] = res; } void init() { for (int i = 0; i < 300005; i++) { a[i] = P(-1, 0); b[i] = i; } C = 100001; } int main() { init(); cin >> N >> Q; for (int i = 0; i < Q; i++) { scanf("%s", str); if (str[0] == 'C') { scanf("%lld %lld", &x, &y); x = b[x]; y = b[y]; s = find(x); t = find(y); if (s.first != t.first) printf("WARNING\n"); else { printf("%lld\n", s.second - t.second); } } else { scanf("%lld %lld %lld", &x, &y, &z); a[C] = a[b[x]]; if (a[C].first != -1) a[C].second -= z; a[b[x]] = P(C, z); b[x] = C++; a[C] = a[b[y]]; if (a[C].first != -1) a[C].second -= z; a[b[y]] = P(C, z); b[y] = C++; x = b[x]; y = b[y]; s = find(x); t = find(y); if (s.first != t.first) { a[s.first].first = t.first; a[s.first].second = z + t.second - s.second; } } } return 0; }
[["-", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 64, 1, 0, 2, 3, 4, 0, 5, 0, 6]]
1
499
#include <cmath> #include <complex> #include <iostream> #include <vector> using namespace std; typedef complex<double> P; typedef pair<P, double> C; #define X real() #define Y imag() const double pi = acos(-1), EPS = (1e-10); double dot(P a, P b) { return a.X * b.X + a.Y * b.Y; } vector<P> cpcc(C a, C b) { //円と円の交点 double d = abs(a.first - b.first), ra = a.second, rb = b.second; double t = (ra * ra - rb * rb + d * d) / 2 / d, h = sqrt(ra * ra - t * t); P m = t / abs(b.first - a.first) * (b.first - a.first) + a.first; vector<P> cp(2, m); P n = (a.first - b.first) * P(0, 1); n /= abs(n); cp[0] -= h * n; cp[1] += h * n; return cp; } vector<P> tangent_to_C(P p, C c) { //点pから円cに伸ばした接線の接点を求める C c2 = C((p + c.first) / 2.0, abs(p - c.first) / 2.0); return cpcc(c, c2); } bool in_sector(P c, double r, double theta, double a, double b) { if (abs(c) < r - EPS) return false; if (abs(c) + r > a + EPS) return false; vector<P> cps = tangent_to_C(P(0, 0), C(c, r)); if (cps.empty()) return false; P d = P(cos(b), sin(b)); for (int i = 0; i < (int)cps.size(); ++i) { P cp = cps[i]; if (dot(cp, d) / abs(cp) < cos(theta / 2) - EPS) return false; } return true; } void dfs(vector<vector<int>> &G, int v, vector<int> &P, vector<int> &R, int t) { for (int i = 0; i < (int)G[v].size(); ++i) { int v_ = G[v][i]; int d = min(P[v_], R[v_] + t) - R[v_]; R[v_] += d; // for(int i = 0; i < (int)R.size(); ++i) cout << R[i] << " ";cout << endl; if (d > 0) dfs(G, v_, P, R, d); } } int solve(vector<vector<int>> &G, vector<int> P) { int n = G.size(); vector<int> R(n, 0); R[0] = P[0]; dfs(G, 0, P, R, R[0]); // for(int i = 0; i < n; ++i) cout << R[i] << " ";cout << endl; return R.back(); } int main() { int N; cin >> N; double theta, a; vector<int> Power(N + 2, 0); Power.back() = (int)1e9; cin >> theta >> a >> Power[0]; theta *= pi / 180.0; vector<P> L(N + 1); vector<double> R(N + 1), A(N), T(N), B(N); for (int i = 0; i < N; ++i) { double x, y; cin >> x >> y >> R[i] >> T[i] >> A[i] >> B[i] >> Power[i + 1]; L[i] = P(x, y); T[i] *= pi / 180.0; B[i] *= pi / 180.0; } double x, y; cin >> x >> y >> R[N]; L[N] = P(x, y); vector<vector<int>> G(N + 2); for (int i = 0; i < N; ++i) { for (int j = 0; j <= N; ++j) { if (i == j) continue; if (in_sector(L[j] - L[i], R[j], T[i], A[i], B[i])) { G[i + 1].push_back(j + 1); // cout << i << " " << j << endl; } } } int ans = 0; for (int i = 0; i <= N; ++i) { if (abs(L[i]) + R[i] > a) continue; if (abs(L[i]) - R[i] < EPS) continue; vector<P> cps = tangent_to_C(P(0, 0), C(L[i], R[i])); if (cps.empty()) continue; P cp = cps[0]; if (arg(cps[0]) > arg(cps[1])) swap(cps[0], cps[1]); double b = arg(cp * P(cos(theta / 2), sin(theta / 2))); G[0] = vector<int>(); for (int j = 0; j <= N; ++j) { if (in_sector(L[j], R[j], theta, a, b)) { G[0].push_back(j + 1); } } /* cout << "i = " << i << endl; for(int j = 0; j < N+2; ++j){ cout << j << " : "; for(int k = 0; k < (int)G[j].size(); ++k) cout << G[j][k] << " ";cout << endl; } cout << solve(G, Power) << endl; */ ans = max(ans, solve(G, Power)); } cout << ans << endl; return 0; }
#include <cmath> #include <complex> #include <iostream> #include <vector> using namespace std; typedef complex<double> P; typedef pair<P, double> C; #define X real() #define Y imag() const double pi = acos(-1), EPS = (1e-7); double dot(P a, P b) { return a.X * b.X + a.Y * b.Y; } vector<P> cpcc(C a, C b) { //円と円の交点 double d = abs(a.first - b.first), ra = a.second, rb = b.second; double t = (ra * ra - rb * rb + d * d) / 2 / d, h = sqrt(ra * ra - t * t); P m = t / abs(b.first - a.first) * (b.first - a.first) + a.first; vector<P> cp(2, m); P n = (a.first - b.first) * P(0, 1); n /= abs(n); cp[0] -= h * n; cp[1] += h * n; return cp; } vector<P> tangent_to_C(P p, C c) { //点pから円cに伸ばした接線の接点を求める C c2 = C((p + c.first) / 2.0, abs(p - c.first) / 2.0); return cpcc(c, c2); } bool in_sector(P c, double r, double theta, double a, double b) { if (abs(c) < r + EPS) return false; if (abs(c) + r > a + EPS) return false; vector<P> cps = tangent_to_C(P(0, 0), C(c, r)); if (cps.empty()) return false; P d = P(cos(b), sin(b)); for (int i = 0; i < (int)cps.size(); ++i) { P cp = cps[i]; if (dot(cp, d) / abs(cp) < cos(theta / 2) - EPS) return false; } return true; } void dfs(vector<vector<int>> &G, int v, vector<int> &P, vector<int> &R, int t) { for (int i = 0; i < (int)G[v].size(); ++i) { int v_ = G[v][i]; int d = min(P[v_], R[v_] + t) - R[v_]; R[v_] += d; // for(int i = 0; i < (int)R.size(); ++i) cout << R[i] << " ";cout << endl; if (d > 0) dfs(G, v_, P, R, d); } } int solve(vector<vector<int>> &G, vector<int> P) { int n = G.size(); vector<int> R(n, 0); R[0] = P[0]; dfs(G, 0, P, R, R[0]); // for(int i = 0; i < n; ++i) cout << R[i] << " ";cout << endl; return R.back(); } int main() { int N; cin >> N; double theta, a; vector<int> Power(N + 2, 0); Power.back() = (int)1e9; cin >> theta >> a >> Power[0]; theta *= pi / 180.0; vector<P> L(N + 1); vector<double> R(N + 1), A(N), T(N), B(N); for (int i = 0; i < N; ++i) { double x, y; cin >> x >> y >> R[i] >> T[i] >> A[i] >> B[i] >> Power[i + 1]; L[i] = P(x, y); T[i] *= pi / 180.0; B[i] *= pi / 180.0; } double x, y; cin >> x >> y >> R[N]; L[N] = P(x, y); vector<vector<int>> G(N + 2); for (int i = 0; i < N; ++i) { for (int j = 0; j <= N; ++j) { if (i == j) continue; if (in_sector(L[j] - L[i], R[j], T[i], A[i], B[i])) { G[i + 1].push_back(j + 1); // cout << i << " " << j << endl; } } } int ans = 0; for (int i = 0; i <= N; ++i) { if (abs(L[i]) + R[i] > a) continue; if (abs(L[i]) - R[i] < EPS) continue; vector<P> cps = tangent_to_C(P(0, 0), C(L[i], R[i])); if (cps.empty()) continue; P cp = cps[0]; if (arg(cps[0]) > arg(cps[1])) swap(cps[0], cps[1]); double b = arg(cp * P(cos(theta / 2), sin(theta / 2))); G[0] = vector<int>(); for (int j = 0; j <= N; ++j) { if (in_sector(L[j], R[j], theta, a, b)) { G[0].push_back(j + 1); } } /* cout << "i = " << i << endl; for(int j = 0; j < N+2; ++j){ cout << j << " : "; for(int k = 0; k < (int)G[j].size(); ++k) cout << G[j][k] << " ";cout << endl; } cout << solve(G, Power) << endl; */ ans = max(ans, solve(G, Power)); } cout << ans << endl; return 0; }
[["-", 0, 30, 0, 43, 49, 50, 51, 23, 0, 13], ["+", 0, 30, 0, 43, 49, 50, 51, 23, 0, 13], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 33], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 72]]
1
1,211
#include <iostream> using namespace std; int main() { int m, nmax, nmin, n, a; while (1) { n = 0; cin >> m >> nmin >> nmax; if (m == 0 && nmax == 0 && nmin == 0) break; int *p = new int[m]; for (int i = 0; i < m; i++) { cin >> p[i]; } for (int j = nmin; j < nmax; j++) { if (n <= p[j - 1] - p[j]) { n = p[j - 1] - p[j]; a = j; } } cout << a << endl; delete[] p; } return 0; }
#include <iostream> using namespace std; int main() { int m, nmax, nmin, n, a; while (1) { n = 0; cin >> m >> nmin >> nmax; if (m == 0 && nmax == 0 && nmin == 0) break; int *p = new int[m]; for (int i = 0; i < m; i++) { cin >> p[i]; } for (int j = nmin; j <= nmax; j++) { if (n <= p[j - 1] - p[j]) { n = p[j - 1] - p[j]; a = j; } } cout << a << endl; delete[] p; } return 0; }
[["-", 0, 52, 8, 9, 0, 7, 15, 16, 17, 18], ["+", 0, 52, 8, 9, 0, 7, 15, 16, 17, 19]]
1
156
#include <bits/stdc++.h> using namespace std; int main() { int m, nmin, nmax; while (cin >> m >> nmin >> nmax) { if (m == 0) return 0; int mx = 0, ans = 0, a[m + 5]; for (int i = 1; i <= m; i++) cin >> a[i]; for (int i = nmin; i <= nmax; i++) { if (a[i] - a[i + 1] >= mx) mx = a[i] - a[i - 1], ans = i; } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int m, nmin, nmax; while (cin >> m >> nmin >> nmax) { if (m == 0) return 0; int mx = 0, ans = 0, a[m + 5]; for (int i = 1; i <= m; i++) cin >> a[i]; for (int i = nmin; i <= nmax; i++) { if (a[i] - a[i + 1] >= mx) mx = abs(a[i] - a[i + 1]), ans = i; } // cout << mx << endl; cout << ans << endl; } }
[["+", 64, 1, 0, 34, 31, 11, 12, 2, 63, 22], ["+", 0, 34, 31, 11, 12, 2, 3, 4, 0, 24], ["-", 12, 16, 12, 69, 341, 342, 0, 16, 17, 33], ["+", 0, 16, 12, 69, 341, 342, 0, 16, 17, 72], ["+", 0, 34, 31, 11, 12, 2, 3, 4, 0, 25]]
1
133
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int m, min, max, su, gap, temp; vector<int> p; while (1) { cin >> m >> min >> max; if (m == 0 && min == 0 && max == 0) break; for (int i = 0; i < m; i++) { int P; cin >> P; p.push_back(P); } // sort(p.begin(), p.end(), greater<int>()); su = p[min - 1] - p[min]; gap = min; for (int i = min - 1; i < max; i++) { temp = p[i] - p[i + 1]; // cout << temp << ' ' << gap << endl; if (temp > su) { su = temp; gap = i + 1; } } cout << gap << endl; p.clear(); } return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { int m, min, max, su, gap, temp; vector<int> p; while (1) { cin >> m >> min >> max; if (m == 0 && min == 0 && max == 0) break; for (int i = 0; i < m; i++) { int P; cin >> P; p.push_back(P); } // sort(p.begin(), p.end(), greater<int>()); su = p[min - 1] - p[min]; gap = min; for (int i = min - 1; i < max; i++) { temp = p[i] - p[i + 1]; // cout << temp << ' ' << gap << endl; if (temp >= su) { su = temp; gap = i + 1; } } cout << gap << endl; p.clear(); } return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
1
180
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); while (1) { int m, nmin, nmax; cin >> m >> nmin >> nmax; if (m == 0) break; vector<int> p(m); for (int i = 0; i < m; i++) cin >> p[i]; int ans = 0, point = 0; for (int i = nmin; i <= nmax; i++) { int gap = p[i - 1] - p[i]; if (point < gap) { ans = i; point = gap; } } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); while (1) { int m, nmin, nmax; cin >> m >> nmin >> nmax; if (m == 0) break; vector<int> p(m); for (int i = 0; i < m; i++) cin >> p[i]; int ans = 0, point = 0; for (int i = nmin; i <= nmax; i++) { int gap = p[i - 1] - p[i]; if (point <= gap) { ans = i; point = gap; } } cout << ans << endl; } }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 19]]
1
147
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "../dump.hpp" #else #define dump(...) #endif #define rep(i, n) for (ll i = 0, i##_cond = (n); i < i##_cond; ++i) #define FOR(i, a, b) for (ll i = (a), i##_cond = (b); i < i##_cond; ++i) #define ROF(i, a, b) for (ll i = (a)-1, i##_cond = (b); i >= i##_cond; --i) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() // sortで大きい順 #define UNIQUE(v) v.erase(unique(all(v)), v.end()) #define SUM(a) accumulate(all(a), 0) #define sz(x) ((ll)(x).size()) #define pb push_back #define fst first #define snd second #define mp make_pair typedef long long ll; typedef vector<ll> vi; typedef vector<vi> vvi; typedef vector<string> vs; typedef pair<ll, ll> pii; const ll inf = 1ll << 62; const ll mod = 1e9 + 7; #define int ll main() { while (1) { int m, nmin, nmax; cin >> m >> nmin >> nmax; nmin--; nmax--; if (m == 0) break; vi p(m); rep(i, m) cin >> p[i]; int maxv = 0, pos; FOR(i, nmin, nmax + 1) { if (p[i] - p[i + 1] > maxv) { maxv = p[i] - p[i + 1]; pos = i; } } cout << pos + 1 << endl; } }
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "../dump.hpp" #else #define dump(...) #endif #define rep(i, n) for (ll i = 0, i##_cond = (n); i < i##_cond; ++i) #define FOR(i, a, b) for (ll i = (a), i##_cond = (b); i < i##_cond; ++i) #define ROF(i, a, b) for (ll i = (a)-1, i##_cond = (b); i >= i##_cond; --i) #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() // sortで大きい順 #define UNIQUE(v) v.erase(unique(all(v)), v.end()) #define SUM(a) accumulate(all(a), 0) #define sz(x) ((ll)(x).size()) #define pb push_back #define fst first #define snd second #define mp make_pair typedef long long ll; typedef vector<ll> vi; typedef vector<vi> vvi; typedef vector<string> vs; typedef pair<ll, ll> pii; const ll inf = 1ll << 62; const ll mod = 1e9 + 7; #define int ll main() { while (1) { int m, nmin, nmax; cin >> m >> nmin >> nmax; nmin--; nmax--; if (m == 0) break; vi p(m); rep(i, m) cin >> p[i]; int maxv = 0, pos; FOR(i, nmin, nmax + 1) { if (p[i] - p[i + 1] >= maxv) { maxv = p[i] - p[i + 1]; pos = i; } } cout << pos + 1 << endl; } }
[["-", 0, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
1
267
#!usr/bin/env python #-*- coding: utf-8 -*- while True: (m, nmin, nmax) = list(map(int, input().split())) if m == 0: break scores = [] for i in range(m): scores.append(int(input())) submax = 0 for i in range(nmin, nmax): subtmp = scores[i-1] - scores[i] if subtmp >= submax: ans = i submax = subtmp print(ans)
#!usr/bin/env python #-*- coding: utf-8 -*- while True: (m, nmin, nmax) = list(map(int, input().split())) if m == 0: break scores = [] for i in range(m): scores.append(int(input())) submax = 0 for i in range(nmin, nmax+1): subtmp = scores[i-1] - scores[i] if subtmp >= submax: ans = i submax = subtmp print(ans)
[["+", 0, 7, 12, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612]]
5
98
while 1: m,nn,nx= map(int,input().split()) if m==0: break s=[int(input()) for _ in range(m)] v=k=0 for i in range(nn-1,nx): t=s[i]-s[i+1] if v<t: k,v=i+1,t print(k)
while 1: m,nn,nx= map(int,input().split()) if m==0: break s=[int(input()) for _ in range(m)] v=k=0 for i in range(nn-1,nx): t=s[i]-s[i+1] if v<=t: k,v=i+1,t print(k)
[["-", 0, 7, 8, 196, 0, 57, 15, 666, 667, 18], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 667, 19]]
5
92
da = list(map(int,input().split())) k = [] while sum(da) != 0: for i in range(da[0]): k.append(int(input())) for i in range(da[0]): k[da[0] - 1 -i] = k[da[0] - 1 -i] - k[da[0]-2 -i] pp = k[da[1]:da[2]+1] print(pp) qq = min(pp) for i in range(len(pp)): if pp[i] == qq: jj = i print(da[1]+jj) da = list(map(int,input().split())) k = []
da = list(map(int,input().split())) k = [] while sum(da) != 0: for i in range(da[0]): k.append(int(input())) for i in range(da[0]): k[da[0] - 1 -i] = k[da[0] - 1 -i] - k[da[0]-2 -i] pp = k[da[1]:da[2]+1] qq = min(pp) for i in range(len(pp)): if pp[i] == qq: jj = i print(da[1]+jj) da = list(map(int,input().split())) k = []
[["-", 0, 52, 8, 196, 0, 1, 0, 652, 63, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 8, 196, 0, 1, 0, 652, 3, 4, 0, 25]]
5
175
import java.util.Scanner; public class Main { static int[] num; static int set; public static void main(String[] args) { Scanner scan = new Scanner(System.in); while (true) { set = scan.nextInt(); if (set == 0) break; String gomi = scan.nextLine(); String[] data = new String[set]; num = new int[set]; for (int i = 0; i < set; ++i) { data[i] = scan.nextLine(); num[i] = data[i].length(); } for (int i = 0; i < set; ++i) { int flag = 0, sum = 0, j = i; while (true) { if (i < set) { sum += num[j]; if (flag == 0 || flag == 2) { if (sum == 5) { sum = 0; flag += 1; } else if (sum < 5) { } else { break; } } else { if (sum == 7) { sum = 0; flag += 1; } else if (sum < 7) { } else { break; } } j++; } else { break; } if (flag == 5) { System.out.println(i + 1); return; } } } } } }
import java.util.Scanner; public class Main { static int[] num; static int set; public static void main(String[] args) { Scanner scan = new Scanner(System.in); while (true) { set = scan.nextInt(); if (set == 0) break; String gomi = scan.nextLine(); String[] data = new String[set]; num = new int[set]; for (int i = 0; i < set; ++i) { data[i] = scan.nextLine(); num[i] = data[i].length(); } for (int i = 0; i < set; ++i) { int flag = 0, sum = 0, j = i; while (true) { if (i < set) { sum += num[j]; if (flag == 0 || flag == 2) { if (sum == 5) { sum = 0; flag += 1; } else if (sum < 5) { } else { break; } } else { if (sum == 7) { sum = 0; flag += 1; } else if (sum < 7) { } else { break; } } j++; } else { break; } if (flag == 5) { System.out.println(i + 1); i = set; break; } } } } } }
[["-", 8, 196, 0, 57, 64, 196, 0, 37, 0, 38], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 11, 12, 22], ["+", 8, 196, 0, 57, 64, 196, 0, 1, 0, 35], ["+", 8, 196, 0, 57, 64, 196, 0, 93, 0, 94]]
3
290
import java.util.Scanner; public class Main { static final int[] HAIKU = {5, 7, 5, 7, 7}; void run() { Scanner scan = new Scanner(System.in); while (true) { int n = scan.nextInt(); if (n == 0) break; int[] w = new int[n]; for (int i = 0; i < n; i++) w[i] = scan.next().length(); int count = 1; int index = 0; for (int i = 0; i < n; i++) { int sum = 0; int j = i; while (j < w.length) { sum += w[j]; if (sum >= HAIKU[index]) break; j++; } if (sum == HAIKU[index]) { i = j; index++; } else { i = count; count++; index = 0; } if (index == HAIKU.length) { System.out.println(count); break; } } } } public static void main(String[] args) { new Main().run(); } }
import java.util.Scanner; public class Main { static final int[] HAIKU = {5, 7, 5, 7, 7}; void run() { Scanner scan = new Scanner(System.in); while (true) { int n = scan.nextInt(); if (n == 0) break; int[] w = new int[n]; for (int i = 0; i < n; i++) w[i] = scan.next().length(); int count = 1; int index = 0; for (int i = 0; i < n; i++) { int sum = 0; int j = i; while (j < w.length) { sum += w[j]; if (sum >= HAIKU[index]) break; j++; } if (sum == HAIKU[index]) { i = j; index++; } else { i = count - 1; count++; index = 0; } if (index == HAIKU.length) { System.out.println(count); break; } } } } public static void main(String[] args) { new Main().run(); } }
[["+", 75, 196, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 75, 196, 0, 1, 0, 11, 12, 16, 12, 499]]
3
252
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int N; int L, i; int j, k; int a = 0; char c[40][100]; int length; int flag; int A[100]; for (;;) { scanf("%d\n", &N); if (N == 0) break; for (j = 0; j < 40; j++) { for (k = 0; k < 100; k++) c[j][k] = '\0'; } for (i = 0; i < N; i++) scanf("%s\n", c[i]); for (L = 0; L < N; L++) { length = 5; i = L; flag = 0; while (length > 0) { length = length - strlen(c[i]); i++; } if (length == 0) flag = 1; if (flag == 1) { length = 7; while (length > 0) { length = length - strlen(c[i]); i++; } if (length == 0) flag = 2; } if (flag == 2) { length = 5; while (length > 0) { length = length - strlen(c[i]); i++; } if (length == 0) flag = 3; } if (flag == 3) { length = 7; while (length > 0) { length = length - strlen(c[i]); i++; } if (length == 0) flag = 4; } if (flag == 4) { length = 7; while (length > 0) { length = length - strlen(c[i]); i++; } if (length == 0) flag = 5; } if (flag == 5) { A[a] = L + 1; a++; break; } } } for (i = 0; i < a; i++) printf("%d %d\n", i, A[i]); return 0; }
#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int N; int L, i; int j, k; int a = 0; char c[40][100]; int length; int flag; int A[100]; for (;;) { scanf("%d\n", &N); if (N == 0) break; for (j = 0; j < 40; j++) { for (k = 0; k < 100; k++) c[j][k] = '\0'; } for (i = 0; i < N; i++) scanf("%s\n", c[i]); for (L = 0; L < N; L++) { length = 5; i = L; flag = 0; while (length > 0) { length = length - strlen(c[i]); i++; } if (length == 0) flag = 1; if (flag == 1) { length = 7; while (length > 0) { length = length - strlen(c[i]); i++; } if (length == 0) flag = 2; } if (flag == 2) { length = 5; while (length > 0) { length = length - strlen(c[i]); i++; } if (length == 0) flag = 3; } if (flag == 3) { length = 7; while (length > 0) { length = length - strlen(c[i]); i++; } if (length == 0) flag = 4; } if (flag == 4) { length = 7; while (length > 0) { length = length - strlen(c[i]); i++; } if (length == 0) flag = 5; } if (flag == 5) { A[a] = L + 1; a++; break; } } } for (i = 0; i < a; i++) printf("%d\n", A[i]); return 0; }
[["-", 8, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["+", 8, 1, 0, 2, 3, 4, 0, 5, 0, 6], ["-", 0, 7, 8, 1, 0, 2, 3, 4, 0, 21], ["-", 0, 7, 8, 1, 0, 2, 3, 4, 0, 22]]
0
436
#include <stdio.h> #include <string.h> int NextInt() { int d; scanf("%d", &d); return d; } int main() { int i, j, n; int t, u; char s[11]; int a[41]; int c; int b[5] = {5, 7, 5, 7, 7}; int ok; int ans; while (1) { n = NextInt(); if (n == 0) { break; } for (i = 0; i < n; i++) { scanf("%s", s); a[i] = strlen(s); } ans = n; for (j = 0; j < n; j++) { c = 0; t = 0; u = 1; for (i = j; i < n; i++) { t += a[i]; if (t > b[c]) { t = a[i]; c = 0; u = i + 1; } if (t == b[c]) { t = 0; c++; if (c == 5) { break; } } } if (u < ans) { ans = u; } } printf("%d\n", ans); } return 0; }
#include <stdio.h> #include <string.h> int NextInt() { int d; scanf("%d", &d); return d; } int main() { int i, j, n; int t, u; char s[11]; int a[41]; int c; int b[5] = {5, 7, 5, 7, 7}; int ans; while (1) { n = NextInt(); if (n == 0) { break; } for (i = 0; i < n; i++) { scanf("%s", s); a[i] = strlen(s); } ans = n; for (j = 0; j < n; j++) { c = 0; t = 0; u = j + 1; for (i = j; i < n; i++) { t += a[i]; if (t > b[c]) { t = a[i]; c = 0; u = i + 1; } if (t == b[c]) { t = 0; c++; if (c == 5) { break; } } } if (u < ans) { ans = u; } } printf("%d\n", ans); } return 0; }
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 35], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 72]]
0
273
#include <iostream> #include <string> #include <vector> using namespace std; int main() { int n; while (cin >> n) { if (n == 0) { break; } vector<int> data(n); string s; for (int i = 0; i < n; i++) { cin >> s; data[i] = s.size(); } for (int i = 0; i < n; i++) { int a[5] = {0}; int cc = 0; bool h = true; a[0] = data[i]; if (a[0] == 5) { cc++; } else if (a[0] > 5) { continue; } for (int j = i + 1; j < n; j++) { a[cc] += data[j]; if (cc == 0) { if (a[0] == 5) { cc++; } else if (a[0] > 5) { h = false; break; } } else if (cc == 1) { if (a[1] == 7) { cc++; } else if (a[1] > 7) { h = false; break; } } else if (cc == 2) { if (a[2] == 5) { cc++; } else if (a[2] > 5) { h = false; break; } } else if (cc == 3) { if (a[3] == 7) { cc++; } else if (a[3] > 7) { h = false; break; } } else { if (a[4] == 7) { cc++; break; } else if (a[4] > 7) { h = false; break; } } } if (h && cc == 5) { cout << i + 1 << endl; } } } return 0; }
#include <iostream> #include <string> #include <vector> using namespace std; int main() { int n; while (cin >> n) { if (n == 0) { break; } vector<int> data(n); string s; for (int i = 0; i < n; i++) { cin >> s; data[i] = s.size(); } /*for (int i = 0; i < n; i++) { cout << data[i] << endl; }*/ for (int i = 0; i < n; i++) { int a[5] = {0}; int cc = 0; bool h = true; a[0] = data[i]; if (a[0] == 5) { cc++; } else if (a[0] > 5) { continue; } for (int j = i + 1; j < n; j++) { a[cc] += data[j]; if (cc == 0) { if (a[0] == 5) { cc++; } else if (a[0] > 5) { h = false; break; } } else if (cc == 1) { if (a[1] == 7) { cc++; } else if (a[1] > 7) { h = false; break; } } else if (cc == 2) { if (a[2] == 5) { cc++; } else if (a[2] > 5) { h = false; break; } } else if (cc == 3) { if (a[3] == 7) { cc++; } else if (a[3] > 7) { h = false; break; } } else { if (a[4] == 7) { cc++; break; } else if (a[4] > 7) { h = false; break; } } } if (h && cc == 5) { cout << i + 1 << endl; break; } } } return 0; }
[["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 94], ["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 35]]
1
403
#include <iostream> #include <string> using namespace std; int w[42]; // 1-origin int n; static const int secToNum[6] = {0, 5, 7, 5, 7, 7}; bool solve(int x) { int sum; for (int sec = 1; sec <= 5; sec++) { sum = 0; while (sum < secToNum[sec]) { sum += w[x]; x++; } if (sum > secToNum[sec]) { return false; } } return true; } int main() { while (1) { cin >> n; if (n == 0) { break; } string s; for (int i = 1; i <= n; i++) { cin >> s; w[i] = s.size(); } for (int i = 1; i <= n; i++) { if (solve(i)) cout << i << endl; break; } } return 0; }
#include <iostream> #include <string> using namespace std; int w[42]; // 1-origin int n; static const int secToNum[6] = {0, 5, 7, 5, 7, 7}; bool solve(int x) { int sum; for (int sec = 1; sec <= 5; sec++) { sum = 0; while (sum < secToNum[sec]) { sum += w[x]; x++; } if (sum > secToNum[sec]) { return false; } } return true; } int main() { while (1) { cin >> n; if (n == 0) { break; } string s; for (int i = 1; i <= n; i++) { cin >> s; w[i] = s.size(); } for (int i = 1; i <= n; i++) { if (solve(i)) { cout << i << endl; break; } } } return 0; }
[["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46]]
1
203
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) const double PI = 3.1415926535897932384626433832795028841971; const int INF = 100000000; const double EPS = 1e-10; const int MOD = 1000000007; using namespace std; typedef long long ll; typedef pair<int, int> P; int n; string str[40]; void solve() { rep(i, n) cin >> str[i]; rep(i, n) { int cnt[5] = {5, 7, 5, 7, 7}; for (int j = i; j < n; j++) { rep(k, 5) { if (cnt[k] != 0) { cnt[k] -= str[j].size(); break; } } } bool ok = true; rep(j, 5) if (cnt[j] != 0) ok = false; if (ok) cout << i + 1 << endl; } } int main() { while (cin >> n) { if (n == 0) break; solve(); } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) const double PI = 3.1415926535897932384626433832795028841971; const int INF = 100000000; const double EPS = 1e-10; const int MOD = 1000000007; using namespace std; typedef long long ll; typedef pair<int, int> P; int n; string str[40]; void solve() { rep(i, n) cin >> str[i]; rep(i, n) { int cnt[5] = {5, 7, 5, 7, 7}; for (int j = i; j < n; j++) { rep(k, 5) { if (cnt[k] != 0) { cnt[k] -= str[j].size(); break; } } } bool ok = true; rep(j, 5) if (cnt[j] != 0) ok = false; if (ok) { cout << i + 1 << endl; break; } } } int main() { while (cin >> n) { if (n == 0) break; solve(); } }
[["+", 0, 14, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35], ["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 94], ["+", 0, 14, 8, 9, 0, 57, 64, 9, 0, 46]]
1
220
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <fstream> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < n; ++i) #define FOR(i, a, b) for (int i = a; i <= b; ++i) #define FORR(i, a, b) for (int i = a; i >= b; --i) #define pi M_PI typedef long long ll; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<VI> VVI; typedef pair<int, int> P; typedef pair<ll, ll> PL; int main() { int n; int w[5] = {5, 7, 5, 7, 7}; while (cin >> n && n) { VI a(n); REP(i, n) { string s; cin >> s; a[i] = s.length(); } REP(s, n) { int x = 0, i = s, j = 0, f = 1; while (f) { x += a[i]; i++; if (x > w[j]) f = 0; if (x == w[j]) { x = 0; j++; } if (j == 5) break; } if (f) cout << s + 1 << endl; } } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <fstream> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < n; ++i) #define FOR(i, a, b) for (int i = a; i <= b; ++i) #define FORR(i, a, b) for (int i = a; i >= b; --i) #define pi M_PI typedef long long ll; typedef vector<int> VI; typedef vector<ll> VL; typedef vector<VI> VVI; typedef pair<int, int> P; typedef pair<ll, ll> PL; int main() { int n; int w[5] = {5, 7, 5, 7, 7}; while (cin >> n && n) { VI a(n); REP(i, n) { string s; cin >> s; a[i] = s.length(); } REP(s, n) { int x = 0, i = s, j = 0, f = 1; while (f) { x += a[i]; i++; if (x > w[j]) f = 0; if (x == w[j]) { x = 0; j++; } if (j == 5) break; } if (f) { cout << s + 1 << endl; break; } } } return 0; }
[["+", 0, 14, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35], ["+", 8, 9, 0, 57, 64, 9, 0, 93, 0, 94], ["+", 0, 14, 8, 9, 0, 57, 64, 9, 0, 46]]
1
267
#include <iostream> using namespace std; int main() { int a[] = {5, 7, 5, 7, 7}, n, i, j, c, k; while (cin >> n, n) { string s[n]; for (i = 0; i < n; i++) cin >> s[i]; for (i = 0; i < n; i++) { c = k = 0; for (j = i; j < n; j++) { c += s[j].size(); if (c == a[k]) { c = 0; if (++k == 5) goto L; } } } L: if (k == 5) cout << i << endl; } }
#include <iostream> using namespace std; int main() { int a[] = {5, 7, 5, 7, 7}, n, i, j, c, k; while (cin >> n, n) { string s[n]; for (i = 0; i < n; i++) cin >> s[i]; for (i = 0; i < n; i++) { c = k = 0; for (j = i; j < n; j++) { c += s[j].size(); if (c == a[k]) { c = 0; if (++k == 5) goto L; } } } L: if (k == 5) cout << i + 1 << endl; } }
[["+", 64, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 64, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
161
#define _USE_MATH_DEFINES #define INF 0x3f3f3f3f #include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <limits> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> PP; static const double EPS = 1e-8; int tx[] = {0, 1, 0, -1}; int ty[] = {-1, 0, 1, 0}; int main() { int num_word; while (~scanf("%d", &num_word)) { if (num_word == 0) break; vector<string> words; for (int word_i = 0; word_i < num_word; word_i++) { string word; cin >> word; words.push_back(word); } int res = 0; for (int start = 0; start < num_word; start++) { bool has_end[50]; memset(has_end, 0, sizeof(has_end)); int pos = 0; for (int word_i = start; word_i < num_word; word_i++) { pos += words[word_i].size(); has_end[pos] = true; } if (has_end[5] && has_end[5 + 7] && has_end[5 + 7 + 5] && has_end[5 + 7 + 5 + 7] && has_end[5 + 7 + 5 + 7 + 7]) { res = start + 1; break; } } printf("%d\n", res); } }
#define _USE_MATH_DEFINES #define INF 0x3f3f3f3f #include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <limits> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> PP; static const double EPS = 1e-8; int tx[] = {0, 1, 0, -1}; int ty[] = {-1, 0, 1, 0}; int main() { int num_word; while (~scanf("%d", &num_word)) { if (num_word == 0) break; vector<string> words; for (int word_i = 0; word_i < num_word; word_i++) { string word; cin >> word; words.push_back(word); } int res = 0; for (int start = 0; start < num_word; start++) { bool has_end[256]; memset(has_end, 0, sizeof(has_end)); int pos = 0; for (int word_i = start; word_i < num_word; word_i++) { pos += words[word_i].size(); has_end[pos] = true; } if (has_end[5] && has_end[5 + 7] && has_end[5 + 7 + 5] && has_end[5 + 7 + 5 + 7] && has_end[5 + 7 + 5 + 7 + 7]) { res = start + 1; break; } } printf("%d\n", res); } }
[["-", 0, 7, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 7, 8, 9, 0, 43, 49, 80, 81, 13]]
1
318
#include <bits/stdc++.h> using namespace std; int main() { int step, flag = 0, n, l, x; while (1) { cin >> n; if (n == 0) { break; } string w[n]; for (int i = 0; i < n; i++) { cin >> w[i]; } for (int i = 0; i < n; i++) { l = 0; step = 1; flag = 0; x = i; while (1) { if (flag == 1) { break; } l += w[x].length(); switch (step) { case 1: if (l > 5) { flag = 1; } else if (l == 5) { step++; } break; case 2: if (l > 12) { flag = 1; } else if (l == 12) { step++; } break; case 3: if (l > 17) { flag = 1; } else if (l == 17) { step++; } break; case 4: if (l > 22) { flag = 1; } else if (l == 22) { step++; } break; case 5: if (l > 29) { flag = 1; } else if (l == 29) { flag = 2; } break; } if (flag == 2) { break; } x++; } if (flag = 2) { x = i + 1; break; } } if (flag = 2) { cout << x << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int step, flag = 0, n, l, x; while (1) { cin >> n; if (n == 0) { break; } string w[n]; for (int i = 0; i < n; i++) { cin >> w[i]; } for (int i = 0; i < n; i++) { l = 0; step = 1; flag = 0; x = i; while (1) { if (flag == 1) { break; } l += w[x].length(); switch (step) { case 1: if (l > 5) { flag = 1; } else if (l == 5) { step++; } break; case 2: if (l > 12) { flag = 1; } else if (l == 12) { step++; } break; case 3: if (l > 17) { flag = 1; } else if (l == 17) { step++; } break; case 4: if (l > 24) { flag = 1; } else if (l == 24) { step++; } break; case 5: if (l > 31) { flag = 1; } else if (l == 31) { flag = 2; } break; } if (flag == 2) { break; } x++; } if (flag == 2) { x = i + 1; break; } } if (flag == 2) { cout << x << endl; } } return 0; }
[["-", 0, 100, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 0, 100, 0, 57, 15, 339, 51, 16, 12, 13], ["-", 75, 76, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 12, 13], ["-", 8, 9, 0, 57, 15, 339, 51, 11, 17, 32], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60]]
1
331
// // main.cpp // Short Phrase // // Created by x15071xx on 2017/06/18. // Copyright ?? 2017??´ AIT. All rights reserved. // #include <cstdio> #include <iostream> #include <string> #include <vector> using namespace std; int main(int argc, const char *argv[]) { while (1) { int n, i, j; vector<string> str; cin >> n; if (n == 0) { break; } string tmp; for (i = 0; i < n; i++) { cin >> tmp; str.push_back(tmp); } for (i = 0; i < n; i++) { int flag = 0; j = i; int numsum = 0; while (1) { if (flag == -1) { break; } if (flag == 5) { cout << i + 1 << endl; break; } numsum += str[i + j].length(); // if (i == 5) { // cout << numsum << str[i+j] <<endl; // } if (flag == 0 || flag == 2) { if (numsum > 5) { flag = -1; } else if (numsum < 5) { j++; } else if (numsum == 5) { flag++; numsum = 0; j++; } } else { if (numsum > 7) { flag = -1; } else if (numsum < 7) { j++; } else if (numsum == 7) { flag++; numsum = 0; j++; } } } if (flag == 5) { break; } } } return 0; }
// // main.cpp // Short Phrase // // Created by x15071xx on 2017/06/18. // Copyright ?? 2017??´ AIT. All rights reserved. // #include <cstdio> #include <iostream> #include <string> #include <vector> using namespace std; int main(int argc, const char *argv[]) { while (1) { int n, i, j; vector<string> str; cin >> n; if (n == 0) { break; } string tmp; for (i = 0; i < n; i++) { cin >> tmp; str.push_back(tmp); } for (i = 0; i < n; i++) { int flag = 0; j = 0; int numsum = 0; while (1) { if (flag == -1) { break; } if (flag == 5) { cout << i + 1 << endl; break; } numsum += str[i + j].length(); // if (i == 5) { // cout << numsum << str[i+j] <<endl; // } if (flag == 0 || flag == 2) { if (numsum > 5) { flag = -1; } else if (numsum < 5) { j++; } else if (numsum == 5) { flag++; numsum = 0; j++; } } else { if (numsum > 7) { flag = -1; } else if (numsum < 7) { j++; } else if (numsum == 7) { flag++; numsum = 0; j++; } } } if (flag == 5) { break; } } } return 0; }
[["-", 0, 7, 8, 9, 0, 1, 0, 11, 12, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13]]
1
289
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <numeric> #include <vector> using namespace std; using ll = long long; int main() { constexpr int len[5] = {5, 7, 5, 7, 7}; while (true) { int n; cin >> n; if (n == 0) { break; } vector<int> l(n); for (int i = 0; i < n; i++) { string s; cin >> s; l[i] = s.size(); } for (int i = 0; i < n; i++) { int ind = 0; int sum = 0; for (int j = i; j < n; j++) { if (ind == 5) { break; } sum += l[j]; if (sum > len[ind]) { break; } else if (sum == len[ind]) { ind++; sum = 0; } } if (ind == 5) { cout << i << endl; break; } } } return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <numeric> #include <vector> using namespace std; using ll = long long; int main() { constexpr int len[5] = {5, 7, 5, 7, 7}; while (true) { int n; cin >> n; if (n == 0) { break; } vector<int> l(n); for (int i = 0; i < n; i++) { string s; cin >> s; l[i] = s.size(); } for (int i = 0; i < n; i++) { int ind = 0; int sum = 0; for (int j = i; j < n; j++) { if (ind == 5) { break; } sum += l[j]; if (sum > len[ind]) { break; } else if (sum == len[ind]) { ind++; sum = 0; } } if (ind == 5) { cout << i + 1 << endl; break; } } } return 0; }
[["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 12, 13]]
1
223