problem_id
stringlengths
6
6
language
stringclasses
2 values
original_status
stringclasses
3 values
original_src
stringlengths
19
243k
changed_src
stringlengths
19
243k
change
stringclasses
3 values
i1
int64
0
8.44k
i2
int64
0
8.44k
j1
int64
0
8.44k
j2
int64
0
8.44k
error
stringclasses
270 values
stderr
stringlengths
0
226k
p02749
C++
Runtime Error
#include <algorithm> //sort,reverse #include <deque> //double_ended queue #include <iostream> #include <queue> //queue,priority_queue #include <string> #include <utility> //pair #include <vector> using namespace std; typedef pair<int, int> P; // Pでpair<-,->を表す。 typedef long long LL; LL MOD = 1000000007; /*ここから*/ int V; // 頂点の個数 vector<int> e[2000010]; // iから出る辺 int t[2000010]; // 親情報の記録媒体 int h[2000010]; bool h_flg[2000010]; // すでにある辺と頂点の情報から木の作成 void Tree(int s) { // sは一番根元 for (int i = 1; i <= V; i++) { t[i] = i; // 初期情報 } queue<int> q; q.push(s); while (!q.empty()) { int from; from = q.front(); q.pop(); while (!e[from].empty()) { int to; to = e[from].back(); e[from].pop_back(); if (to != t[from]) { t[to] = from; q.push(to); } } } } void height(int s) { if (t[s] == s) { h[s] = 1; h_flg[s] = true; } else { if (!h_flg[t[s]]) { height(s); } h[s] = h[t[s]] + 1; h_flg[s] = true; } } /*ここまで*/ int main() { int n; cin >> n; V = n; for (int i = 0; i < V - 1; i++) { int a, b; cin >> a >> b; e[a].push_back(b); e[b].push_back(a); } Tree(1); for (int i = 0; i < 2000010; i++) { h[i] = 0; h_flg[i] = false; } for (int i = 1; i <= V; i++) { height(i); } // for(int i=1;i<=V;i++){cout<<h[i]<<endl;} int ans[n + 1]; int cnt1 = 0; int cnt2 = 0; int b1 = 0; int b2 = 0; if (n % 3 == 0) { b1 = n / 3; b2 = n / 3; } else if (n % 3 == 1) { b1 = n / 3 + 1; b2 = n / 3; } else { b1 = n / 3 + 1; b2 = n / 3 + 1; } for (int i = 1; i <= n; i++) { if (h[i] % 2 == 1) { cnt1++; if (cnt1 <= b1) { ans[i] = 1; } else { ans[i] = 3; } } else { cnt2++; if (cnt2 <= b2) { ans[i] = 2; } else { ans[i] = 3; } } } if (cnt1 < b1) { int x = cnt1; cnt1 = 0; cnt2 = 0; int cnt3 = x; for (int i = 1; i <= n; i++) { if (ans[i] == 1) { ans[i] = 3 * x; x--; } else { if (cnt1 < b1) { ans[i] = 3 * cnt1 + 1; cnt1++; } else if (cnt2 < b2) { ans[i] = 3 * cnt2 + 2; cnt2++; } else { ans[i] = cnt3 * 3 + 3; cnt3++; } } } } else if (cnt2 < b2) { int x = cnt2; cnt1 = 0; cnt2 = 0; int cnt3 = x; for (int i = 1; i <= n; i++) { if (ans[i] == 2) { ans[i] = 3 * x; x--; } else { if (cnt1 < b1) { ans[i] = 3 * cnt1 + 1; cnt1++; } else if (cnt2 < b2) { ans[i] = 3 * cnt2 + 2; cnt2++; } else { ans[i] = cnt3 * 3 + 3; cnt3++; } } } } else { cnt1 = 0; cnt2 = 0; int cnt3 = 0; for (int i = 1; i <= n; i++) { if (ans[i] == 1) { ans[i] = cnt1 * 3 + 1; cnt1++; } else if (ans[i] == 2) { ans[i] = cnt2 * 3 + 2; cnt2++; } else { ans[i] = cnt3 * 3 + 3; cnt3++; } } } for (int i = 1; i < n; i++) { cout << ans[i] << ' '; } cout << ans[n] << endl; return 0; }
#include <algorithm> //sort,reverse #include <deque> //double_ended queue #include <iostream> #include <queue> //queue,priority_queue #include <string> #include <utility> //pair #include <vector> using namespace std; typedef pair<int, int> P; // Pでpair<-,->を表す。 typedef long long LL; LL MOD = 1000000007; /*ここから*/ int V; // 頂点の個数 vector<int> e[2000010]; // iから出る辺 int t[2000010]; // 親情報の記録媒体 int h[2000010]; bool h_flg[2000010]; // すでにある辺と頂点の情報から木の作成 void Tree(int s) { // sは一番根元 for (int i = 1; i <= V; i++) { t[i] = i; // 初期情報 } queue<int> q; q.push(s); while (!q.empty()) { int from; from = q.front(); q.pop(); while (!e[from].empty()) { int to; to = e[from].back(); e[from].pop_back(); if (to != t[from]) { t[to] = from; q.push(to); } } } } void height(int s) { if (t[s] == s) { h[s] = 1; h_flg[s] = true; } else { if (!h_flg[t[s]]) { height(t[s]); } h[s] = h[t[s]] + 1; h_flg[s] = true; } } /*ここまで*/ int main() { int n; cin >> n; V = n; for (int i = 0; i < V - 1; i++) { int a, b; cin >> a >> b; e[a].push_back(b); e[b].push_back(a); } Tree(1); for (int i = 0; i < 2000010; i++) { h[i] = 0; h_flg[i] = false; } for (int i = 1; i <= V; i++) { height(i); } // for(int i=1;i<=V;i++){cout<<h[i]<<endl;} int ans[n + 1]; int cnt1 = 0; int cnt2 = 0; int b1 = 0; int b2 = 0; if (n % 3 == 0) { b1 = n / 3; b2 = n / 3; } else if (n % 3 == 1) { b1 = n / 3 + 1; b2 = n / 3; } else { b1 = n / 3 + 1; b2 = n / 3 + 1; } for (int i = 1; i <= n; i++) { if (h[i] % 2 == 1) { cnt1++; if (cnt1 <= b1) { ans[i] = 1; } else { ans[i] = 3; } } else { cnt2++; if (cnt2 <= b2) { ans[i] = 2; } else { ans[i] = 3; } } } if (cnt1 < b1) { int x = cnt1; cnt1 = 0; cnt2 = 0; int cnt3 = x; for (int i = 1; i <= n; i++) { if (ans[i] == 1) { ans[i] = 3 * x; x--; } else { if (cnt1 < b1) { ans[i] = 3 * cnt1 + 1; cnt1++; } else if (cnt2 < b2) { ans[i] = 3 * cnt2 + 2; cnt2++; } else { ans[i] = cnt3 * 3 + 3; cnt3++; } } } } else if (cnt2 < b2) { int x = cnt2; cnt1 = 0; cnt2 = 0; int cnt3 = x; for (int i = 1; i <= n; i++) { if (ans[i] == 2) { ans[i] = 3 * x; x--; } else { if (cnt1 < b1) { ans[i] = 3 * cnt1 + 1; cnt1++; } else if (cnt2 < b2) { ans[i] = 3 * cnt2 + 2; cnt2++; } else { ans[i] = cnt3 * 3 + 3; cnt3++; } } } } else { cnt1 = 0; cnt2 = 0; int cnt3 = 0; for (int i = 1; i <= n; i++) { if (ans[i] == 1) { ans[i] = cnt1 * 3 + 1; cnt1++; } else if (ans[i] == 2) { ans[i] = cnt2 * 3 + 2; cnt2++; } else { ans[i] = cnt3 * 3 + 3; cnt3++; } } } for (int i = 1; i < n; i++) { cout << ans[i] << ' '; } cout << ans[n] << endl; return 0; }
replace
48
49
48
49
0
p02749
Python
Runtime Error
from collections import deque N = int(input()) G = [[] for _ in range(N + 1)] dist = [-1 for _ in range(N + 1)] for _ in range(N - 1): a, b = map(int, input().split()) G[a].append(b) G[b].append(a) zero = [] one = [] two = [] for i in range(1, N + 1): if i % 3 == 1: one.append(i) elif i % 3 == 2: two.append(i) else: zero.append(i) q = deque([1]) dist[1] = 0 while q.__len__() != 0: s = q.pop(0) for i in G[s]: if dist[i] == -1: q.append(i) dist[i] = (dist[s] + 1) % 2 red = 0 blue = 0 for i in range(1, N + 1): if dist[i] == 0: red += 1 else: blue += 1 ans = [] if red > N / 3 and blue > N / 3: for i in range(1, N + 1): if dist[i] == 0 and one.__len__() != 0: ans.append(one.pop()) elif dist[i] == 1 and two.__len__() != 0: ans.append(two.pop()) else: ans.append(zero.pop()) elif red <= N / 3: for i in range(1, N + 1): if dist[i] == 0: ans.append(zero.pop()) else: if one.__len__() != 0: ans.append(one.pop()) elif two.__len__() != 0: ans.append(two.pop()) else: ans.append(zero.pop()) else: for i in range(1, N + 1): if dist[i] == 1: ans.append(zero.pop()) else: if one.__len__() != 0: ans.append(one.pop()) elif two.__len__() != 0: ans.append(two.pop()) else: ans.append(zero.pop()) print(*ans)
from collections import deque N = int(input()) G = [[] for _ in range(N + 1)] dist = [-1 for _ in range(N + 1)] for _ in range(N - 1): a, b = map(int, input().split()) G[a].append(b) G[b].append(a) zero = [] one = [] two = [] for i in range(1, N + 1): if i % 3 == 1: one.append(i) elif i % 3 == 2: two.append(i) else: zero.append(i) q = deque([1]) dist[1] = 0 while q.__len__() != 0: s = q.popleft() for i in G[s]: if dist[i] == -1: q.append(i) dist[i] = (dist[s] + 1) % 2 red = 0 blue = 0 for i in range(1, N + 1): if dist[i] == 0: red += 1 else: blue += 1 ans = [] if red > N / 3 and blue > N / 3: for i in range(1, N + 1): if dist[i] == 0 and one.__len__() != 0: ans.append(one.pop()) elif dist[i] == 1 and two.__len__() != 0: ans.append(two.pop()) else: ans.append(zero.pop()) elif red <= N / 3: for i in range(1, N + 1): if dist[i] == 0: ans.append(zero.pop()) else: if one.__len__() != 0: ans.append(one.pop()) elif two.__len__() != 0: ans.append(two.pop()) else: ans.append(zero.pop()) else: for i in range(1, N + 1): if dist[i] == 1: ans.append(zero.pop()) else: if one.__len__() != 0: ans.append(one.pop()) elif two.__len__() != 0: ans.append(two.pop()) else: ans.append(zero.pop()) print(*ans)
replace
23
24
23
24
TypeError: deque.pop() takes no arguments (1 given)
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02749/Python/s008733613.py", line 23, in <module> s = q.pop(0) TypeError: deque.pop() takes no arguments (1 given)
p02749
Python
Runtime Error
N = int(input()) T = [[] for _ in range(N)] for _ in range(N - 1): a, b = map(int, input().split()) a, b = a - 1, b - 1 T[a].append(b) T[b].append(a) colors = [-1] * N stack = [(0, 0)] while stack: n, color = stack.pop() colors[n] = color for to in T[n]: if colors[to] != -1: continue stack.append((to, color ^ 1)) # あまり1、あまり2、あまり0になるように並び替え X = [[] for _ in range(3)] for n in range(1, N + 1): X[n % 3].append(n) X.append(X[0]) del X[0] ans = [] x12, x3 = X[0] + X[1], X[2] if colors.count(0) <= N // 3: for color in colors: if color == 0: ans.append(x3.pop()) elif x12: ans.append(x12.pop()) else: ans.append(x3.pop()) elif colors.count(1) <= N // 3: for color in colors: if color == 1: ans.append(x3.pop()) elif x12: ans.append(x12.pop()) else: ans.append(x3.pop()) else: for color in colors: if X[color]: ans.append(X[color ^ 1].pop()) else: ans.append(X[2].pop()) print(" ".join(map(str, ans)))
N = int(input()) T = [[] for _ in range(N)] for _ in range(N - 1): a, b = map(int, input().split()) a, b = a - 1, b - 1 T[a].append(b) T[b].append(a) colors = [-1] * N stack = [(0, 0)] while stack: n, color = stack.pop() colors[n] = color for to in T[n]: if colors[to] != -1: continue stack.append((to, color ^ 1)) # あまり1、あまり2、あまり0になるように並び替え X = [[] for _ in range(3)] for n in range(1, N + 1): X[n % 3].append(n) X.append(X[0]) del X[0] ans = [] x12, x3 = X[0] + X[1], X[2] if colors.count(0) <= N // 3: for color in colors: if color == 0: ans.append(x3.pop()) elif x12: ans.append(x12.pop()) else: ans.append(x3.pop()) elif colors.count(1) <= N // 3: for color in colors: if color == 1: ans.append(x3.pop()) elif x12: ans.append(x12.pop()) else: ans.append(x3.pop()) else: for color in colors: if X[color]: ans.append(X[color].pop()) else: ans.append(X[2].pop()) print(" ".join(map(str, ans)))
replace
51
52
51
52
IndexError: pop from empty list
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02749/Python/s592613558.py", line 54, in <module> ans.append(X[2].pop()) IndexError: pop from empty list
p02749
Python
Runtime Error
n = int(input()) ab = [list(map(int, input().split())) for _ in range(n - 1)] adj = [[] for _ in range(n)] for a, b in ab: a -= 1 b -= 1 adj[a].append(b) adj[b].append(a) class Tree: WHITE = 0 GRAY = -1 BLACK = 1 def __init__(self, adj): n = len(adj) self.adj = adj self.colors = [self.WHITE] * n self.depths = [-1] * n self.depth = 0 def init(self): self.__init__(self.adj) def dfs(self, u): if self.colors[u] == self.BLACK: return self.colors[u] = self.GRAY self.depths[u] = self.depth for v in self.adj[u]: if self.colors[v] == self.WHITE: self.depth += 1 self.dfs(v) self.depth -= 1 self.colors[u] = self.BLACK tree = Tree(adj) tree.dfs(0) ev = [i for i, e in enumerate(tree.depths) if e % 2 == 0] od = [i for i, e in enumerate(tree.depths) if e % 2] l_ev = len(ev) l_od = len(od) mod0 = [e for e in range(1, n + 1) if e % 3 == 0] mod1 = [e for e in range(1, n + 1) if e % 3 == 1] mod2 = [e for e in range(1, n + 1) if e % 3 == 2] ans = [0] * n def f(li1, li2): while li1 and li2: i = li1.pop() num = li2.pop() ans[i] = num if l_ev > n / 3 and l_od > n / 3: f(ev, mod1) f(od, mod2) f(ev, mod0) f(od, mod0) elif l_ev <= n / 3: f(ev, mod0) f(od, mod0) f(od, mod1) f(od, mod2) else: f(od, mod0) f(ev, mod0) f(ev, mod1) f(ev, mod2) print(*ans)
import sys sys.setrecursionlimit(10**6) n = int(input()) ab = [list(map(int, input().split())) for _ in range(n - 1)] adj = [[] for _ in range(n)] for a, b in ab: a -= 1 b -= 1 adj[a].append(b) adj[b].append(a) class Tree: WHITE = 0 GRAY = -1 BLACK = 1 def __init__(self, adj): n = len(adj) self.adj = adj self.colors = [self.WHITE] * n self.depths = [-1] * n self.depth = 0 def init(self): self.__init__(self.adj) def dfs(self, u): if self.colors[u] == self.BLACK: return self.colors[u] = self.GRAY self.depths[u] = self.depth for v in self.adj[u]: if self.colors[v] == self.WHITE: self.depth += 1 self.dfs(v) self.depth -= 1 self.colors[u] = self.BLACK tree = Tree(adj) tree.dfs(0) ev = [i for i, e in enumerate(tree.depths) if e % 2 == 0] od = [i for i, e in enumerate(tree.depths) if e % 2] l_ev = len(ev) l_od = len(od) mod0 = [e for e in range(1, n + 1) if e % 3 == 0] mod1 = [e for e in range(1, n + 1) if e % 3 == 1] mod2 = [e for e in range(1, n + 1) if e % 3 == 2] ans = [0] * n def f(li1, li2): while li1 and li2: i = li1.pop() num = li2.pop() ans[i] = num if l_ev > n / 3 and l_od > n / 3: f(ev, mod1) f(od, mod2) f(ev, mod0) f(od, mod0) elif l_ev <= n / 3: f(ev, mod0) f(od, mod0) f(od, mod1) f(od, mod2) else: f(od, mod0) f(ev, mod0) f(ev, mod1) f(ev, mod2) print(*ans)
insert
0
0
0
4
0
p02749
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #define X first #define Y second #define pb push_back #define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X)) #define reps(X, S, Y) for (int(X) = S; (X) < (Y); ++(X)) #define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X)) #define rreps(X, S, Y) for (int(X) = (Y)-1; (X) >= (S); --(X)) #define repe(X, Y) for ((X) = 0; (X) < (Y); ++(X)) #define peat(X, Y) for (; (X) < (Y); ++(X)) #define all(X) (X).begin(), (X).end() #define rall(X) (X).rbegin(), (X).rend() #define eb emplace_back #define UNIQUE(X) (X).erase(unique(all(X)), (X).end()) #define Endl endl #define NL << "\n" using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; template <class T> using vv = vector<vector<T>>; template <class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; } template <class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; } // #undef NUIP #ifdef NUIP #include "benri.h" #else #define out(args...) #endif #ifdef __cpp_init_captures template <typename T> vector<T> table(int n, T v) { return vector<T>(n, v); } template <class... Args> auto table(int n, Args... args) { auto val = table(args...); return vector<decltype(val)>(n, move(val)); } #endif const ll MOD = 1e9 + 7; // 998244353 int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(0); ll n; cin >> n; n; vv<int> g(n); rep(i, n - 1) { int a, b; cin >> a >> b; --a; --b; g[a].pb(b); g[b].pb(a); } vector<int> d(n, MOD); { d[0] = 0; queue<int> que; que.emplace(0); while (que.size()) { int v = que.front(); que.pop(); for (int w : g[v]) if (MN(d[w], d[v] + 1)) que.emplace(w); } } out(d, 1); vector<int> os, es; rep(i, n)(d[i] % 2 ? es : os).pb(i); vector<int> re(n); reps(o, 1, 3) { if (os.size() > es.size()) swap(os, es); for (int v = o; v <= n; v += 3) { re[es.back()] = v; es.pop_back(); } } os.insert(os.end(), all(es)); for (int v = 3; v <= n; v += 3) { re[os.back()] = v; os.pop_back(); } assert(os.empty()); assert(es.empty()); rep(i, n) cout << re[i] << " \n"[i + 1 == n]; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #define X first #define Y second #define pb push_back #define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X)) #define reps(X, S, Y) for (int(X) = S; (X) < (Y); ++(X)) #define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X)) #define rreps(X, S, Y) for (int(X) = (Y)-1; (X) >= (S); --(X)) #define repe(X, Y) for ((X) = 0; (X) < (Y); ++(X)) #define peat(X, Y) for (; (X) < (Y); ++(X)) #define all(X) (X).begin(), (X).end() #define rall(X) (X).rbegin(), (X).rend() #define eb emplace_back #define UNIQUE(X) (X).erase(unique(all(X)), (X).end()) #define Endl endl #define NL << "\n" using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; template <class T> using vv = vector<vector<T>>; template <class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; } template <class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; } // #undef NUIP #ifdef NUIP #include "benri.h" #else #define out(args...) #endif #ifdef __cpp_init_captures template <typename T> vector<T> table(int n, T v) { return vector<T>(n, v); } template <class... Args> auto table(int n, Args... args) { auto val = table(args...); return vector<decltype(val)>(n, move(val)); } #endif const ll MOD = 1e9 + 7; // 998244353 int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(0); ll n; cin >> n; n; vv<int> g(n); rep(i, n - 1) { int a, b; cin >> a >> b; --a; --b; g[a].pb(b); g[b].pb(a); } vector<int> d(n, MOD); { d[0] = 0; queue<int> que; que.emplace(0); while (que.size()) { int v = que.front(); que.pop(); for (int w : g[v]) if (MN(d[w], d[v] + 1)) que.emplace(w); } } out(d, 1); vector<int> os, es; rep(i, n)(d[i] % 2 ? es : os).pb(i); vector<int> re(n); reps(o, 1, 3) { if (os.size() > es.size()) swap(os, es); for (int v = o; v <= n; v += 3) { re[es.back()] = v; es.pop_back(); } } os.insert(os.end(), all(es)); for (int v = 3; v <= n; v += 3) { re[os.back()] = v; os.pop_back(); } rep(i, n) cout << re[i] << " \n"[i + 1 == n]; return 0; }
delete
111
113
111
111
0
p02749
C++
Runtime Error
/* 二部グラフになるように色を付ける。 不可能ならば空のvectorを返す 0 or 1で色を付ける -1は頂点0とつながってない部分 vector<int>(); GはGraphを想定 WeightGraphの場合は//+++++の部分を変える必要がある verify: https://atcoder.jp/contests/hitachi2020/tasks/hitachi2020_c */ #include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using Graph = vector<vector<int>>; template <typename G> vector<int> bipartite(const G &g) { vector<int> color(g.size(), -1); stack<pii> st; st.push({0, 0}); while (!st.empty()) { int idx, nc; tie(idx, nc) = st.top(); st.pop(); for (auto next : g[idx]) { if (color[next] == -1) { color[idx] = nc ^ 1; st.push({next, nc ^ 1}); //++++++++++++++++++++ } else { if (color[next] != nc ^ 1) return vector<int>(); //+++++++++++ } } } return color; } signed main() { int n; cin >> n; Graph g(n); for (int i = 1; i < n; i++) { int a, b; cin >> a >> b; a--; b--; g[a].push_back(b); g[b].push_back(a); } auto color = bipartite(g); // vout(color); int cnt0 = 0, cnt1 = 0; int num0 = 0, num1 = 1; for (int i = 0; i < n; i++) { if (color[i] == 0) cnt0++; else cnt1++; } vector<int> ret(n); if (cnt0 > cnt1) swap(cnt1, cnt0), swap(num1, num0); vector<int> v0, v1; if (cnt0 <= n / 3) { for (int i = 0; i < n / 3; i++) { if (i < cnt0) v0.push_back(3 * (i + 1)); else v1.push_back(3 * (i + 1)); } for (int i = 1; i <= n; i++) { if (i % 3 == 0) continue; v1.push_back(i); } } else { int now = 1; for (int i = 1; i <= n; i++) { if (i % 3 == 1) v0.push_back(i); else if (i % 3 == 2) v1.push_back(i); } for (int i = 0; i < cnt0 - (n + 2) / 3; i++) { v0.push_back(now * 3); now++; } for (int i = 0; i < cnt1 - (n + 1) / 3; i++) { v1.push_back(now * 3); now++; } } int now0 = 0, now1 = 0; for (int i = 0; i < n; i++) { if (num0 == color[i]) { cout << v0[now0] << endl; now0++; } else { cout << v1[now1] << endl; now1++; } } }
/* 二部グラフになるように色を付ける。 不可能ならば空のvectorを返す 0 or 1で色を付ける -1は頂点0とつながってない部分 vector<int>(); GはGraphを想定 WeightGraphの場合は//+++++の部分を変える必要がある verify: https://atcoder.jp/contests/hitachi2020/tasks/hitachi2020_c */ #include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; using Graph = vector<vector<int>>; template <typename G> vector<int> bipartite(const G &g) { vector<int> color(g.size(), -1); stack<pii> st; st.push({0, 0}); while (!st.empty()) { int idx, nc; tie(idx, nc) = st.top(); st.pop(); for (auto next : g[idx]) { if (color[next] == -1) { color[next] = nc ^ 1; st.push({next, nc ^ 1}); //++++++++++++++++++++ } else { if (color[next] != nc ^ 1) return vector<int>(); //+++++++++++ } } } return color; } signed main() { int n; cin >> n; Graph g(n); for (int i = 1; i < n; i++) { int a, b; cin >> a >> b; a--; b--; g[a].push_back(b); g[b].push_back(a); } auto color = bipartite(g); // vout(color); int cnt0 = 0, cnt1 = 0; int num0 = 0, num1 = 1; for (int i = 0; i < n; i++) { if (color[i] == 0) cnt0++; else cnt1++; } vector<int> ret(n); if (cnt0 > cnt1) swap(cnt1, cnt0), swap(num1, num0); vector<int> v0, v1; if (cnt0 <= n / 3) { for (int i = 0; i < n / 3; i++) { if (i < cnt0) v0.push_back(3 * (i + 1)); else v1.push_back(3 * (i + 1)); } for (int i = 1; i <= n; i++) { if (i % 3 == 0) continue; v1.push_back(i); } } else { int now = 1; for (int i = 1; i <= n; i++) { if (i % 3 == 1) v0.push_back(i); else if (i % 3 == 2) v1.push_back(i); } for (int i = 0; i < cnt0 - (n + 2) / 3; i++) { v0.push_back(now * 3); now++; } for (int i = 0; i < cnt1 - (n + 1) / 3; i++) { v1.push_back(now * 3); now++; } } int now0 = 0, now1 = 0; for (int i = 0; i < n; i++) { if (num0 == color[i]) { cout << v0[now0] << endl; now0++; } else { cout << v1[now1] << endl; now1++; } } }
replace
33
34
33
34
-11
p02749
C++
Runtime Error
#include <iostream> #include <queue> #include <vector> using namespace std; typedef pair<int, int> P; struct Graph { int n; vector<vector<int>> g; Graph(int n) : n(n) { g.resize(n); } void init(int n_) { n = n_; g.resize(n_); } void add_edge(int from, int to) { g[from].push_back(to); } }; vector<int> BipartiteGraph(Graph &g) { int n = g.n; vector<int> b(n); queue<int> que; for (int i = 0; i < n; i++) { if (b[i]) continue; b[i] = 1; que.push(i); while (que.size()) { int u = que.front(); que.pop(); for (int v : g.g[u]) { if (b[u] == b[v]) { for (int i = 0; i < n; i++) b[i] = -1; return b; } if (b[v] == 0) { b[v] = 3 - b[u]; que.push(v); } } } } return b; } int main() { int n; cin >> n; Graph g(n); for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; a--; b--; g.add_edge(a, b); g.add_edge(b, a); } vector<int> b = BipartiteGraph(g); int a[3]{0}; for (int i = 0; i < n; i++) { a[b[i]]++; } int x = 1, y = 2, z = 3; int ans[100005]; if (a[1] <= n / 3 || a[2] <= n / 3) { int j; if (a[1] <= n / 3) j = 1; else j = 2; for (int i = 0; i < n; i++) { if (b[i] == j) { ans[i] = z; z += 3; } else { if (x <= n) { ans[i] = x; x += 3; } else if (y <= n) { ans[i] = y; y += 3; } else { ans[i] = z; z += 3; } } } } else { for (int i = 0; i < n; i++) { if (b[i] == 1) { if (x <= n) { ans[i] = x; x += 3; } else { ans[i] = z; z += 3; } } else { if (y <= n) { ans[i] = y; y += 3; } else { ans[i] = z; z += 3; } } } } for (int i = 0; i < n; i++) cout << ans[i] << " "; cout << endl; }
#include <iostream> #include <queue> #include <vector> using namespace std; typedef pair<int, int> P; struct Graph { int n; vector<vector<int>> g; Graph(int n) : n(n) { g.resize(n); } void init(int n_) { n = n_; g.resize(n_); } void add_edge(int from, int to) { g[from].push_back(to); } }; vector<int> BipartiteGraph(Graph &g) { int n = g.n; vector<int> b(n); queue<int> que; for (int i = 0; i < n; i++) { if (b[i]) continue; b[i] = 1; que.push(i); while (que.size()) { int u = que.front(); que.pop(); for (int v : g.g[u]) { if (b[u] == b[v]) { for (int i = 0; i < n; i++) b[i] = -1; return b; } if (b[v] == 0) { b[v] = 3 - b[u]; que.push(v); } } } } return b; } int main() { int n; cin >> n; Graph g(n); for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; a--; b--; g.add_edge(a, b); g.add_edge(b, a); } vector<int> b = BipartiteGraph(g); int a[3]{0}; for (int i = 0; i < n; i++) { a[b[i]]++; } int x = 1, y = 2, z = 3; int ans[200005]; if (a[1] <= n / 3 || a[2] <= n / 3) { int j; if (a[1] <= n / 3) j = 1; else j = 2; for (int i = 0; i < n; i++) { if (b[i] == j) { ans[i] = z; z += 3; } else { if (x <= n) { ans[i] = x; x += 3; } else if (y <= n) { ans[i] = y; y += 3; } else { ans[i] = z; z += 3; } } } } else { for (int i = 0; i < n; i++) { if (b[i] == 1) { if (x <= n) { ans[i] = x; x += 3; } else { ans[i] = z; z += 3; } } else { if (y <= n) { ans[i] = y; y += 3; } else { ans[i] = z; z += 3; } } } } for (int i = 0; i < n; i++) cout << ans[i] << " "; cout << endl; }
replace
66
67
66
67
0
p02749
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int _ = 1e5 + 7; struct Edge { int end, upEd; } Ed[_ << 1]; int head[_], cntEd, col[2], N; void addEd(int a, int b) { Ed[++cntEd] = (Edge){b, head[a]}; head[a] = cntEd; } void dfs(int x, int p, int c) { ++col[c]; for (int i = head[x]; i; i = Ed[i].upEd) if (Ed[i].end != p) dfs(Ed[i].end, x, c ^ 1); } vector<int> pot[3]; int arr[_]; void dfs1(int x, int p, int c, int id) { if (id == 2) { int i = pot[c + 1].size() ? c + 1 : 0; arr[x] = pot[i].back(); pot[i].pop_back(); } else if (!(id ^ c)) { arr[x] = pot[0].back(); pot[0].pop_back(); } else { int p = pot[1].empty() ? (pot[2].empty() ? 0 : 2) : 1; arr[x] = pot[p].back(); pot[p].pop_back(); } for (int i = head[x]; i; i = Ed[i].upEd) if (Ed[i].end != p) dfs1(Ed[i].end, x, c ^ 1, id); } signed main() { cin >> N; for (int i = 1; i < N; ++i) { int x, y; cin >> x >> y; addEd(x, y); addEd(y, x); } for (int i = 1; i <= N; ++i) pot[i % 3].push_back(i); dfs(1, 0, 0); dfs1(1, 0, 0, col[0] < pot[1].size() ? 0 : (col[1] < pot[2].size() ? 1 : 2)); for (int i = 1; i <= N; ++i) cout << arr[i] << ' '; return 0; }
#include <bits/stdc++.h> using namespace std; const int _ = 2e5 + 7; struct Edge { int end, upEd; } Ed[_ << 1]; int head[_], cntEd, col[2], N; void addEd(int a, int b) { Ed[++cntEd] = (Edge){b, head[a]}; head[a] = cntEd; } void dfs(int x, int p, int c) { ++col[c]; for (int i = head[x]; i; i = Ed[i].upEd) if (Ed[i].end != p) dfs(Ed[i].end, x, c ^ 1); } vector<int> pot[3]; int arr[_]; void dfs1(int x, int p, int c, int id) { if (id == 2) { int i = pot[c + 1].size() ? c + 1 : 0; arr[x] = pot[i].back(); pot[i].pop_back(); } else if (!(id ^ c)) { arr[x] = pot[0].back(); pot[0].pop_back(); } else { int p = pot[1].empty() ? (pot[2].empty() ? 0 : 2) : 1; arr[x] = pot[p].back(); pot[p].pop_back(); } for (int i = head[x]; i; i = Ed[i].upEd) if (Ed[i].end != p) dfs1(Ed[i].end, x, c ^ 1, id); } signed main() { cin >> N; for (int i = 1; i < N; ++i) { int x, y; cin >> x >> y; addEd(x, y); addEd(y, x); } for (int i = 1; i <= N; ++i) pot[i % 3].push_back(i); dfs(1, 0, 0); dfs1(1, 0, 0, col[0] < pot[1].size() ? 0 : (col[1] < pot[2].size() ? 1 : 2)); for (int i = 1; i <= N; ++i) cout << arr[i] << ' '; return 0; }
replace
3
4
3
4
0
p02749
C++
Runtime Error
#include <bits/stdc++.h> typedef int LL; #define pb push_back const LL maxn = 1e6 + 9; struct node { LL to, nxt; } dis[maxn]; LL n, num; LL head[maxn], p[maxn], dep[maxn]; std::vector<LL> V[3], a[3]; void Add(LL u, LL v) { dis[++num] = (node){v, head[u]}; head[u] = num; } void Dfs(LL u, LL f) { V[dep[u]].pb(u); for (LL i = head[u]; i; i = dis[i].nxt) { LL v(dis[i].to); if (v == f) continue; dep[v] = (dep[u] ^ 1); Dfs(v, u); } } int main() { scanf("%d", &n); for (LL i = 1; i < n; ++i) { LL u, v; scanf("%d%d", &u, &v); Add(u, v); Add(v, u); } for (LL i = 1; i <= n; ++i) { a[i % 3].pb(i); } LL ret(n / 3); Dfs(1, 0); if (V[0].size() > V[1].size()) std::swap(V[0], V[1]); LL tot0(0), tot1(0), tot2(0); if (V[0].size() <= ret) { for (LL i = 0; i < V[0].size(); ++i) { LL x(V[0][i]); p[x] = a[0][tot0++]; } for (LL i = 0; i < V[1].size(); ++i) { LL x(V[0][i]); if (tot2 < a[2].size()) p[x] = a[2][tot2++]; else if (tot0 < a[0].size()) p[x] = a[0][tot0++]; else p[x] = a[1][tot1++]; } for (LL i = 1; i <= n; ++i) printf("%d ", p[i]); puts(""); return 0; } for (LL i = 0; i < V[0].size(); ++i) { LL x(V[0][i]); if (tot1 < a[1].size()) p[x] = a[1][tot1++]; else if (tot0 < a[0].size()) p[x] = a[0][tot0++]; else p[x] = a[2][tot2++]; } for (LL i = 0; i < V[1].size(); ++i) { LL x(V[1][i]); if (tot2 < a[2].size()) p[x] = a[2][tot2++]; else if (tot0 < a[0].size()) p[x] = a[0][tot0++]; else p[x] = a[1][tot1++]; } for (LL i = 1; i <= n; ++i) printf("%d ", p[i]); puts(""); return 0; }
#include <bits/stdc++.h> typedef int LL; #define pb push_back const LL maxn = 1e6 + 9; struct node { LL to, nxt; } dis[maxn]; LL n, num; LL head[maxn], p[maxn], dep[maxn]; std::vector<LL> V[3], a[3]; void Add(LL u, LL v) { dis[++num] = (node){v, head[u]}; head[u] = num; } void Dfs(LL u, LL f) { V[dep[u]].pb(u); for (LL i = head[u]; i; i = dis[i].nxt) { LL v(dis[i].to); if (v == f) continue; dep[v] = (dep[u] ^ 1); Dfs(v, u); } } int main() { scanf("%d", &n); for (LL i = 1; i < n; ++i) { LL u, v; scanf("%d%d", &u, &v); Add(u, v); Add(v, u); } for (LL i = 1; i <= n; ++i) { a[i % 3].pb(i); } LL ret(n / 3); Dfs(1, 0); if (V[0].size() > V[1].size()) std::swap(V[0], V[1]); LL tot0(0), tot1(0), tot2(0); if (V[0].size() <= ret) { for (LL i = 0; i < V[0].size(); ++i) { LL x(V[0][i]); p[x] = a[0][tot0++]; } for (LL i = 0; i < V[1].size(); ++i) { LL x(V[1][i]); if (tot2 < a[2].size()) p[x] = a[2][tot2++]; else if (tot0 < a[0].size()) p[x] = a[0][tot0++]; else p[x] = a[1][tot1++]; } for (LL i = 1; i <= n; ++i) printf("%d ", p[i]); puts(""); return 0; } for (LL i = 0; i < V[0].size(); ++i) { LL x(V[0][i]); if (tot1 < a[1].size()) p[x] = a[1][tot1++]; else if (tot0 < a[0].size()) p[x] = a[0][tot0++]; else p[x] = a[2][tot2++]; } for (LL i = 0; i < V[1].size(); ++i) { LL x(V[1][i]); if (tot2 < a[2].size()) p[x] = a[2][tot2++]; else if (tot0 < a[0].size()) p[x] = a[0][tot0++]; else p[x] = a[1][tot1++]; } for (LL i = 1; i <= n; ++i) printf("%d ", p[i]); puts(""); return 0; }
replace
46
47
46
47
0
p02749
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using ll = long long int; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>; using P = pair<int, int>; using Pll = pair<ll, ll>; using cdouble = complex<double>; const double eps = 1e-7; #define Loop(i, n) for (int i = 0; i < int(n); i++) #define Loopll(i, n) for (ll i = 0; i < ll(n); i++) #define Loop1(i, n) for (int i = 1; i <= int(n); i++) #define Loopll1(i, n) for (ll i = 1; i <= ll(n); i++) #define Loopr(i, n) for (int i = int(n) - 1; i >= 0; i--) #define Looprll(i, n) for (ll i = ll(n) - 1; i >= 0; i--) #define Loopr1(i, n) for (int i = int(n); i >= 1; i--) #define Looprll1(i, n) for (ll i = ll(n); i >= 1; i--) #define Foreach(buf, container) for (const auto &buf : container) #define Foreachr(buf, container) for (const auto &buf : reversed(container)) #define Loopdiag(i, j, h, w, sum) \ for (int i = ((sum) >= (h) ? (h)-1 : (sum)), j = (sum)-i; i >= 0 && j < (w); \ i--, j++) #define Loopdiagr(i, j, h, w, sum) \ for (int j = ((sum) >= (w) ? (w)-1 : (sum)), i = (sum)-j; j >= 0 && i < (h); \ j--, i++) #define Loopdiagsym(i, j, h, w, gap) \ for (int i = ((gap) >= 0 ? (gap) : 0), j = i - (gap); i < (h) && j < (w); \ i++, j++) #define Loopdiagsymr(i, j, h, w, gap) \ for (int i = ((gap) > (h) - (w)-1 ? (h)-1 : (w)-1 + (gap)), j = i - (gap); \ i >= 0 && j >= 0; i--, j--) #define Loopitr(itr, container) \ for (auto itr = container.begin(); itr != container.end(); itr++) #define quickio() \ ios::sync_with_stdio(false); \ cin.tie(0); #define endl "\n" #define bitmanip(m, val) static_cast<bitset<(int)m>>(val) #define Comp(type_t) bool operator<(const type_t &another) const #define fst first #define snd second #define INF INFINITY bool feq(double x, double y) { return abs(x - y) <= eps; } bool inrange(ll x, ll t) { return x >= 0 && x < t; } bool inrange(vll xs, ll t) { Foreach(x, xs) if (!(x >= 0 && x < t)) return false; return true; } int ceillog2(ll x) { return int(ceil(log2(x))); } int floorlog2(ll x) { return int(floor(log2(x))); } template <class T> T reversed(T container) { reverse(container.begin(), container.end()); return container; } template <class T> void printv(const vector<T> &v) { for (const T &x : v) cout << x << " "; cout << endl; } template <class T> void printmx(const vector<vector<T>> &mx) { for (const vector<T> &v : mx) printv(v); } ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); } ll floorsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (m * m <= x ? 0 : -1); } ll ceilsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (x <= m * m ? 0 : 1); } ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); } ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); } ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); } ll lcm(ll m, ll n) { return m * n / gcd(m, n); } //========================================================================// struct tree_t { using nodeval_t = int; using edgeval_t = int; int n; // |V|, index begins with 0 vector<P> edges; // E vector<nodeval_t> vals; // value of nodes vector<edgeval_t> costs; // cost, distance, or weight of edges }; // a should be sorted, return will be the root template <class val_t, class tree_t> int make_treap(const vector<val_t> &a, const tree_t &T, int l = 0, int r = -1, int p = -1) { if (r == -1) { r = a.size(); T.n = a.size(); } if (r - l == 0) return -1; int mid = (l + r) / 2; if (p != -1) T.edges.push_back({mid, p}); make_treap(a, T, l, mid, mid); make_treap(a, T, mid + 1, r, mid); return mid; } // #define ANCESTOR // #define HLD class Tree { using nodeval_t = int; using edgeval_t = int; private: struct node { vi childs; int parent = -1; int deg = -1; // the number of edges of the path to the root int eid = -1; // edge id of the edge connected by its parent and itself int subtree_n = 1; // the number of nodes of the partial tree rooted by itself #ifdef ANCESTOR int visited = -1; // time stamp of visiting on DFS, call // solve_sprs_ancestors() for activation int departed = -1; // time stamp of departure on DFS, call // solve_sprs_ancestors() for activation #endif #ifdef HLD int pid = -1; // path id of heavy light decompotion int qid = -1; // id in its path #endif nodeval_t val; // value of the node itself edgeval_t cost; // cost of the edge connected by its parent and itself }; struct edgeinfo_t { int eid; int to; edgeval_t cost; }; int n; static const nodeval_t init_val = 0; static const edgeval_t init_cost = 1; #ifdef ANCESTOR vvi sprs_ancestors; // (1 << j)-th ancestors in each node_id = i #endif #ifdef HLD vvi hld_paths; // paths #endif void tree_construction(const vector<vector<edgeinfo_t>> &edges) { leaves = {}; queue<int> que; que.push(root); while (que.size()) { int a = que.front(); que.pop(); deg_order.push_back(a); if (a == Tree::root) nodes[a].deg = 0; int leaf_flag = true; Loop(i, edges[a].size()) { int b = edges[a][i].to; if (nodes[b].deg != -1) { nodes[a].parent = b; nodes[a].eid = edges[a][i].eid; nodes[a].cost = edges[a][i].cost; nodes[a].deg = nodes[b].deg + 1; } else { leaf_flag = false; nodes[a].childs.push_back(b); que.push(b); } } if (leaf_flag) leaves.push_back(a); } Loopr(i, n) { int a = deg_order[i]; Loop(j, nodes[a].childs.size()) { int b = nodes[a].childs[j]; nodes[a].subtree_n += nodes[b].subtree_n; } } } public: vector<node> nodes; vi deg_order; // node ids, sorted by deg vi leaves; int root; public: // T should be non-empty tree Tree(const tree_t &T, int root) { this->n = T.n; this->root = root; nodes.resize(n); Loop(i, n) { nodes[i].val = (int)(T.vals.size()) > i ? T.vals[i] : init_val; nodes[i].cost = init_cost; } vector<vector<edgeinfo_t>> edges(n); Loop(i, n - 1) { edges[T.edges[i].fst].push_back( {i, T.edges[i].snd, ((int)(T.costs.size()) > i ? T.costs[i] : init_cost)}); edges[T.edges[i].snd].push_back( {i, T.edges[i].fst, ((int)(T.costs.size()) > i ? T.costs[i] : init_cost)}); } tree_construction(edges); return; } int solve_diameter() { vi d(n, -1); queue<int> que; d[deg_order[n - 1]] = 0; que.push(deg_order[n - 1]); while (que.size()) { int a = que.front(); que.pop(); int p = nodes[a].parent; if (d[p] == -1) { d[p] = d[a] + 1; que.push(nodes[a].parent); } Foreach(b, nodes[a].childs) { if (d[b] == -1) { d[b] = d[a] + 1; que.push(b); } } } return *max_element(d.begin(), d.end()); } pair<int, vi> solve_center_of_gravity() { pair<int, vi> ret = {INT_MAX, {}}; vi record(n, 1); Foreach(a, deg_order) { int x = n - 1, max_x = INT_MIN; Foreach(b, nodes[a].childs) { max_x = max(max_x, record[b]); x -= record[b]; record[a] += record[b]; } max_x = max(max_x, x); if (max_x < ret.fst) ret = {max_x, {a}}; else if (max_x == ret.fst) ret.snd.push_back(a); } sort(ret.snd.begin(), ret.snd.end()); return ret; } vi solve_node_inclusion_cnt_in_all_path(bool enable_single_node_path) { vi ret(n, 0); Loop(i, n) { int a = i; // desendants to desendants Foreach(b, nodes[a].childs) { ret[i] += nodes[b].subtree_n * (nodes[a].subtree_n - nodes[b].subtree_n - 1); } ret[i] /= 2; // because of double counting ret[i] += (nodes[a].subtree_n - 1) * (n - nodes[a].subtree_n); // desendants to the others except for itself ret[i] += n - 1; // itself to the others if (enable_single_node_path) ret[i]++; // itself } return ret; } vi solve_edge_inclusion_cnt_in_all_path() { vi ret(n - 1, 0); Loop(i, n) { int eid = nodes[i].eid; if (eid < 0) continue; ret[eid] = nodes[i].subtree_n * (n - nodes[i].subtree_n); // members in the partial tree to the others } return ret; } #ifdef ANCESTOR void solve_sprs_ancestors() { sprs_ancestors.resize(n); vector<int> current_ancestors; stack<int> stk; stk.push(Tree::root); int time_stamp = 0; while (stk.size()) { int a = stk.top(); stk.pop(); nodes[a].visited = time_stamp++; for (int i = 1; i <= (int)(current_ancestors.size()); i *= 2) { sprs_ancestors[a].push_back( current_ancestors[current_ancestors.size() - i]); } if (nodes[a].childs.size()) { Loop(i, nodes[a].childs.size()) { stk.push(nodes[a].childs[i]); } current_ancestors.push_back(a); } else { nodes[a].departed = time_stamp++; while (current_ancestors.size() && (stk.empty() || nodes[stk.top()].parent != current_ancestors.back())) { nodes[current_ancestors.back()].departed = time_stamp++; current_ancestors.pop_back(); } } } return; } bool is_ancestor(int descendant, int ancestor) { return nodes[ancestor].visited < nodes[descendant].visited && nodes[descendant].departed < nodes[ancestor].departed; } int get_lowest_common_ancestor(int u, int v) { if (u == v) return u; if (is_ancestor(u, v)) return v; if (is_ancestor(v, u)) return u; int a = u; while (!is_ancestor(v, sprs_ancestors[a][0])) { int b = sprs_ancestors[a][0]; Loop1(i, sprs_ancestors[a].size() - 1) { if (is_ancestor(v, sprs_ancestors[a][i])) break; else b = sprs_ancestors[a][i - 1]; } a = b; } return sprs_ancestors[a][0]; } int get_ancestor(int descendant, int k) { if (k == 0) return descendant; int l = (int)log2(k); if (l >= sprs_ancestors[descendant].size()) return -1; else return get_ancestor(sprs_ancestors[descendant][l], k - (1 << l)); } // return first value causing "t" in evalfunc that returns // descendant->[f,...,f,t,...,t]->root NOTE: if [f,...,f] then return -1 template <typename bsargv_t> int binary_search_upper_ancestor(int descendant, const bsargv_t &bsargv, bool (*evalfunc)(int, const bsargv_t &)) { if (evalfunc(descendant, bsargv)) return descendant; if (descendant == root) return -1; Loop(i, sprs_ancestors[descendant].size()) { if (evalfunc(sprs_ancestors[descendant][i], bsargv)) { if (i == 0) return binary_search_upper_ancestor(sprs_ancestors[descendant][0], bsargv, evalfunc); else return binary_search_upper_ancestor(sprs_ancestors[descendant][i - 1], bsargv, evalfunc); } } return binary_search_upper_ancestor(sprs_ancestors[descendant].back(), bsargv, evalfunc); } // return last value causing "t" in evalfunc that returns // descendant->[t,...,t,f,...,f]->root NOTE: if [f,...,f] then return -1 template <typename bsargv_t> int binary_search_lower_ancestor(int descendant, const bsargv_t &bsargv, bool (*evalfunc)(int, const bsargv_t &)) { if (!evalfunc(descendant, bsargv)) return -1; if (descendant == root) return root; Loop(i, sprs_ancestors[descendant].size()) { if (!evalfunc(sprs_ancestors[descendant][i], bsargv)) { if (i == 0) return descendant; else return binary_search_lower_ancestor(sprs_ancestors[descendant][i - 1], bsargv, evalfunc); } } return binary_search_lower_ancestor(sprs_ancestors[descendant].back(), bsargv, evalfunc); } // static bool evalfunc(int id, bsargv_t bsargv); #endif #ifdef HLD void solve_hld() { Foreach(a, deg_order) { if (nodes[a].pid == -1) { nodes[a].pid = int(hld_paths.size()); nodes[a].qid = 0; hld_paths.push_back({a}); } int max_id = -1; int max_subtree_n = 0; Foreach(b, nodes[a].childs) { if (nodes[b].subtree_n > max_subtree_n) { max_id = b; max_subtree_n = nodes[b].subtree_n; } } if (max_id == -1) continue; nodes[max_id].pid = nodes[a].pid; nodes[max_id].qid = nodes[a].qid + 1; hld_paths[nodes[a].pid].push_back(max_id); } } struct pathinfo_t { int id; int l, r; // [l, r) }; // return all node ids in the single path vector<int> get_ids_in_path(const pathinfo_t &pathinfo) { vi ret(pathinfo.r - pathinfo.l); Loop(i, ret.size()) { ret[i] = hld_paths[pathinfo.id][pathinfo.l + i]; } return ret; } // if weight is for each node, include_lca = true // if weight is for each edge, include_lca = false vector<pathinfo_t> get_path_in_hld(int u, int v, bool include_lca) { vector<pathinfo_t> ret; int w = get_lowest_common_ancestor(u, v); Foreach(x, vector<int>({u, v})) { int a = x; while (a != w) { if (nodes[a].pid != nodes[w].pid) { ret.push_back({nodes[a].pid, 0, nodes[a].qid + 1}); a = nodes[hld_paths[nodes[a].pid][0]].parent; } else { ret.push_back({nodes[a].pid, nodes[w].qid + 1, nodes[a].qid + 1}); a = w; } } } if (include_lca) { Loop(i, ret.size()) { if (nodes[w].pid == ret[i].id) { ret[i].l -= 1; include_lca = false; } } } if (include_lca) { ret.push_back({nodes[w].pid, nodes[w].qid, nodes[w].qid + 1}); } return ret; } vi get_hld_path_sizes() { vi ret(hld_paths.size()); Loop(i, hld_paths.size()) { ret[i] = int(hld_paths[i].size()); } return ret; } int get_hld_path_size(int pid) { return int(hld_paths[pid].size()); } #endif }; void failed() { cout << -1 << endl; } int main() { quickio(); tree_t T; cin >> T.n; Loop(i, T.n - 1) { int s, t; cin >> s >> t; s--; t--; T.edges.push_back({s, t}); } Tree *tree = new Tree(T, 0); vi a, b; Foreach(x, tree->deg_order) { int deg = tree->nodes[x].deg; if (deg & 1) a.push_back(x); else b.push_back(x); } if (a.size() < b.size()) swap(a, b); int p = 0, q = 0; vi ans(T.n); vi used(T.n + 1); Loop1(u, T.n) { if (u % 3 == 1) p++; else if (u % 3 == 2) q++; } if (b.size() < q) { int u = 3; Foreach(x, b) { ans[x] = u; used[u] = 1; u += 3; } u = 1; Foreach(x, a) { while (used[u]) ++u; ans[x] = u; used[u] = 1; } } else { int i = 0, j = 0; Loop1(u, T.n) { if (u % 3 == 1) { ans[a[i]] = u; ++i; } else if (u % 3 == 2) { ans[b[j]] = u; ++j; } } int u = 3; Loop1(x, T.n) { ans[x] = u; u += 3; } } printv(ans); }
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using ll = long long int; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vd = vector<double>; using vvd = vector<vd>; using vvvd = vector<vvd>; using P = pair<int, int>; using Pll = pair<ll, ll>; using cdouble = complex<double>; const double eps = 1e-7; #define Loop(i, n) for (int i = 0; i < int(n); i++) #define Loopll(i, n) for (ll i = 0; i < ll(n); i++) #define Loop1(i, n) for (int i = 1; i <= int(n); i++) #define Loopll1(i, n) for (ll i = 1; i <= ll(n); i++) #define Loopr(i, n) for (int i = int(n) - 1; i >= 0; i--) #define Looprll(i, n) for (ll i = ll(n) - 1; i >= 0; i--) #define Loopr1(i, n) for (int i = int(n); i >= 1; i--) #define Looprll1(i, n) for (ll i = ll(n); i >= 1; i--) #define Foreach(buf, container) for (const auto &buf : container) #define Foreachr(buf, container) for (const auto &buf : reversed(container)) #define Loopdiag(i, j, h, w, sum) \ for (int i = ((sum) >= (h) ? (h)-1 : (sum)), j = (sum)-i; i >= 0 && j < (w); \ i--, j++) #define Loopdiagr(i, j, h, w, sum) \ for (int j = ((sum) >= (w) ? (w)-1 : (sum)), i = (sum)-j; j >= 0 && i < (h); \ j--, i++) #define Loopdiagsym(i, j, h, w, gap) \ for (int i = ((gap) >= 0 ? (gap) : 0), j = i - (gap); i < (h) && j < (w); \ i++, j++) #define Loopdiagsymr(i, j, h, w, gap) \ for (int i = ((gap) > (h) - (w)-1 ? (h)-1 : (w)-1 + (gap)), j = i - (gap); \ i >= 0 && j >= 0; i--, j--) #define Loopitr(itr, container) \ for (auto itr = container.begin(); itr != container.end(); itr++) #define quickio() \ ios::sync_with_stdio(false); \ cin.tie(0); #define endl "\n" #define bitmanip(m, val) static_cast<bitset<(int)m>>(val) #define Comp(type_t) bool operator<(const type_t &another) const #define fst first #define snd second #define INF INFINITY bool feq(double x, double y) { return abs(x - y) <= eps; } bool inrange(ll x, ll t) { return x >= 0 && x < t; } bool inrange(vll xs, ll t) { Foreach(x, xs) if (!(x >= 0 && x < t)) return false; return true; } int ceillog2(ll x) { return int(ceil(log2(x))); } int floorlog2(ll x) { return int(floor(log2(x))); } template <class T> T reversed(T container) { reverse(container.begin(), container.end()); return container; } template <class T> void printv(const vector<T> &v) { for (const T &x : v) cout << x << " "; cout << endl; } template <class T> void printmx(const vector<vector<T>> &mx) { for (const vector<T> &v : mx) printv(v); } ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); } ll floorsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (m * m <= x ? 0 : -1); } ll ceilsqrt(ll x) { ll m = (ll)sqrt((double)x); return m + (x <= m * m ? 0 : 1); } ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); } ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); } ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); } ll lcm(ll m, ll n) { return m * n / gcd(m, n); } //========================================================================// struct tree_t { using nodeval_t = int; using edgeval_t = int; int n; // |V|, index begins with 0 vector<P> edges; // E vector<nodeval_t> vals; // value of nodes vector<edgeval_t> costs; // cost, distance, or weight of edges }; // a should be sorted, return will be the root template <class val_t, class tree_t> int make_treap(const vector<val_t> &a, const tree_t &T, int l = 0, int r = -1, int p = -1) { if (r == -1) { r = a.size(); T.n = a.size(); } if (r - l == 0) return -1; int mid = (l + r) / 2; if (p != -1) T.edges.push_back({mid, p}); make_treap(a, T, l, mid, mid); make_treap(a, T, mid + 1, r, mid); return mid; } // #define ANCESTOR // #define HLD class Tree { using nodeval_t = int; using edgeval_t = int; private: struct node { vi childs; int parent = -1; int deg = -1; // the number of edges of the path to the root int eid = -1; // edge id of the edge connected by its parent and itself int subtree_n = 1; // the number of nodes of the partial tree rooted by itself #ifdef ANCESTOR int visited = -1; // time stamp of visiting on DFS, call // solve_sprs_ancestors() for activation int departed = -1; // time stamp of departure on DFS, call // solve_sprs_ancestors() for activation #endif #ifdef HLD int pid = -1; // path id of heavy light decompotion int qid = -1; // id in its path #endif nodeval_t val; // value of the node itself edgeval_t cost; // cost of the edge connected by its parent and itself }; struct edgeinfo_t { int eid; int to; edgeval_t cost; }; int n; static const nodeval_t init_val = 0; static const edgeval_t init_cost = 1; #ifdef ANCESTOR vvi sprs_ancestors; // (1 << j)-th ancestors in each node_id = i #endif #ifdef HLD vvi hld_paths; // paths #endif void tree_construction(const vector<vector<edgeinfo_t>> &edges) { leaves = {}; queue<int> que; que.push(root); while (que.size()) { int a = que.front(); que.pop(); deg_order.push_back(a); if (a == Tree::root) nodes[a].deg = 0; int leaf_flag = true; Loop(i, edges[a].size()) { int b = edges[a][i].to; if (nodes[b].deg != -1) { nodes[a].parent = b; nodes[a].eid = edges[a][i].eid; nodes[a].cost = edges[a][i].cost; nodes[a].deg = nodes[b].deg + 1; } else { leaf_flag = false; nodes[a].childs.push_back(b); que.push(b); } } if (leaf_flag) leaves.push_back(a); } Loopr(i, n) { int a = deg_order[i]; Loop(j, nodes[a].childs.size()) { int b = nodes[a].childs[j]; nodes[a].subtree_n += nodes[b].subtree_n; } } } public: vector<node> nodes; vi deg_order; // node ids, sorted by deg vi leaves; int root; public: // T should be non-empty tree Tree(const tree_t &T, int root) { this->n = T.n; this->root = root; nodes.resize(n); Loop(i, n) { nodes[i].val = (int)(T.vals.size()) > i ? T.vals[i] : init_val; nodes[i].cost = init_cost; } vector<vector<edgeinfo_t>> edges(n); Loop(i, n - 1) { edges[T.edges[i].fst].push_back( {i, T.edges[i].snd, ((int)(T.costs.size()) > i ? T.costs[i] : init_cost)}); edges[T.edges[i].snd].push_back( {i, T.edges[i].fst, ((int)(T.costs.size()) > i ? T.costs[i] : init_cost)}); } tree_construction(edges); return; } int solve_diameter() { vi d(n, -1); queue<int> que; d[deg_order[n - 1]] = 0; que.push(deg_order[n - 1]); while (que.size()) { int a = que.front(); que.pop(); int p = nodes[a].parent; if (d[p] == -1) { d[p] = d[a] + 1; que.push(nodes[a].parent); } Foreach(b, nodes[a].childs) { if (d[b] == -1) { d[b] = d[a] + 1; que.push(b); } } } return *max_element(d.begin(), d.end()); } pair<int, vi> solve_center_of_gravity() { pair<int, vi> ret = {INT_MAX, {}}; vi record(n, 1); Foreach(a, deg_order) { int x = n - 1, max_x = INT_MIN; Foreach(b, nodes[a].childs) { max_x = max(max_x, record[b]); x -= record[b]; record[a] += record[b]; } max_x = max(max_x, x); if (max_x < ret.fst) ret = {max_x, {a}}; else if (max_x == ret.fst) ret.snd.push_back(a); } sort(ret.snd.begin(), ret.snd.end()); return ret; } vi solve_node_inclusion_cnt_in_all_path(bool enable_single_node_path) { vi ret(n, 0); Loop(i, n) { int a = i; // desendants to desendants Foreach(b, nodes[a].childs) { ret[i] += nodes[b].subtree_n * (nodes[a].subtree_n - nodes[b].subtree_n - 1); } ret[i] /= 2; // because of double counting ret[i] += (nodes[a].subtree_n - 1) * (n - nodes[a].subtree_n); // desendants to the others except for itself ret[i] += n - 1; // itself to the others if (enable_single_node_path) ret[i]++; // itself } return ret; } vi solve_edge_inclusion_cnt_in_all_path() { vi ret(n - 1, 0); Loop(i, n) { int eid = nodes[i].eid; if (eid < 0) continue; ret[eid] = nodes[i].subtree_n * (n - nodes[i].subtree_n); // members in the partial tree to the others } return ret; } #ifdef ANCESTOR void solve_sprs_ancestors() { sprs_ancestors.resize(n); vector<int> current_ancestors; stack<int> stk; stk.push(Tree::root); int time_stamp = 0; while (stk.size()) { int a = stk.top(); stk.pop(); nodes[a].visited = time_stamp++; for (int i = 1; i <= (int)(current_ancestors.size()); i *= 2) { sprs_ancestors[a].push_back( current_ancestors[current_ancestors.size() - i]); } if (nodes[a].childs.size()) { Loop(i, nodes[a].childs.size()) { stk.push(nodes[a].childs[i]); } current_ancestors.push_back(a); } else { nodes[a].departed = time_stamp++; while (current_ancestors.size() && (stk.empty() || nodes[stk.top()].parent != current_ancestors.back())) { nodes[current_ancestors.back()].departed = time_stamp++; current_ancestors.pop_back(); } } } return; } bool is_ancestor(int descendant, int ancestor) { return nodes[ancestor].visited < nodes[descendant].visited && nodes[descendant].departed < nodes[ancestor].departed; } int get_lowest_common_ancestor(int u, int v) { if (u == v) return u; if (is_ancestor(u, v)) return v; if (is_ancestor(v, u)) return u; int a = u; while (!is_ancestor(v, sprs_ancestors[a][0])) { int b = sprs_ancestors[a][0]; Loop1(i, sprs_ancestors[a].size() - 1) { if (is_ancestor(v, sprs_ancestors[a][i])) break; else b = sprs_ancestors[a][i - 1]; } a = b; } return sprs_ancestors[a][0]; } int get_ancestor(int descendant, int k) { if (k == 0) return descendant; int l = (int)log2(k); if (l >= sprs_ancestors[descendant].size()) return -1; else return get_ancestor(sprs_ancestors[descendant][l], k - (1 << l)); } // return first value causing "t" in evalfunc that returns // descendant->[f,...,f,t,...,t]->root NOTE: if [f,...,f] then return -1 template <typename bsargv_t> int binary_search_upper_ancestor(int descendant, const bsargv_t &bsargv, bool (*evalfunc)(int, const bsargv_t &)) { if (evalfunc(descendant, bsargv)) return descendant; if (descendant == root) return -1; Loop(i, sprs_ancestors[descendant].size()) { if (evalfunc(sprs_ancestors[descendant][i], bsargv)) { if (i == 0) return binary_search_upper_ancestor(sprs_ancestors[descendant][0], bsargv, evalfunc); else return binary_search_upper_ancestor(sprs_ancestors[descendant][i - 1], bsargv, evalfunc); } } return binary_search_upper_ancestor(sprs_ancestors[descendant].back(), bsargv, evalfunc); } // return last value causing "t" in evalfunc that returns // descendant->[t,...,t,f,...,f]->root NOTE: if [f,...,f] then return -1 template <typename bsargv_t> int binary_search_lower_ancestor(int descendant, const bsargv_t &bsargv, bool (*evalfunc)(int, const bsargv_t &)) { if (!evalfunc(descendant, bsargv)) return -1; if (descendant == root) return root; Loop(i, sprs_ancestors[descendant].size()) { if (!evalfunc(sprs_ancestors[descendant][i], bsargv)) { if (i == 0) return descendant; else return binary_search_lower_ancestor(sprs_ancestors[descendant][i - 1], bsargv, evalfunc); } } return binary_search_lower_ancestor(sprs_ancestors[descendant].back(), bsargv, evalfunc); } // static bool evalfunc(int id, bsargv_t bsargv); #endif #ifdef HLD void solve_hld() { Foreach(a, deg_order) { if (nodes[a].pid == -1) { nodes[a].pid = int(hld_paths.size()); nodes[a].qid = 0; hld_paths.push_back({a}); } int max_id = -1; int max_subtree_n = 0; Foreach(b, nodes[a].childs) { if (nodes[b].subtree_n > max_subtree_n) { max_id = b; max_subtree_n = nodes[b].subtree_n; } } if (max_id == -1) continue; nodes[max_id].pid = nodes[a].pid; nodes[max_id].qid = nodes[a].qid + 1; hld_paths[nodes[a].pid].push_back(max_id); } } struct pathinfo_t { int id; int l, r; // [l, r) }; // return all node ids in the single path vector<int> get_ids_in_path(const pathinfo_t &pathinfo) { vi ret(pathinfo.r - pathinfo.l); Loop(i, ret.size()) { ret[i] = hld_paths[pathinfo.id][pathinfo.l + i]; } return ret; } // if weight is for each node, include_lca = true // if weight is for each edge, include_lca = false vector<pathinfo_t> get_path_in_hld(int u, int v, bool include_lca) { vector<pathinfo_t> ret; int w = get_lowest_common_ancestor(u, v); Foreach(x, vector<int>({u, v})) { int a = x; while (a != w) { if (nodes[a].pid != nodes[w].pid) { ret.push_back({nodes[a].pid, 0, nodes[a].qid + 1}); a = nodes[hld_paths[nodes[a].pid][0]].parent; } else { ret.push_back({nodes[a].pid, nodes[w].qid + 1, nodes[a].qid + 1}); a = w; } } } if (include_lca) { Loop(i, ret.size()) { if (nodes[w].pid == ret[i].id) { ret[i].l -= 1; include_lca = false; } } } if (include_lca) { ret.push_back({nodes[w].pid, nodes[w].qid, nodes[w].qid + 1}); } return ret; } vi get_hld_path_sizes() { vi ret(hld_paths.size()); Loop(i, hld_paths.size()) { ret[i] = int(hld_paths[i].size()); } return ret; } int get_hld_path_size(int pid) { return int(hld_paths[pid].size()); } #endif }; void failed() { cout << -1 << endl; } int main() { quickio(); tree_t T; cin >> T.n; Loop(i, T.n - 1) { int s, t; cin >> s >> t; s--; t--; T.edges.push_back({s, t}); } Tree *tree = new Tree(T, 0); vi a, b; Foreach(x, tree->deg_order) { int deg = tree->nodes[x].deg; if (deg & 1) a.push_back(x); else b.push_back(x); } if (a.size() < b.size()) swap(a, b); int p = 0, q = 0; vi ans(T.n); vi used(T.n + 1); Loop1(u, T.n) { if (u % 3 == 1) p++; else if (u % 3 == 2) q++; } if (b.size() < q) { int u = 3; Foreach(x, b) { ans[x] = u; used[u] = 1; u += 3; } u = 1; Foreach(x, a) { while (used[u]) ++u; ans[x] = u; used[u] = 1; } } else { int i = 0, j = 0; Loop1(u, T.n) { if (u % 3 == 1) { ans[a[i]] = u; ++i; } else if (u % 3 == 2) { ans[b[j]] = u; ++j; } } int u = 3; Loop(x, T.n) { if (ans[x] == 0) { ans[x] = u; u += 3; } } } printv(ans); }
replace
537
540
537
542
0
p02749
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <queue> using namespace std; typedef long long ll; const int MAXN = 2e5 + 5; struct Edge { int next, to; } e[MAXN << 1]; int head[MAXN], etot = 0; inline void add(int u, int v) { e[++etot] = (Edge){head[u], v}; head[u] = etot; } int clr[MAXN], ccnt[3]; void dfs(int u, int fa) { ++ccnt[clr[u]]; for (int i = head[u]; i; i = e[i].next) { int v = e[i].to; if (v == fa) continue; clr[v] = !clr[u]; dfs(v, u); } } queue<int> q[4]; int main(void) { int n; scanf("%d", &n); for (int i = 1; i < n; ++i) { int u, v; scanf("%d%d", &u, &v); add(u, v); add(v, u); } dfs(1, 0); for (int i = 1; i <= n; ++i) q[i % 3].push(i); int c1 = q[1].size(); int c2 = q[2].size(); if (c1 <= ccnt[0] && c2 <= ccnt[1]) for (int i = 1; i <= n; ++i) { int x = clr[i] + 1; if (q[x].empty()) x = 0; printf("%d ", q[x].front()); q[x].pop(); } else if (c1 <= ccnt[0] && c2 <= ccnt[0]) for (int i = 1; i <= n; ++i) { int x = (!clr[i]) + 1; if (q[x].empty()) x = 0; printf("%d ", q[x].front()); q[x].pop(); } else if (c1 + c2 <= ccnt[0]) for (int i = 1; i <= n; ++i) { int x; if (clr[i]) x = 0; else if (!q[1].empty()) x = 1; else if (!q[2].empty()) x = 2; else x = 0; printf("%d ", q[x].front()); q[x].pop(); } else if (c1 + c2 <= ccnt[1]) for (int i = 1; i <= n; ++i) { int x; if (!clr[i]) x = 0; else if (!q[1].empty()) x = 1; else if (!q[2].empty()) x = 2; else x = 0; printf("%d ", q[x].front()); q[x].pop(); } else printf("-1"); return 0; }
#include <algorithm> #include <cstdio> #include <queue> using namespace std; typedef long long ll; const int MAXN = 2e5 + 5; struct Edge { int next, to; } e[MAXN << 1]; int head[MAXN], etot = 0; inline void add(int u, int v) { e[++etot] = (Edge){head[u], v}; head[u] = etot; } int clr[MAXN], ccnt[3]; void dfs(int u, int fa) { ++ccnt[clr[u]]; for (int i = head[u]; i; i = e[i].next) { int v = e[i].to; if (v == fa) continue; clr[v] = !clr[u]; dfs(v, u); } } queue<int> q[4]; int main(void) { int n; scanf("%d", &n); for (int i = 1; i < n; ++i) { int u, v; scanf("%d%d", &u, &v); add(u, v); add(v, u); } dfs(1, 0); for (int i = 1; i <= n; ++i) q[i % 3].push(i); int c1 = q[1].size(); int c2 = q[2].size(); if (c1 <= ccnt[0] && c2 <= ccnt[1]) for (int i = 1; i <= n; ++i) { int x = clr[i] + 1; if (q[x].empty()) x = 0; printf("%d ", q[x].front()); q[x].pop(); } else if (c1 <= ccnt[1] && c2 <= ccnt[0]) for (int i = 1; i <= n; ++i) { int x = (!clr[i]) + 1; if (q[x].empty()) x = 0; printf("%d ", q[x].front()); q[x].pop(); } else if (c1 + c2 <= ccnt[0]) for (int i = 1; i <= n; ++i) { int x; if (clr[i]) x = 0; else if (!q[1].empty()) x = 1; else if (!q[2].empty()) x = 2; else x = 0; printf("%d ", q[x].front()); q[x].pop(); } else if (c1 + c2 <= ccnt[1]) for (int i = 1; i <= n; ++i) { int x; if (!clr[i]) x = 0; else if (!q[1].empty()) x = 1; else if (!q[2].empty()) x = 2; else x = 0; printf("%d ", q[x].front()); q[x].pop(); } else printf("-1"); return 0; }
replace
55
56
55
56
0
p02749
C++
Runtime Error
#include <bits/stdc++.h> #define N 200002 using namespace std; vector<int> v[N], vv[2], nr[3]; int c[N], l[N]; void dfs(int i) { vv[l[i] % 2].push_back(i); for (auto it : v[i]) if (!l[it]) l[it] = l[i] + 1, dfs(it); } void ad(int i, int j) { c[vv[i].back()] = nr[j].back(); vv[i].pop_back(); nr[j].pop_back(); } int main() { int n, i, j, k; cin >> n; for (k = 1; k < n; k++) { cin >> i >> j; v[i].push_back(j); v[j].push_back(i); nr[k % 3].push_back(k); } nr[n % 3].push_back(n); l[1] = 1; dfs(1); if (vv[0].size() <= n / 3) { while (vv[0].size()) ad(0, 0); while (vv[1].size()) ad(1, nr[0].size() ? 0 : (nr[1].size() ? 1 : 2)); } else if (vv[1].size() <= 3) { while (vv[1].size()) ad(1, 0); while (vv[0].size()) ad(0, nr[0].size() ? 0 : (nr[1].size() ? 1 : 2)); } else { while (vv[0].size()) ad(0, nr[1].size() ? 1 : 0); while (vv[1].size()) ad(1, nr[0].size() ? 0 : 2); } for (i = 1; i <= n; i++) cout << c[i] << " "; return 0; }
#include <bits/stdc++.h> #define N 200002 using namespace std; vector<int> v[N], vv[2], nr[3]; int c[N], l[N]; void dfs(int i) { vv[l[i] % 2].push_back(i); for (auto it : v[i]) if (!l[it]) l[it] = l[i] + 1, dfs(it); } void ad(int i, int j) { c[vv[i].back()] = nr[j].back(); vv[i].pop_back(); nr[j].pop_back(); } int main() { int n, i, j, k; cin >> n; for (k = 1; k < n; k++) { cin >> i >> j; v[i].push_back(j); v[j].push_back(i); nr[k % 3].push_back(k); } nr[n % 3].push_back(n); l[1] = 1; dfs(1); if (vv[0].size() <= n / 3) { while (vv[0].size()) ad(0, 0); while (vv[1].size()) ad(1, nr[0].size() ? 0 : (nr[1].size() ? 1 : 2)); } else if (vv[1].size() <= n / 3) { while (vv[1].size()) ad(1, 0); while (vv[0].size()) ad(0, nr[0].size() ? 0 : (nr[1].size() ? 1 : 2)); } else { while (vv[0].size()) ad(0, nr[1].size() ? 1 : 0); while (vv[1].size()) ad(1, nr[0].size() ? 0 : 2); } for (i = 1; i <= n; i++) cout << c[i] << " "; return 0; }
replace
33
34
33
34
0
p02749
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define FOR(i, o, n) for (long long i = o; i < n; i++) #define FORR(x, arr) for (auto &x : arr) #define oneforall \ ios::sync_with_stdio(false); \ cin.tie(0); #define all(v) (v).begin(), (v).end() #define ini(...) \ int __VA_ARGS__; \ in(__VA_ARGS__) #define inl(...) \ long long __VA_ARGS__; \ in(__VA_ARGS__) #define ins(...) \ string __VA_ARGS__; \ in(__VA_ARGS__) const long long INF = 1e18; void in() {} template <typename T, class... U> void in(T &t, U &...u) { cin >> t; in(u...); } void out() { cout << "\n"; } template <typename T, class... U> void out(const T &t, const U &...u) { cout << t; if (sizeof...(u)) cout << " "; out(u...); } typedef vector<int> vi; typedef vector<long long> vl; typedef long long ll; typedef vector<pair<long, long>> vpll; typedef vector<pair<int, int>> vpii; vi adj[320000]; vi mod[3]; vi x[2]; void dfs(int x_, int visit, int x1) { x[x1].push_back(x_); FORR(tmp, adj[x_]) { if (tmp != visit) dfs(tmp, x_, x1 ^ 1); } } int main() { oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall ini( n); int tmp1[32000]; FOR(i, 1, n + 1) { mod[i % 3].push_back(i); } FOR(i, 0, n - 1) { ini(x4); ini(x4_); x4--; x4_--; adj[x4].push_back(x4_); adj[x4_].push_back(x4); } dfs(0, 0, 0); if (x[0].size() > x[1].size()) swap(x[0], x[1]); if (x[0].size() <= mod[0].size()) { while (x[0].size() and mod[0].size()) { int pos = x[0].back(); x[0].pop_back(); int pos1 = mod[0].back(); mod[0].pop_back(); tmp1[pos] = pos1; } FORR(tmp, x[1]) { FOR(i, 0, 3) { if (mod[i].size()) { int pos = mod[i].back(); mod[i].pop_back(); tmp1[tmp] = pos; break; } } } } else { while (x[0].size() and mod[2].size()) { int pos = x[0].back(); x[0].pop_back(); int pos1 = mod[2].back(); mod[2].pop_back(); tmp1[pos] = pos1; } while (x[1].size() and mod[1].size()) { int pos = x[1].back(); x[1].pop_back(); int pos1 = mod[1].back(); mod[1].pop_back(); tmp1[pos] = pos1; } FORR(tmp14, x[0]) { FOR(i, 0, 3) { if (mod[i].size()) { int pos = mod[i].back(); mod[i].pop_back(); tmp1[tmp14] = pos; break; } } } FORR(tmp, x[1]) { FOR(i, 0, 3) { if (mod[i].size()) { int pos = mod[i].back(); mod[i].pop_back(); tmp1[tmp] = pos; break; } } } } FOR(i, 0, n) { cout << tmp1[i] << " "; } return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, o, n) for (long long i = o; i < n; i++) #define FORR(x, arr) for (auto &x : arr) #define oneforall \ ios::sync_with_stdio(false); \ cin.tie(0); #define all(v) (v).begin(), (v).end() #define ini(...) \ int __VA_ARGS__; \ in(__VA_ARGS__) #define inl(...) \ long long __VA_ARGS__; \ in(__VA_ARGS__) #define ins(...) \ string __VA_ARGS__; \ in(__VA_ARGS__) const long long INF = 1e18; void in() {} template <typename T, class... U> void in(T &t, U &...u) { cin >> t; in(u...); } void out() { cout << "\n"; } template <typename T, class... U> void out(const T &t, const U &...u) { cout << t; if (sizeof...(u)) cout << " "; out(u...); } typedef vector<int> vi; typedef vector<long long> vl; typedef long long ll; typedef vector<pair<long, long>> vpll; typedef vector<pair<int, int>> vpii; vi adj[320000]; vi mod[3]; vi x[2]; void dfs(int x_, int visit, int x1) { x[x1].push_back(x_); FORR(tmp, adj[x_]) { if (tmp != visit) dfs(tmp, x_, x1 ^ 1); } } int main() { oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall oneforall ini( n); int tmp1[320000]; FOR(i, 1, n + 1) { mod[i % 3].push_back(i); } FOR(i, 0, n - 1) { ini(x4); ini(x4_); x4--; x4_--; adj[x4].push_back(x4_); adj[x4_].push_back(x4); } dfs(0, 0, 0); if (x[0].size() > x[1].size()) swap(x[0], x[1]); if (x[0].size() <= mod[0].size()) { while (x[0].size() and mod[0].size()) { int pos = x[0].back(); x[0].pop_back(); int pos1 = mod[0].back(); mod[0].pop_back(); tmp1[pos] = pos1; } FORR(tmp, x[1]) { FOR(i, 0, 3) { if (mod[i].size()) { int pos = mod[i].back(); mod[i].pop_back(); tmp1[tmp] = pos; break; } } } } else { while (x[0].size() and mod[2].size()) { int pos = x[0].back(); x[0].pop_back(); int pos1 = mod[2].back(); mod[2].pop_back(); tmp1[pos] = pos1; } while (x[1].size() and mod[1].size()) { int pos = x[1].back(); x[1].pop_back(); int pos1 = mod[1].back(); mod[1].pop_back(); tmp1[pos] = pos1; } FORR(tmp14, x[0]) { FOR(i, 0, 3) { if (mod[i].size()) { int pos = mod[i].back(); mod[i].pop_back(); tmp1[tmp14] = pos; break; } } } FORR(tmp, x[1]) { FOR(i, 0, 3) { if (mod[i].size()) { int pos = mod[i].back(); mod[i].pop_back(); tmp1[tmp] = pos; break; } } } } FOR(i, 0, n) { cout << tmp1[i] << " "; } return 0; }
replace
50
51
50
51
0
p02749
C++
Runtime Error
// //  main.cpp // #include <algorithm> #include <array> #include <assert.h> #include <complex> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <math.h> #include <memory> #include <queue> #include <random> #include <set> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; using ll = int64_t; using ull = uint64_t; constexpr ll LL_MAX = numeric_limits<ll>::max(); constexpr ull ULL_MAX = numeric_limits<ull>::max(); template <typename T> vector<T> make_vec_nd(T init, ll size) { return vector<T>(size, init); } template <typename T, typename... Args> auto make_vec_nd(T init, ll size, Args... rest) { auto inner = make_vec_nd(init, rest...); return vector<decltype(inner)>(size, inner); } #define rep(i, a, b) for (ll i = (a); i < (b); i++) #define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--) struct Node { ll parent = -1; vector<ll> child; ll depth = 0; }; void to_tree(vector<vector<ll>> &graph, vector<Node> &tree, vector<bool> &visited, ll node) { visited[node] = true; for (ll ch : graph[node]) { if (visited[ch]) { continue; } tree[ch].parent = node; tree[ch].depth = tree[node].depth + 1; tree[node].child.push_back(ch); to_tree(graph, tree, visited, ch); } } int main() { ll N; cin >> N; vector<vector<ll>> graph(N); rep(i, 0, N - 1) { ll a, b; cin >> a >> b; a--; b--; graph[a].push_back(b); graph[b].push_back(a); } vector<Node> tree(N); vector<bool> visited(N); to_tree(graph, tree, visited, 0); ll even_cnt = 0; rep(i, 0, N) { if (tree[i].depth % 2 == 0) { even_cnt++; } } ll odd_cnt = N - even_cnt; vector<ll> ans(N); vector<ll> zeros; vector<ll> ones; vector<ll> twes; vector<ll> onetwoes; rep(i, 1, N + 1) { if (i % 3 == 0) { zeros.push_back(i); } else if (i % 3 == 1) { ones.push_back(i); onetwoes.push_back(i); } else if (i % 3 == 2) { twes.push_back(i); onetwoes.push_back(i); } } if (even_cnt <= N / 3) { rep(i, 0, N) { if (tree[i].depth % 2 == 0) { ans[i] = zeros.back(); zeros.pop_back(); } else { if (!onetwoes.empty()) { ans[i] = onetwoes.back(); onetwoes.pop_back(); } else { ans[i] = zeros.back(); zeros.pop_back(); } } } } else if (odd_cnt <= N / 3) { rep(i, 0, N) { if (tree[i].depth % 2 == 1) { ans[i] = zeros.back(); zeros.pop_back(); } else { ans[i] = onetwoes.back(); onetwoes.pop_back(); } } } else { rep(i, 0, N) { if (tree[i].depth % 2 == 0) { if (!ones.empty()) { ans[i] = ones.back(); ones.pop_back(); } else { ans[i] = zeros.back(); zeros.pop_back(); } } else { if (!twes.empty()) { ans[i] = twes.back(); twes.pop_back(); } else { ans[i] = zeros.back(); zeros.pop_back(); } } } } rep(i, 0, N) { cout << ans[i]; if (i != N - 1) { cout << " "; } } cout << endl; } /* 10 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 */
// //  main.cpp // #include <algorithm> #include <array> #include <assert.h> #include <complex> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <math.h> #include <memory> #include <queue> #include <random> #include <set> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; using ll = int64_t; using ull = uint64_t; constexpr ll LL_MAX = numeric_limits<ll>::max(); constexpr ull ULL_MAX = numeric_limits<ull>::max(); template <typename T> vector<T> make_vec_nd(T init, ll size) { return vector<T>(size, init); } template <typename T, typename... Args> auto make_vec_nd(T init, ll size, Args... rest) { auto inner = make_vec_nd(init, rest...); return vector<decltype(inner)>(size, inner); } #define rep(i, a, b) for (ll i = (a); i < (b); i++) #define rrep(i, a, b) for (ll i = (a)-1; i >= (b); i--) struct Node { ll parent = -1; vector<ll> child; ll depth = 0; }; void to_tree(vector<vector<ll>> &graph, vector<Node> &tree, vector<bool> &visited, ll node) { visited[node] = true; for (ll ch : graph[node]) { if (visited[ch]) { continue; } tree[ch].parent = node; tree[ch].depth = tree[node].depth + 1; tree[node].child.push_back(ch); to_tree(graph, tree, visited, ch); } } int main() { ll N; cin >> N; vector<vector<ll>> graph(N); rep(i, 0, N - 1) { ll a, b; cin >> a >> b; a--; b--; graph[a].push_back(b); graph[b].push_back(a); } vector<Node> tree(N); vector<bool> visited(N); to_tree(graph, tree, visited, 0); ll even_cnt = 0; rep(i, 0, N) { if (tree[i].depth % 2 == 0) { even_cnt++; } } ll odd_cnt = N - even_cnt; vector<ll> ans(N); vector<ll> zeros; vector<ll> ones; vector<ll> twes; vector<ll> onetwoes; rep(i, 1, N + 1) { if (i % 3 == 0) { zeros.push_back(i); } else if (i % 3 == 1) { ones.push_back(i); onetwoes.push_back(i); } else if (i % 3 == 2) { twes.push_back(i); onetwoes.push_back(i); } } if (even_cnt <= N / 3) { rep(i, 0, N) { if (tree[i].depth % 2 == 0) { ans[i] = zeros.back(); zeros.pop_back(); } else { if (!onetwoes.empty()) { ans[i] = onetwoes.back(); onetwoes.pop_back(); } else { ans[i] = zeros.back(); zeros.pop_back(); } } } } else if (odd_cnt <= N / 3) { rep(i, 0, N) { if (tree[i].depth % 2 == 1) { ans[i] = zeros.back(); zeros.pop_back(); } else { if (!onetwoes.empty()) { ans[i] = onetwoes.back(); onetwoes.pop_back(); } else { ans[i] = zeros.back(); zeros.pop_back(); } } } } else { rep(i, 0, N) { if (tree[i].depth % 2 == 0) { if (!ones.empty()) { ans[i] = ones.back(); ones.pop_back(); } else { ans[i] = zeros.back(); zeros.pop_back(); } } else { if (!twes.empty()) { ans[i] = twes.back(); twes.pop_back(); } else { ans[i] = zeros.back(); zeros.pop_back(); } } } } rep(i, 0, N) { cout << ans[i]; if (i != N - 1) { cout << " "; } } cout << endl; } /* 10 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 1 10 */
replace
124
126
124
131
0
p02749
C++
Runtime Error
#pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") #include <algorithm> #include <assert.h> #include <bitset> #include <cfloat> #include <complex> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <list> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <string.h> #include <string> #include <time.h> #include <unordered_map> #include <unordered_set> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define REP(i, n) for (int i = 1; i <= (n); i++) #define int long long #define ll long long #define mod (int)1000000007 #define P pair<int, int> #define prique(T) priority_queue<T, vector<T>, greater<T>> #define all(V) V.begin(), V.end() #ifdef int constexpr int INF = LLONG_MAX / 10; #else constexpr int INF = INT_MAX / 10; #endif constexpr double eps = DBL_EPSILON; template <class T, class U> inline bool chmax(T &lhs, const U &rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; } template <class T, class U> inline bool chmin(T &lhs, const U &rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; } using namespace std; inline int gcd(int a, int b) { while (b) { int c = a; a = b; b = c % b; } return a; } inline int lcm(int a, int b) { return a / gcd(a, b) * b; } bool isprime(int n) { if (n == 1) return false; for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } int mypow(int a, int b) { if (!b) return 1; if (b & 1) return mypow(a, b - 1) * a; int memo = mypow(a, b >> 1); return memo * memo; } int modpow(int a, int b, int m = mod) { if (!b) return 1; if (b & 1) return modpow(a, b - 1, m) * a % m; int memo = modpow(a, b >> 1, m); return memo * memo % m; } int n, a, b; vector<int> vec[100010]; int dist[100010]; void dfs(int node) { for (int i : vec[node]) { if (dist[i] == -1) { dist[i] = 1 - dist[node]; dfs(i); } } } signed main() { cin >> n; rep(i, n - 1) { cin >> a >> b; vec[a].push_back(b); vec[b].push_back(a); } fill(dist + 1, dist + n + 1, -1); dist[1] = 0; dfs(1); vector<int> ans[3]; int count[2] = {}, cnt = 1; REP(i, n) { ans[i % 3].push_back(i); count[dist[i]]++; } if (count[0] <= n / 3) { REP(i, n) { if (dist[i] == 0) { cout << cnt * 3; cnt++; } else { if (!ans[1].empty()) { cout << ans[1].back(); ans[1].pop_back(); } else if (!ans[2].empty()) { cout << ans[2].back(); ans[2].pop_back(); } else { cout << cnt * 3; cnt++; } } if (i == n) cout << endl; else cout << " "; } } else if (count[1] <= n / 3) { REP(i, n) { if (dist[i] == 1) { cout << cnt * 3; cnt++; } else { if (!ans[1].empty()) { cout << ans[1].back(); ans[1].pop_back(); } else if (!ans[2].empty()) { cout << ans[2].back(); ans[2].pop_back(); } else { cout << cnt * 3; cnt++; } } if (i == n) cout << endl; else cout << " "; } } else { REP(i, n) { if (ans[dist[i] + 1].empty()) { cout << cnt * 3; cnt++; } else { cout << ans[dist[i] + 1].back(); ans[dist[i] + 1].pop_back(); } if (i == n) cout << endl; else cout << " "; } } return 0; }
#pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") #include <algorithm> #include <assert.h> #include <bitset> #include <cfloat> #include <complex> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <list> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <string.h> #include <string> #include <time.h> #include <unordered_map> #include <unordered_set> #include <vector> #define rep(i, n) for (int i = 0; i < (n); i++) #define REP(i, n) for (int i = 1; i <= (n); i++) #define int long long #define ll long long #define mod (int)1000000007 #define P pair<int, int> #define prique(T) priority_queue<T, vector<T>, greater<T>> #define all(V) V.begin(), V.end() #ifdef int constexpr int INF = LLONG_MAX / 10; #else constexpr int INF = INT_MAX / 10; #endif constexpr double eps = DBL_EPSILON; template <class T, class U> inline bool chmax(T &lhs, const U &rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; } template <class T, class U> inline bool chmin(T &lhs, const U &rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; } using namespace std; inline int gcd(int a, int b) { while (b) { int c = a; a = b; b = c % b; } return a; } inline int lcm(int a, int b) { return a / gcd(a, b) * b; } bool isprime(int n) { if (n == 1) return false; for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } int mypow(int a, int b) { if (!b) return 1; if (b & 1) return mypow(a, b - 1) * a; int memo = mypow(a, b >> 1); return memo * memo; } int modpow(int a, int b, int m = mod) { if (!b) return 1; if (b & 1) return modpow(a, b - 1, m) * a % m; int memo = modpow(a, b >> 1, m); return memo * memo % m; } int n, a, b; vector<int> vec[200010]; int dist[200010]; void dfs(int node) { for (int i : vec[node]) { if (dist[i] == -1) { dist[i] = 1 - dist[node]; dfs(i); } } } signed main() { cin >> n; rep(i, n - 1) { cin >> a >> b; vec[a].push_back(b); vec[b].push_back(a); } fill(dist + 1, dist + n + 1, -1); dist[1] = 0; dfs(1); vector<int> ans[3]; int count[2] = {}, cnt = 1; REP(i, n) { ans[i % 3].push_back(i); count[dist[i]]++; } if (count[0] <= n / 3) { REP(i, n) { if (dist[i] == 0) { cout << cnt * 3; cnt++; } else { if (!ans[1].empty()) { cout << ans[1].back(); ans[1].pop_back(); } else if (!ans[2].empty()) { cout << ans[2].back(); ans[2].pop_back(); } else { cout << cnt * 3; cnt++; } } if (i == n) cout << endl; else cout << " "; } } else if (count[1] <= n / 3) { REP(i, n) { if (dist[i] == 1) { cout << cnt * 3; cnt++; } else { if (!ans[1].empty()) { cout << ans[1].back(); ans[1].pop_back(); } else if (!ans[2].empty()) { cout << ans[2].back(); ans[2].pop_back(); } else { cout << cnt * 3; cnt++; } } if (i == n) cout << endl; else cout << " "; } } else { REP(i, n) { if (ans[dist[i] + 1].empty()) { cout << cnt * 3; cnt++; } else { cout << ans[dist[i] + 1].back(); ans[dist[i] + 1].pop_back(); } if (i == n) cout << endl; else cout << " "; } } return 0; }
replace
91
93
91
93
0
p02749
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; struct edge { int to; int cost; edge(int t, int w) : to(t), cost(w) {} }; int main() { vector<int> y, z; stack<int> s; int c[200010], ans1[200010], i, n, a, b, ans[200010], x; int INF = (1 << 29); vector<vector<edge>> g(200010); scanf("%d\n", &n); for (i = 0; i < n; i++) { scanf("%d %d\n", &a, &b); a--, b--; g[a].push_back(edge(b, 1)); g[b].push_back(edge(a, 1)); } for (i = 0; i < n; i++) { ans[i] = 0; } s.push(0), ans[0] = 1; while (!s.empty()) { x = s.top(); s.pop(); for (i = 0; i < g[x].size(); i++) { if (ans[g[x][i].to] == 0) { ans[g[x][i].to] = -ans[x]; s.push(g[x][i].to); } } } for (i = 0; i < n; i++) { if (ans[i] == 1) { y.push_back(i); } else { z.push_back(i); } } for (i = 0; i <= n; i++) { c[i] = 0; } int d = 0; if (y.size() <= n / 3) { for (i = 1; i <= n; i++) { if (y.size() == d) { break; } if (i % 3 == 0) { c[i] = 1; ans1[y[d]] = i; d++; } } d = 0; for (i = 1; i <= n; i++) { if (c[i] == 0) { ans1[z[d]] = i; d++; } } } else if (z.size() <= n / 3) { for (i = 1; i <= n; i++) { if (z.size() == d) { break; } if (i % 3 == 0) { c[i] = 1; ans1[z[d]] = i; d++; } } d = 0; for (i = 1; i <= n; i++) { if (c[i] == 0) { ans1[y[d]] = i; d++; } } } else { for (i = 1; i <= n; i++) { if (d == y.size()) { break; } if (i % 3 == 1) { c[i] = 1; ans1[y[d]] = i; d++; } } if (d < y.size()) { for (i = 1; i <= n; i++) { if (d == y.size()) { break; } if (i % 3 == 0) { c[i] = 1; ans1[y[d]] = i; d++; } } } d = 0; for (i = 1; i <= n; i++) { if (c[i] == 0) { ans1[z[d]] = i; d++; } } } for (i = 0; i < n; i++) { if (i == 0) { printf("%d", ans1[i]); continue; } printf(" %d", ans1[i]); } return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; struct edge { int to; int cost; edge(int t, int w) : to(t), cost(w) {} }; int main() { vector<int> y, z; stack<int> s; int c[200010], ans1[200010], i, n, a, b, ans[200010], x; int INF = (1 << 29); vector<vector<edge>> g(200010); scanf("%d\n", &n); for (i = 0; i < n - 1; i++) { scanf("%d %d\n", &a, &b); a--, b--; g[a].push_back(edge(b, 1)); g[b].push_back(edge(a, 1)); } for (i = 0; i < n; i++) { ans[i] = 0; } s.push(0), ans[0] = 1; while (!s.empty()) { x = s.top(); s.pop(); for (i = 0; i < g[x].size(); i++) { if (ans[g[x][i].to] == 0) { ans[g[x][i].to] = -ans[x]; s.push(g[x][i].to); } } } for (i = 0; i < n; i++) { if (ans[i] == 1) { y.push_back(i); } else { z.push_back(i); } } for (i = 0; i <= n; i++) { c[i] = 0; } int d = 0; if (y.size() <= n / 3) { for (i = 1; i <= n; i++) { if (y.size() == d) { break; } if (i % 3 == 0) { c[i] = 1; ans1[y[d]] = i; d++; } } d = 0; for (i = 1; i <= n; i++) { if (c[i] == 0) { ans1[z[d]] = i; d++; } } } else if (z.size() <= n / 3) { for (i = 1; i <= n; i++) { if (z.size() == d) { break; } if (i % 3 == 0) { c[i] = 1; ans1[z[d]] = i; d++; } } d = 0; for (i = 1; i <= n; i++) { if (c[i] == 0) { ans1[y[d]] = i; d++; } } } else { for (i = 1; i <= n; i++) { if (d == y.size()) { break; } if (i % 3 == 1) { c[i] = 1; ans1[y[d]] = i; d++; } } if (d < y.size()) { for (i = 1; i <= n; i++) { if (d == y.size()) { break; } if (i % 3 == 0) { c[i] = 1; ans1[y[d]] = i; d++; } } } d = 0; for (i = 1; i <= n; i++) { if (c[i] == 0) { ans1[z[d]] = i; d++; } } } for (i = 0; i < n; i++) { if (i == 0) { printf("%d", ans1[i]); continue; } printf(" %d", ans1[i]); } return 0; }
replace
25
26
25
26
0
p02749
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 template <typename ty1, typename ty2> inline int add(ty1 x, ty2 y) { if (y >= MOD) y %= MOD; if (x >= MOD) x %= MOD; x += y; return x < MOD ? x : x - MOD; } template <typename ty1, typename ty2> inline void addto(ty1 &x, ty2 y) { if (y >= MOD) y %= MOD; if (x >= MOD) x %= MOD; x += y; if (x >= MOD) x -= MOD; } template <typename ty1, typename ty2> inline int sub(ty1 x, ty2 y) { if (y >= MOD) y %= MOD; if (x >= MOD) x %= MOD; x -= y; return x < 0 ? x + MOD : x; } template <typename ty1, typename ty2> inline void subto(ty1 &x, ty2 y) { if (y >= MOD) y %= MOD; if (x >= MOD) x %= MOD; x -= y; if (x < 0) x += MOD; } template <typename ty1, typename ty2> inline int mul(ty1 x, ty2 y) { if (y >= MOD) y %= MOD; if (x >= MOD) x %= MOD; return 1ll * x * y % MOD; } template <typename ty1, typename ty2> void multo(ty1 &x, ty2 y) { if (y >= MOD) y %= MOD; if (x >= MOD) x %= MOD; x = 1ll * x * y % MOD; } #define MAX 100002 int n; vector<int> v[MAX]; vector<int> nd[2]; inline void dfs(int b, int dep = 0, int pr = -1) { nd[dep & 1].push_back(b); for (int el : v[b]) { if (pr == el) continue; dfs(el, dep + 1, b); } } vector<int> val[3]; int ans[MAX]; int main() { cin >> n; for (int i = 1; i < n; i++) { int a, b; scanf("%d%d", &a, &b); a--; b--; v[a].push_back(b); v[b].push_back(a); } dfs(0); for (int i = 1; i <= n; i++) val[i % 3].push_back(i); auto apply = [&](int a, int b, int c = -1) { while (nd[a].size() && val[b].size()) { ans[nd[a].back()] = val[b].back(); nd[a].pop_back(); val[b].pop_back(); } b = c; while (b != -1 && nd[a].size() && val[b].size()) { ans[nd[a].back()] = val[b].back(); nd[a].pop_back(); val[b].pop_back(); } }; if (nd[0].size() <= val[0].size()) { apply(0, 0); apply(1, 1, 2); apply(1, 0); } else { if (nd[1].size() <= val[0].size()) { apply(0, 1, 2); apply(1, 0); apply(0, 0); } else { if (nd[0].size() >= val[1].size() && nd[1].size() >= val[2].size()) { apply(0, 1); apply(1, 2); } else { apply(0, 2); apply(1, 1); } apply(0, 0); apply(1, 0); } } for (int i = 0; i < n; i++) { if (i) printf(" "); printf("%d", ans[i]); } puts(""); return 0; }
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 template <typename ty1, typename ty2> inline int add(ty1 x, ty2 y) { if (y >= MOD) y %= MOD; if (x >= MOD) x %= MOD; x += y; return x < MOD ? x : x - MOD; } template <typename ty1, typename ty2> inline void addto(ty1 &x, ty2 y) { if (y >= MOD) y %= MOD; if (x >= MOD) x %= MOD; x += y; if (x >= MOD) x -= MOD; } template <typename ty1, typename ty2> inline int sub(ty1 x, ty2 y) { if (y >= MOD) y %= MOD; if (x >= MOD) x %= MOD; x -= y; return x < 0 ? x + MOD : x; } template <typename ty1, typename ty2> inline void subto(ty1 &x, ty2 y) { if (y >= MOD) y %= MOD; if (x >= MOD) x %= MOD; x -= y; if (x < 0) x += MOD; } template <typename ty1, typename ty2> inline int mul(ty1 x, ty2 y) { if (y >= MOD) y %= MOD; if (x >= MOD) x %= MOD; return 1ll * x * y % MOD; } template <typename ty1, typename ty2> void multo(ty1 &x, ty2 y) { if (y >= MOD) y %= MOD; if (x >= MOD) x %= MOD; x = 1ll * x * y % MOD; } #define MAX 200002 int n; vector<int> v[MAX]; vector<int> nd[2]; inline void dfs(int b, int dep = 0, int pr = -1) { nd[dep & 1].push_back(b); for (int el : v[b]) { if (pr == el) continue; dfs(el, dep + 1, b); } } vector<int> val[3]; int ans[MAX]; int main() { cin >> n; for (int i = 1; i < n; i++) { int a, b; scanf("%d%d", &a, &b); a--; b--; v[a].push_back(b); v[b].push_back(a); } dfs(0); for (int i = 1; i <= n; i++) val[i % 3].push_back(i); auto apply = [&](int a, int b, int c = -1) { while (nd[a].size() && val[b].size()) { ans[nd[a].back()] = val[b].back(); nd[a].pop_back(); val[b].pop_back(); } b = c; while (b != -1 && nd[a].size() && val[b].size()) { ans[nd[a].back()] = val[b].back(); nd[a].pop_back(); val[b].pop_back(); } }; if (nd[0].size() <= val[0].size()) { apply(0, 0); apply(1, 1, 2); apply(1, 0); } else { if (nd[1].size() <= val[0].size()) { apply(0, 1, 2); apply(1, 0); apply(0, 0); } else { if (nd[0].size() >= val[1].size() && nd[1].size() >= val[2].size()) { apply(0, 1); apply(1, 2); } else { apply(0, 2); apply(1, 1); } apply(0, 0); apply(1, 0); } } for (int i = 0; i < n; i++) { if (i) printf(" "); printf("%d", ans[i]); } puts(""); return 0; }
replace
52
53
52
53
0
p02749
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define F(i, a, b) for (long long i = a; i < b; i++) #define rF(i, a, b) for (long long i = a - 1; i >= b; i--) #define endl "\n" #define min1(x, y, z) min(x, min(y, z)) #define max1(x, y, z) max(x, max(y, z)) #define input_vector(v, n, type) \ vector<type> v; \ for (int i = 0; i < n; i++) { \ type x; \ cin >> x; \ v.push_back(x); \ } #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define int long long #define inf (1LL << 61) typedef pair<int, int> ii; typedef vector<pair<int, int>> vii; typedef vector<int> vi; vector<int> adj[20000 + 5]; int32_t main() { IOS; int n; cin >> n; for (int i = 0; i < n - 1; i++) { int x, y; cin >> x >> y; x--; y--; adj[x].push_back(y); adj[y].push_back(x); } queue<int> q; vector<int> color(n, -1); q.push(0); color[0] = 0; vector<int> cnt(2, 0); cnt[0]++; while (!q.empty()) { int cur = q.front(); q.pop(); for (auto u : adj[cur]) { if (color[u] == -1) { color[u] = 1 - color[cur]; cnt[color[u]]++; q.push(u); } } } // cout<<cnt[0]<<" "<<cnt[1]<<endl; int lesser = min(cnt[0], cnt[1]); int mincolor = (cnt[0] < cnt[1] ? 0 : 1); vector<int> ans(n, -1); int k, j, k1, k2; if (lesser <= n / 3) { k = 1; for (int i = 0; i < n; i++) { if (color[i] == mincolor) { ans[i] = 3 * k; k++; } } j = 1; for (int i = 0; i < n; i++) { if (ans[i] == -1) { if (j % 3) { if (j > n) { ans[i] = 3 * k; k++; } else { ans[i] = j++; } } else { if (j + 1 > n) { ans[i] = 3 * k; k++; } else { ans[i] = ++j; j++; } } } } } else { k1 = 0, k2 = 0, j = 1; for (int i = 0; i < n; i++) { if (color[i] == mincolor) { ans[i] = 3 * k1 + 1; k1++; } else { ans[i] = 3 * k2 + 2; k2++; } } int j = 1; for (int i = 0; i < n; i++) { if (ans[i] == -1 || ans[i] > n) { ans[i] = 3 * j; j++; } } } for (int i = 0; i < n; i++) { cout << ans[i] << " "; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define F(i, a, b) for (long long i = a; i < b; i++) #define rF(i, a, b) for (long long i = a - 1; i >= b; i--) #define endl "\n" #define min1(x, y, z) min(x, min(y, z)) #define max1(x, y, z) max(x, max(y, z)) #define input_vector(v, n, type) \ vector<type> v; \ for (int i = 0; i < n; i++) { \ type x; \ cin >> x; \ v.push_back(x); \ } #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define int long long #define inf (1LL << 61) typedef pair<int, int> ii; typedef vector<pair<int, int>> vii; typedef vector<int> vi; vector<int> adj[200000 + 5]; int32_t main() { IOS; int n; cin >> n; for (int i = 0; i < n - 1; i++) { int x, y; cin >> x >> y; x--; y--; adj[x].push_back(y); adj[y].push_back(x); } queue<int> q; vector<int> color(n, -1); q.push(0); color[0] = 0; vector<int> cnt(2, 0); cnt[0]++; while (!q.empty()) { int cur = q.front(); q.pop(); for (auto u : adj[cur]) { if (color[u] == -1) { color[u] = 1 - color[cur]; cnt[color[u]]++; q.push(u); } } } // cout<<cnt[0]<<" "<<cnt[1]<<endl; int lesser = min(cnt[0], cnt[1]); int mincolor = (cnt[0] < cnt[1] ? 0 : 1); vector<int> ans(n, -1); int k, j, k1, k2; if (lesser <= n / 3) { k = 1; for (int i = 0; i < n; i++) { if (color[i] == mincolor) { ans[i] = 3 * k; k++; } } j = 1; for (int i = 0; i < n; i++) { if (ans[i] == -1) { if (j % 3) { if (j > n) { ans[i] = 3 * k; k++; } else { ans[i] = j++; } } else { if (j + 1 > n) { ans[i] = 3 * k; k++; } else { ans[i] = ++j; j++; } } } } } else { k1 = 0, k2 = 0, j = 1; for (int i = 0; i < n; i++) { if (color[i] == mincolor) { ans[i] = 3 * k1 + 1; k1++; } else { ans[i] = 3 * k2 + 2; k2++; } } int j = 1; for (int i = 0; i < n; i++) { if (ans[i] == -1 || ans[i] > n) { ans[i] = 3 * j; j++; } } } for (int i = 0; i < n; i++) { cout << ans[i] << " "; } cout << endl; return 0; }
replace
25
26
25
26
0
p02749
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(A) A.begin(), A.end() #define RALL(A) A.rbegin(), A.rend() typedef long long ll; typedef pair<ll, ll> P; const ll mod = 1000000007; const ll LINF = 1LL << 60; const int INF = 1 << 30; int n; vector<int> v(100001, 0); vector<vector<int>> g(100001); void dfs(int x, int parent, int dist) { for (int i = 0; i < g[x].size(); i++) { if (g[x][i] != parent) { v[g[x][i]] = (dist % 2); dfs(g[x][i], x, dist + 1); } } } int main() { cin >> n; for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; g[a].pb(b); g[b].pb(a); } dfs(1, -1, 1); int cnt_red = 0; int cnt_blue = 0; for (int i = 1; i <= n; i++) { // cout << v[i] << " "; if (v[i] == 0) { cnt_red++; } else { cnt_blue++; } } vector<int> ans(n + 1, 0); vector<int> s0; vector<int> s1; vector<int> s2; for (int i = 1; i <= n; i++) { if (i % 3 == 0) { s0.pb(i); } else if (i % 3 == 1) { s1.pb(i); } else { s2.pb(i); } } if (cnt_red <= n / 3) { int p = 0; int q = 0; int r = 0; for (int i = 1; i <= n; i++) { if (v[i] == 0) { ans[i] = s0[p]; p++; } } for (int i = 1; i <= n; i++) { if (ans[i] == 0) { if (p < s0.size()) { ans[i] = s0[p]; p++; } else { if (q < s1.size()) { ans[i] = s1[q]; q++; } else if (r < s2.size()) { ans[i] = s2[r]; r++; } } } } } else if (cnt_blue <= n / 3) { int p = 0; int q = 0; int r = 0; for (int i = 1; i <= n; i++) { if (v[i] == 1) { ans[i] = s0[p]; p++; } } for (int i = 1; i <= n; i++) { if (ans[i] == 0) { if (p < s0.size()) { ans[i] = s0[p]; p++; } else { if (q < s1.size()) { ans[i] = s1[q]; q++; } else if (r < s2.size()) { ans[i] = s2[r]; r++; } } } } } else { int p = 0; int q = 0; int r = 0; for (int i = 1; i <= n; i++) { if (v[i] == 0) { if (p < s1.size()) { ans[i] = s1[p]; p++; } else { ans[i] = s0[q]; q++; } } } for (int i = 1; i <= n; i++) { if (ans[i] == 0) { if (q < s0.size()) { ans[i] = s0[q]; q++; } else if (r < s2.size()) { ans[i] = s2[r]; r++; } } } } for (int i = 1; i <= n; i++) { cout << ans[i] << " "; } cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define fs first #define sc second #define pb push_back #define mp make_pair #define eb emplace_back #define ALL(A) A.begin(), A.end() #define RALL(A) A.rbegin(), A.rend() typedef long long ll; typedef pair<ll, ll> P; const ll mod = 1000000007; const ll LINF = 1LL << 60; const int INF = 1 << 30; int n; vector<int> v(200001, 0); vector<vector<int>> g(200001); void dfs(int x, int parent, int dist) { for (int i = 0; i < g[x].size(); i++) { if (g[x][i] != parent) { v[g[x][i]] = (dist % 2); dfs(g[x][i], x, dist + 1); } } } int main() { cin >> n; for (int i = 0; i < n - 1; i++) { int a, b; cin >> a >> b; g[a].pb(b); g[b].pb(a); } dfs(1, -1, 1); int cnt_red = 0; int cnt_blue = 0; for (int i = 1; i <= n; i++) { // cout << v[i] << " "; if (v[i] == 0) { cnt_red++; } else { cnt_blue++; } } vector<int> ans(n + 1, 0); vector<int> s0; vector<int> s1; vector<int> s2; for (int i = 1; i <= n; i++) { if (i % 3 == 0) { s0.pb(i); } else if (i % 3 == 1) { s1.pb(i); } else { s2.pb(i); } } if (cnt_red <= n / 3) { int p = 0; int q = 0; int r = 0; for (int i = 1; i <= n; i++) { if (v[i] == 0) { ans[i] = s0[p]; p++; } } for (int i = 1; i <= n; i++) { if (ans[i] == 0) { if (p < s0.size()) { ans[i] = s0[p]; p++; } else { if (q < s1.size()) { ans[i] = s1[q]; q++; } else if (r < s2.size()) { ans[i] = s2[r]; r++; } } } } } else if (cnt_blue <= n / 3) { int p = 0; int q = 0; int r = 0; for (int i = 1; i <= n; i++) { if (v[i] == 1) { ans[i] = s0[p]; p++; } } for (int i = 1; i <= n; i++) { if (ans[i] == 0) { if (p < s0.size()) { ans[i] = s0[p]; p++; } else { if (q < s1.size()) { ans[i] = s1[q]; q++; } else if (r < s2.size()) { ans[i] = s2[r]; r++; } } } } } else { int p = 0; int q = 0; int r = 0; for (int i = 1; i <= n; i++) { if (v[i] == 0) { if (p < s1.size()) { ans[i] = s1[p]; p++; } else { ans[i] = s0[q]; q++; } } } for (int i = 1; i <= n; i++) { if (ans[i] == 0) { if (q < s0.size()) { ans[i] = s0[q]; q++; } else if (r < s2.size()) { ans[i] = s2[r]; r++; } } } } for (int i = 1; i <= n; i++) { cout << ans[i] << " "; } cout << endl; return 0; }
replace
15
17
15
17
0
p02749
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string.h> #include <vector> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(a) (a).begin(), (a).end() typedef long long lint; using namespace std; struct generator { int n; int i[3] = {1, 0, 0}; generator(int _n) : n(_n) {} bool remain(int a) { if (a > 2) return false; if (3 * i[a] + a > n) return false; return true; } int get(int a) { if (!remain(a)) return 0; int ret = 3 * i[a] + a; i[a]++; return ret; } }; int main() { int N; cin >> N; vector<vector<int>> c(N); REP(i, N - 1) { int a, b; cin >> a >> b; a--; b--; c[a].push_back(b); c[b].push_back(a); } vector<int> d(N, -1); int no = 1, ne = 0; queue<int> q; q.push(0); d[0] = 0; while (!q.empty()) { int p = q.front(); q.pop(); for (auto e : c[p]) if (d[e] < 0) { q.push(e); d[e] = d[p] + 1; if (d[e] % 2 == 0) ne++; else no++; } } REP(i, N) cerr << d[i] << " "; cerr << endl; cerr << ne << " " << no << endl; auto g = generator(N); vector<int> ans(N); REP(i, N) { if (ne <= N / 3) { if (d[i] % 2 == 0) { ans[i] = g.get(0); if (ans[i] == 0) return 1; } else { if (g.remain(1)) ans[i] = g.get(1); else if (g.remain(2)) ans[i] = g.get(2); else ans[i] = g.get(0); } } else if (no <= N / 3) { if (d[i] % 2 == 0) { if (g.remain(1)) ans[i] = g.get(1); else if (g.remain(2)) ans[i] = g.get(2); else ans[i] = g.get(0); } else { ans[i] = g.get(0); if (ans[i] == 0) return 1; } } else { if (d[i] % 2 == 0) { if (g.remain(1)) ans[i] = g.get(1); else ans[i] = g.get(0); } else { if (g.remain(2)) ans[i] = g.get(2); else ans[i] = g.get(0); } } } REP(i, N) cout << ans[i] << " "; cout << endl; return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string.h> #include <vector> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(a) (a).begin(), (a).end() typedef long long lint; using namespace std; struct generator { int n; int i[3] = {1, 0, 0}; generator(int _n) : n(_n) {} bool remain(int a) { if (a > 2) return false; if (3 * i[a] + a > n) return false; return true; } int get(int a) { if (!remain(a)) return 0; int ret = 3 * i[a] + a; i[a]++; return ret; } }; int main() { int N; cin >> N; vector<vector<int>> c(N); REP(i, N - 1) { int a, b; cin >> a >> b; a--; b--; c[a].push_back(b); c[b].push_back(a); } vector<int> d(N, -1); int no = 0, ne = 1; queue<int> q; q.push(0); d[0] = 0; while (!q.empty()) { int p = q.front(); q.pop(); for (auto e : c[p]) if (d[e] < 0) { q.push(e); d[e] = d[p] + 1; if (d[e] % 2 == 0) ne++; else no++; } } REP(i, N) cerr << d[i] << " "; cerr << endl; cerr << ne << " " << no << endl; auto g = generator(N); vector<int> ans(N); REP(i, N) { if (ne <= N / 3) { if (d[i] % 2 == 0) { ans[i] = g.get(0); if (ans[i] == 0) return 1; } else { if (g.remain(1)) ans[i] = g.get(1); else if (g.remain(2)) ans[i] = g.get(2); else ans[i] = g.get(0); } } else if (no <= N / 3) { if (d[i] % 2 == 0) { if (g.remain(1)) ans[i] = g.get(1); else if (g.remain(2)) ans[i] = g.get(2); else ans[i] = g.get(0); } else { ans[i] = g.get(0); if (ans[i] == 0) return 1; } } else { if (d[i] % 2 == 0) { if (g.remain(1)) ans[i] = g.get(1); else ans[i] = g.get(0); } else { if (g.remain(2)) ans[i] = g.get(2); else ans[i] = g.get(0); } } } REP(i, N) cout << ans[i] << " "; cout << endl; return 0; }
replace
52
53
52
53
0
0 1 1 2 2 2 3
p02749
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; vector<int> v[3], g[2], l[200003]; int n, ans[200003]; bool used[200003]; void dfs(int x, bool a, int p) { g[a].push_back(x); for (int i = 0; i < l[x].size(); i++) if (l[x][i] != p) dfs(l[x][i], a ^ 1, x); } int main() { scanf("%d", &n); for (int i = 1; i < n; i++) { int x, y; scanf("%d%d", &x, &y); x--; y--; l[x].push_back(y); l[y].push_back(x); } dfs(0, 0, -1); for (int i = 1; i <= n; i++) v[i % 3].push_back(i); if (g[0].size() < g[1].size()) swap(g[0], g[1]); if (g[0].size() <= v[0].size()) { for (int i = 0; i < g[0].size(); i++) ans[g[0][i]] = v[0][i], used[v[0][i]] = 1; for (int i = 1; i <= n; i++) if (!used[i]) ans[g[1].back()] = i, g[1].pop_back(); } else { for (int i = 0; i < v[1].size(); i++) ans[g[0].back()] = v[1][i], g[0].pop_back(); for (int i = 0; i < v[2].size(); i++) ans[g[1].back()] = v[2][i], g[1].pop_back(); for (int i = 0; i < g[0].size(); i++) ans[g[0][i]] = v[0].back(), v[0].pop_back(); for (int i = 0; i < g[1].size(); i++) ans[g[1][i]] = v[0].back(), v[0].pop_back(); } for (int i = 0; i < n; i++) printf("%d ", ans[i]); }
#include <bits/stdc++.h> using namespace std; vector<int> v[3], g[2], l[200003]; int n, ans[200003]; bool used[200003]; void dfs(int x, bool a, int p) { g[a].push_back(x); for (int i = 0; i < l[x].size(); i++) if (l[x][i] != p) dfs(l[x][i], a ^ 1, x); } int main() { scanf("%d", &n); for (int i = 1; i < n; i++) { int x, y; scanf("%d%d", &x, &y); x--; y--; l[x].push_back(y); l[y].push_back(x); } dfs(0, 0, -1); for (int i = 1; i <= n; i++) v[i % 3].push_back(i); if (g[1].size() < g[0].size()) swap(g[0], g[1]); if (g[0].size() <= v[0].size()) { for (int i = 0; i < g[0].size(); i++) ans[g[0][i]] = v[0][i], used[v[0][i]] = 1; for (int i = 1; i <= n; i++) if (!used[i]) ans[g[1].back()] = i, g[1].pop_back(); } else { for (int i = 0; i < v[1].size(); i++) ans[g[0].back()] = v[1][i], g[0].pop_back(); for (int i = 0; i < v[2].size(); i++) ans[g[1].back()] = v[2][i], g[1].pop_back(); for (int i = 0; i < g[0].size(); i++) ans[g[0][i]] = v[0].back(), v[0].pop_back(); for (int i = 0; i < g[1].size(); i++) ans[g[1][i]] = v[0].back(), v[0].pop_back(); } for (int i = 0; i < n; i++) printf("%d ", ans[i]); }
replace
24
25
24
25
0
p02749
C++
Runtime Error
#include <bits/stdc++.h> #define syosu(x) fixed << setprecision(x) using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<int, P> pip; typedef vector<pip> vip; const int inf = 1 << 30; const ll INF = 1ll << 60; const double pi = acos(-1); const double eps = 1e-9; const ll mod = 1e9 + 7; const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1}; int n; vvi g; vi a, b; vvi c; void dfs(int v, int p, int t) { a[v] = t; for (auto u : g[v]) if (u != p) dfs(u, v, 1 - t); } int main() { cin >> n; g = vvi(n); a = b = vi(n); c = vvi(3); for (int i = 1; i < n; i++) c[i % 3].push_back(i); for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; u--; v--; g[u].push_back(v); g[v].push_back(u); } dfs(0, -1, 0); int t = 0; for (auto i : a) t += i; if (t <= n / 3 || n - t <= n / 3) { int I = 0; set<int> st; int tmp = (t <= n / 3 ? 1 : 0); for (int i = 0; i < n; i++) if (tmp == a[i]) { b[i] = c[0][I++]; st.insert(b[i]); } I = 1; for (int i = 0; i < n; i++) if (!b[i]) { while (st.find(I) != st.end()) I++; b[i] = I; I++; } } else { int I = 0, J = 0; set<int> st; for (int i = 0; i < n; i++) { if (a[i] && I < c[1].size()) { b[i] = c[1][I++]; st.insert(b[i]); } if (!a[i] && J < c[2].size()) { b[i] = c[2][J++]; st.insert(b[i]); } } I = 1; for (int i = 0; i < n; i++) if (!b[i]) { while (st.find(I) != st.end()) I++; b[i] = I; I++; } } for (int i = 0; i < n; i++) cout << b[i] << " \n"[i == n - 1]; }
#include <bits/stdc++.h> #define syosu(x) fixed << setprecision(x) using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<int, P> pip; typedef vector<pip> vip; const int inf = 1 << 30; const ll INF = 1ll << 60; const double pi = acos(-1); const double eps = 1e-9; const ll mod = 1e9 + 7; const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1}; int n; vvi g; vi a, b; vvi c; void dfs(int v, int p, int t) { a[v] = t; for (auto u : g[v]) if (u != p) dfs(u, v, 1 - t); } int main() { cin >> n; g = vvi(n); a = b = vi(n); c = vvi(3); for (int i = 1; i <= n; i++) c[i % 3].push_back(i); for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; u--; v--; g[u].push_back(v); g[v].push_back(u); } dfs(0, -1, 0); int t = 0; for (auto i : a) t += i; if (t <= n / 3 || n - t <= n / 3) { int I = 0; set<int> st; int tmp = (t <= n / 3 ? 1 : 0); for (int i = 0; i < n; i++) if (tmp == a[i]) { b[i] = c[0][I++]; st.insert(b[i]); } I = 1; for (int i = 0; i < n; i++) if (!b[i]) { while (st.find(I) != st.end()) I++; b[i] = I; I++; } } else { int I = 0, J = 0; set<int> st; for (int i = 0; i < n; i++) { if (a[i] && I < c[1].size()) { b[i] = c[1][I++]; st.insert(b[i]); } if (!a[i] && J < c[2].size()) { b[i] = c[2][J++]; st.insert(b[i]); } } I = 1; for (int i = 0; i < n; i++) if (!b[i]) { while (st.find(I) != st.end()) I++; b[i] = I; I++; } } for (int i = 0; i < n; i++) cout << b[i] << " \n"[i == n - 1]; }
replace
45
46
45
46
0
p02750
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; static const int64_t INF = 100000000000; int64_t N, T; int64_t dp[100005][31]; int main() { cin >> N >> T; vector<int64_t> A(N); vector<int64_t> B(N); for (int i = 0; i < N; i++) { int64_t a; cin >> a; A.at(i) = a + 1; cin >> B.at(i); } vector<pair<double, int64_t>> C; vector<int64_t> D; for (int64_t i = 0; i < N; i++) { if (A[i] == 1) D.push_back(B[i] + 1); else { double a = A[i]; double b = B[i]; pair<double, int64_t> p(-(a + b) / (b + 1), i); C.push_back(p); } } sort(C.begin(), C.end()); sort(D.begin(), D.end()); int M = C.size(); vector<pair<int64_t, int64_t>> P(M); for (int i = 0; i < M; i++) { int64_t I = C[i].second; pair<int64_t, int64_t> p(A[I], B[I]); P[i] = p; } for (int i = 0; i <= M; i++) for (int j = 1; j <= 30; j++) dp[i][j] = INF; for (int i = 1; i <= M; i++) for (int j = 1; j <= 30; j++) { dp[i][j] = min(dp[i - 1][j], P[i - 1].first * (dp[i - 1][j - 1] + 1) + P[i - 1].second); } vector<int64_t> d(N - M + 1); d[0] = 0; for (int i = 1; i <= N - M; i++) d[i] = d[i - 1] + D[i - 1]; int64_t ans = 0; for (int i = 0; i <= 30; i++) { if (dp[M][i] <= T) { auto itr = upper_bound(d.begin(), d.end(), T - dp[M][i]); int k = distance(d.begin(), itr); if (ans < k + i - 1) ans = k + i - 1; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; static const int64_t INF = 100000000000; int64_t N, T; int64_t dp[200005][31]; int main() { cin >> N >> T; vector<int64_t> A(N); vector<int64_t> B(N); for (int i = 0; i < N; i++) { int64_t a; cin >> a; A.at(i) = a + 1; cin >> B.at(i); } vector<pair<double, int64_t>> C; vector<int64_t> D; for (int64_t i = 0; i < N; i++) { if (A[i] == 1) D.push_back(B[i] + 1); else { double a = A[i]; double b = B[i]; pair<double, int64_t> p(-(a + b) / (b + 1), i); C.push_back(p); } } sort(C.begin(), C.end()); sort(D.begin(), D.end()); int M = C.size(); vector<pair<int64_t, int64_t>> P(M); for (int i = 0; i < M; i++) { int64_t I = C[i].second; pair<int64_t, int64_t> p(A[I], B[I]); P[i] = p; } for (int i = 0; i <= M; i++) for (int j = 1; j <= 30; j++) dp[i][j] = INF; for (int i = 1; i <= M; i++) for (int j = 1; j <= 30; j++) { dp[i][j] = min(dp[i - 1][j], P[i - 1].first * (dp[i - 1][j - 1] + 1) + P[i - 1].second); } vector<int64_t> d(N - M + 1); d[0] = 0; for (int i = 1; i <= N - M; i++) d[i] = d[i - 1] + D[i - 1]; int64_t ans = 0; for (int i = 0; i <= 30; i++) { if (dp[M][i] <= T) { auto itr = upper_bound(d.begin(), d.end(), T - dp[M][i]); int k = distance(d.begin(), itr); if (ans < k + i - 1) ans = k + i - 1; } } cout << ans << endl; return 0; }
replace
4
5
4
5
0
p02750
C++
Time Limit Exceeded
/* This code has been written by MinakoKojima, feel free to ask me question. Blog: http://www.shuizilong.com/house Template Date: 2015.10.12 Note: ... */ #pragma comment(linker, "/STACK:36777216") // #pragma GCC optimize ("O2") #define LOCAL #include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> // #include <tr1/unordered_set> // #include <tr1/unordered_map> // #include <array> 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 DWN(i, b, a) for (int i = b - 1; i >= a; --i) #define REP_1(i, n) for (int i = 1; i <= n; ++i) #define FOR_1(i, a, b) for (int i = a; i <= b; ++i) #define DWN_1(i, b, a) for (int i = b; i >= a; --i) #define REP_C(i, n) for (int n____ = n, i = 0; i < n____; ++i) #define FOR_C(i, a, b) for (int b____ = b, i = a; i < b____; ++i) #define DWN_C(i, b, a) for (int a____ = a, i = b - 1; i >= a____; --i) #define REP_N(i, n) for (i = 0; i < n; ++i) #define FOR_N(i, a, b) for (i = a; i < b; ++i) #define DWN_N(i, b, a) for (i = b - 1; i >= a; --i) #define REP_1_C(i, n) for (int n____ = n, i = 1; i <= n____; ++i) #define FOR_1_C(i, a, b) for (int b____ = b, i = a; i <= b____; ++i) #define DWN_1_C(i, b, a) for (int a____ = a, i = b; i >= a____; --i) #define REP_1_N(i, n) for (i = 1; i <= n; ++i) #define FOR_1_N(i, a, b) for (i = a; i <= b; ++i) #define DWN_1_N(i, b, a) for (i = b; i >= a; --i) #define REP_C_N(i, n) for (int n____ = (i = 0, n); i < n____; ++i) #define FOR_C_N(i, a, b) for (int b____ = (i = 0, b); i < b____; ++i) #define DWN_C_N(i, b, a) for (int a____ = (i = b - 1, a); i >= a____; --i) #define REP_1_C_N(i, n) for (int n____ = (i = 1, n); i <= n____; ++i) #define FOR_1_C_N(i, a, b) for (int b____ = (i = a, b); i <= b____; ++i) #define DWN_1_C_N(i, b, a) for (int a____ = (i = b, a); i >= a____; --i) #define ECH(it, A) \ for (__typeof((A).begin()) it = (A).begin(); it != (A).end(); ++it) #define rECH(it, A) \ for (__typeof((A).rbegin()) it = (A).rbegin(); it != (A).rend(); ++it) #define REP_S(i, str) for (char *i = str; *i; ++i) #define REP_L(i, hd, suc) for (int i = hd; i; i = suc[i]) #define REP_G(i, u) REP_L(i, hd[u], suc) #define REP_SS(x, s) for (int x = s; x; x = (x - 1) & s) #define DO(n) for (int ____n = n; ____n-- > 0;) #define REP_2(i, j, n, m) REP(i, n) REP(j, m) #define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m) #define REP_3(i, j, k, n, m, l) REP(i, n) REP(j, m) REP(k, l) #define REP_3_1(i, j, k, n, m, l) REP_1(i, n) REP_1(j, m) REP_1(k, l) #define REP_4(i, j, k, ii, n, m, l, nn) \ REP(i, n) REP(j, m) REP(k, l) REP(ii, nn) #define REP_4_1(i, j, k, ii, n, m, l, nn) \ REP_1(i, n) REP_1(j, m) REP_1(k, l) REP_1(ii, nn) #define ALL(A) A.begin(), A.end() #define LLA(A) A.rbegin(), A.rend() #define CPY(A, B) memcpy(A, B, sizeof(A)) #define INS(A, P, B) A.insert(A.begin() + P, B) #define ERS(A, P) A.erase(A.begin() + P) #define LBD(A, x) (lower_bound(ALL(A), x) - A.begin()) #define UBD(A, x) (upper_bound(ALL(A), x) - A.begin()) #define CTN(T, x) (T.find(x) != T.end()) #define SZ(A) int((A).size()) #define PB push_back #define MP(A, B) make_pair(A, B) #define PTT pair<T, T> #define Ts *this #define rTs return Ts #define fi first #define se second #define re real() #define im imag() #define Rush for (int ____T = RD(); ____T--;) #define Display(A, n, m) \ { \ REP(i, n) { \ REP(j, m - 1) cout << A[i][j] << " "; \ cout << A[i][m - 1] << endl; \ } \ } #define Display_1(A, n, m) \ { \ REP_1(i, n) { \ REP_1(j, m - 1) cout << A[i][j] << " "; \ cout << A[i][m] << endl; \ } \ } typedef long long LL; // typedef long double DB; typedef double DB; typedef unsigned uint; typedef unsigned long long uLL; typedef vector<int> VI; typedef vector<char> VC; typedef vector<string> VS; typedef vector<LL> VL; typedef vector<DB> VF; typedef set<int> SI; typedef set<string> SS; typedef map<int, int> MII; typedef map<string, int> MSI; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef vector<PII> VII; typedef vector<VI> VVI; typedef vector<VII> VVII; template <class T> inline T &RD(T &); template <class T> inline void OT(const T &); // inline int RD(){int x; return RD(x);} inline LL RD() { LL x; return RD(x); } inline DB &RF(DB &); inline DB RF() { DB x; return RF(x); } inline char *RS(char *s); inline char &RC(char &c); inline char RC(); inline char &RC(char &c) { scanf(" %c", &c); return c; } inline char RC() { char c; return RC(c); } // inline char& RC(char &c){c = getchar(); return c;} // inline char RC(){return getchar();} template <class T> inline T &RDD(T &); inline LL RDD() { LL x; return RDD(x); } template <class T0, class T1> inline T0 &RD(T0 &x0, T1 &x1) { RD(x0), RD(x1); return x0; } template <class T0, class T1, class T2> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2) { RD(x0), RD(x1), RD(x2); return x0; } template <class T0, class T1, class T2, class T3> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3) { RD(x0), RD(x1), RD(x2), RD(x3); return x0; } template <class T0, class T1, class T2, class T3, class T4> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4) { RD(x0), RD(x1), RD(x2), RD(x3), RD(x4); return x0; } template <class T0, class T1, class T2, class T3, class T4, class T5> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5) { RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5); return x0; } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6) { RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6); return x0; } template <class T0, class T1> inline void OT(const T0 &x0, const T1 &x1) { OT(x0), OT(x1); } template <class T0, class T1, class T2> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2) { OT(x0), OT(x1), OT(x2); } template <class T0, class T1, class T2, class T3> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3) { OT(x0), OT(x1), OT(x2), OT(x3); } template <class T0, class T1, class T2, class T3, class T4> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4) { OT(x0), OT(x1), OT(x2), OT(x3), OT(x4); } template <class T0, class T1, class T2, class T3, class T4, class T5> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5) { OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5); } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5, const T6 &x6) { OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6); } inline char &RC(char &a, char &b) { RC(a), RC(b); return a; } inline char &RC(char &a, char &b, char &c) { RC(a), RC(b), RC(c); return a; } inline char &RC(char &a, char &b, char &c, char &d) { RC(a), RC(b), RC(c), RC(d); return a; } inline char &RC(char &a, char &b, char &c, char &d, char &e) { RC(a), RC(b), RC(c), RC(d), RC(e); return a; } inline char &RC(char &a, char &b, char &c, char &d, char &e, char &f) { RC(a), RC(b), RC(c), RC(d), RC(e), RC(f); return a; } inline char &RC(char &a, char &b, char &c, char &d, char &e, char &f, char &g) { RC(a), RC(b), RC(c), RC(d), RC(e), RC(f), RC(g); return a; } inline DB &RF(DB &a, DB &b) { RF(a), RF(b); return a; } inline DB &RF(DB &a, DB &b, DB &c) { RF(a), RF(b), RF(c); return a; } inline DB &RF(DB &a, DB &b, DB &c, DB &d) { RF(a), RF(b), RF(c), RF(d); return a; } inline DB &RF(DB &a, DB &b, DB &c, DB &d, DB &e) { RF(a), RF(b), RF(c), RF(d), RF(e); return a; } inline DB &RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f) { RF(a), RF(b), RF(c), RF(d), RF(e), RF(f); return a; } inline DB &RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f, DB &g) { RF(a), RF(b), RF(c), RF(d), RF(e), RF(f), RF(g); return a; } inline void RS(char *s1, char *s2) { RS(s1), RS(s2); } inline void RS(char *s1, char *s2, char *s3) { RS(s1), RS(s2), RS(s3); } template <class T0, class T1> inline T0 &RDD(T0 &a, T1 &b) { RDD(a), RDD(b); return a; } template <class T0, class T1, class T2> inline T1 &RDD(T0 &a, T1 &b, T2 &c) { RDD(a), RDD(b), RDD(c); return a; } template <class T> inline void RST(T &A) { memset(A, 0, sizeof(A)); } template <class T> inline void FLC(T &A, int x) { memset(A, x, sizeof(A)); } template <class T> inline void CLR(T &A) { A.clear(); } template <class T0, class T1> inline void RST(T0 &A0, T1 &A1) { RST(A0), RST(A1); } template <class T0, class T1, class T2> inline void RST(T0 &A0, T1 &A1, T2 &A2) { RST(A0), RST(A1), RST(A2); } template <class T0, class T1, class T2, class T3> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3) { RST(A0), RST(A1), RST(A2), RST(A3); } template <class T0, class T1, class T2, class T3, class T4> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4) { RST(A0), RST(A1), RST(A2), RST(A3), RST(A4); } template <class T0, class T1, class T2, class T3, class T4, class T5> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5) { RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5); } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6) { RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6); } template <class T0, class T1> inline void FLC(T0 &A0, T1 &A1, int x) { FLC(A0, x), FLC(A1, x); } template <class T0, class T1, class T2> inline void FLC(T0 &A0, T1 &A1, T2 &A2, int x) { FLC(A0, x), FLC(A1, x), FLC(A2, x); } template <class T0, class T1, class T2, class T3> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, int x) { FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x); } template <class T0, class T1, class T2, class T3, class T4> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, int x) { FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x); } template <class T0, class T1, class T2, class T3, class T4, class T5> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, int x) { FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x); } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6, int x) { FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x), FLC(A6, x); } template <class T> inline void CLR(priority_queue<T> &Q) { while (!Q.empty()) Q.pop(); } template <class T> inline void CLR(stack<T> &S) { while (!S.empty()) S.pop(); } template <class T> inline void CLR(queue<T> &Q) { while (!Q.empty()) Q.pop(); } template <class T0, class T1> inline void CLR(T0 &A0, T1 &A1) { CLR(A0), CLR(A1); } template <class T0, class T1, class T2> inline void CLR(T0 &A0, T1 &A1, T2 &A2) { CLR(A0), CLR(A1), CLR(A2); } template <class T0, class T1, class T2, class T3> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3) { CLR(A0), CLR(A1), CLR(A2), CLR(A3); } template <class T0, class T1, class T2, class T3, class T4> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4) { CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4); } template <class T0, class T1, class T2, class T3, class T4, class T5> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5) { CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5); } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6) { CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6); } template <class T> inline void CLR(T &A, int n) { REP(i, n) CLR(A[i]); } template <class T> inline bool EPT(T &a) { return a.empty(); } template <class T> inline T &SRT(T &A) { sort(ALL(A)); return A; } template <class T, class C> inline T &SRT(T &A, C cmp) { sort(ALL(A), cmp); return A; } template <class T> inline T &RVS(T &A) { reverse(ALL(A)); return A; } template <class T> inline T &UNQQ(T &A) { A.resize(unique(ALL(A)) - A.begin()); return A; } template <class T> inline T &UNQ(T &A) { SRT(A); return UNQQ(A); } template <class T, class C> inline T &UNQ(T &A, C cmp) { SRT(A, cmp); return UNQQ(A); } //} /** Constant List .. **/ //{ // const int MOD = int(1e9) + 7; const int MOD = 998244353; // int(1e9) + 1; const int INF = 0x3f3f3f3f; const LL INFF = 0x3f3f3f3f3f3f3f3fLL; const DB EPS = 1e-9; const DB OO = 1e20; const DB PI = acos(-1.0); // M_PI; const int dx[] = {-2, -2, -1, -1, 1, 1, 2, 2}; const int dy[] = {-1, 1, -2, 2, -2, 2, -1, 1}; //} /** Add On .. **/ //{ // <<= '0. Nichi Joo ., //{ template <class T> inline bool checkMin(T &a, const T b) { return b < a ? a = b, 1 : 0; } template <class T> inline bool checkMax(T &a, const T b) { return a < b ? a = b, 1 : 0; } template <class T, class C> inline bool checkUpd(T &a, const T b, C c) { return c(b, a) ? a = b, 1 : 0; } template <class T> inline T min(T a, T b, T c) { return min(min(a, b), c); } template <class T> inline T max(T a, T b, T c) { return max(max(a, b), c); } template <class T> inline T min(T a, T b, T c, T d) { return min(min(a, b), min(c, d)); } template <class T> inline T max(T a, T b, T c, T d) { return max(max(a, b), max(c, d)); } template <class T> inline T min(T a, T b, T c, T d, T e) { return min(min(min(a, b), min(c, d)), e); } template <class T> inline T max(T a, T b, T c, T d, T e) { return max(max(max(a, b), max(c, d)), e); } template <class T> inline T sqr(T a) { return a * a; } template <class T> inline T cub(T a) { return a * a * a; } template <class T> inline T ceil(T x, T y) { return (x + y - 1) / y; } template <class T> T abs(T x) { return x > 0 ? x : -x; } inline int sgn(DB x) { return x < -EPS ? -1 : x > EPS; } inline int sgn(DB x, DB y) { return sgn(x - y); } inline DB cos(DB a, DB b, DB c) { return (sqr(a) + sqr(b) - sqr(c)) / (2 * a * b); } inline DB cot(DB x) { return 1. / tan(x); }; inline DB sec(DB x) { return 1. / cos(x); }; inline DB csc(DB x) { return 1. / sin(x); }; //} // <<= '1. Bitwise Operation ., //{ namespace BO { inline bool _1(int x, int i) { return bool(x & 1 << i); } inline bool _1(LL x, int i) { return bool(x & 1LL << i); } inline LL _1(int i) { return 1LL << i; } inline LL _U(int i) { return _1(i) - 1; }; inline int reverse_bits(int x) { x = ((x >> 1) & 0x55555555) | ((x << 1) & 0xaaaaaaaa); x = ((x >> 2) & 0x33333333) | ((x << 2) & 0xcccccccc); x = ((x >> 4) & 0x0f0f0f0f) | ((x << 4) & 0xf0f0f0f0); x = ((x >> 8) & 0x00ff00ff) | ((x << 8) & 0xff00ff00); x = ((x >> 16) & 0x0000ffff) | ((x << 16) & 0xffff0000); return x; } inline LL reverse_bits(LL x) { x = ((x >> 1) & 0x5555555555555555LL) | ((x << 1) & 0xaaaaaaaaaaaaaaaaLL); x = ((x >> 2) & 0x3333333333333333LL) | ((x << 2) & 0xccccccccccccccccLL); x = ((x >> 4) & 0x0f0f0f0f0f0f0f0fLL) | ((x << 4) & 0xf0f0f0f0f0f0f0f0LL); x = ((x >> 8) & 0x00ff00ff00ff00ffLL) | ((x << 8) & 0xff00ff00ff00ff00LL); x = ((x >> 16) & 0x0000ffff0000ffffLL) | ((x << 16) & 0xffff0000ffff0000LL); x = ((x >> 32) & 0x00000000ffffffffLL) | ((x << 32) & 0xffffffff00000000LL); return x; } template <class T> inline bool odd(T x) { return x & 1; } template <class T> inline bool even(T x) { return !odd(x); } template <class T> inline T low_bit(T x) { return x & -x; } template <class T> inline T high_bit(T x) { T p = low_bit(x); while (p != x) x -= p, p = low_bit(x); return p; } template <class T> inline T cover_bit(T x) { T p = 1; while (p < x) p <<= 1; return p; } template <class T> inline int cover_idx(T x) { int p = 0; while (_1(p) < x) ++p; return p; } inline int clz(int x) { return __builtin_clz(x); } inline int clz(LL x) { return __builtin_clzll(x); } inline int ctz(int x) { return __builtin_ctz(x); } inline int ctz(LL x) { return __builtin_ctzll(x); } inline int lg2(int x) { return !x ? -1 : 31 - clz(x); } inline int lg2(LL x) { return !x ? -1 : 63 - clz(x); } inline int low_idx(int x) { return !x ? -1 : ctz(x); } inline int low_idx(LL x) { return !x ? -1 : ctz(x); } inline int high_idx(int x) { return lg2(x); } inline int high_idx(LL x) { return lg2(x); } inline int parity(int x) { return __builtin_parity(x); } inline int parity(LL x) { return __builtin_parityll(x); } inline int count_bits(int x) { return __builtin_popcount(x); } inline int count_bits(LL x) { return __builtin_popcountll(x); } } // namespace BO using namespace BO; //} // <<= '2. Number Theory .,//{ namespace NT { #define gcd __gcd inline LL lcm(LL a, LL b) { return a * b / gcd(a, b); } inline void INC(int &a, int b) { a += b; if (a >= MOD) a -= MOD; } inline int sum(int a, int b) { a += b; if (a >= MOD) a -= MOD; return a; } /* 模数两倍刚好超 int 时。 inline int sum(uint a, int b){a += b; a %= MOD;if (a < 0) a += MOD; return a;} inline void INC(int &a, int b){a = sum(a, b);} */ inline void DEC(int &a, int b) { a -= b; if (a < 0) a += MOD; } inline int dff(int a, int b) { a -= b; if (a < 0) a += MOD; return a; } inline void MUL(int &a, int b) { a = (LL)a * b % MOD; } // inline int pdt(int a, int b){return (LL)a * b % MOD;} inline int pdt(int x, int y) { int ret; __asm__ __volatile__("\tmull %%ebx\n\tdivl %%ecx\n" : "=d"(ret) : "a"(x), "b"(y), "c"(MOD)); return ret; } inline int gcd(int m, int n, int &x, int &y) { x = 1, y = 0; int xx = 0, yy = 1, q; while (1) { q = m / n, m %= n; if (!m) { x = xx, y = yy; return n; } DEC(x, pdt(q, xx)), DEC(y, pdt(q, yy)); q = n / m, n %= m; if (!n) return m; DEC(xx, pdt(q, x)), DEC(yy, pdt(q, y)); } } inline int sum(int a, int b, int c) { return sum(a, sum(b, c)); } inline int sum(int a, int b, int c, int d) { return sum(sum(a, b), sum(c, d)); } inline int pdt(int a, int b, int c) { return pdt(a, pdt(b, c)); } inline int pdt(int a, int b, int c, int d) { return pdt(pdt(a, b), pdt(c, d)); } inline int pow(int a, LL b) { int c(1); while (b) { if (b & 1) MUL(c, a); MUL(a, a), b >>= 1; } return c; } template <class T> inline T pow(T a, LL b) { T c(1); while (b) { if (b & 1) c *= a; a *= a, b >>= 1; } return c; } template <class T> inline T pow(T a, int b) { return pow(a, (LL)b); } inline int _I(int b) { int a = MOD, x1 = 0, x2 = 1, q; while (1) { q = a / b, a %= b; if (!a) return x2; DEC(x1, pdt(q, x2)); q = b / a, b %= a; if (!b) return x1; DEC(x2, pdt(q, x1)); } } inline void DIV(int &a, int b) { MUL(a, _I(b)); } inline int qtt(int a, int b) { return pdt(a, _I(b)); } struct Int { int val; operator int() const { return val; } Int(int _val = 0) : val(_val) { val %= MOD; if (val < 0) val += MOD; } Int(LL _val) : val(_val) { _val %= MOD; if (_val < 0) _val += MOD; val = _val; } Int &operator+=(const int &rhs) { INC(val, rhs); rTs; } Int operator+(const int &rhs) const { return sum(val, rhs); } Int &operator-=(const int &rhs) { DEC(val, rhs); rTs; } Int operator-(const int &rhs) const { return dff(val, rhs); } Int &operator*=(const int &rhs) { MUL(val, rhs); rTs; } Int operator*(const int &rhs) const { return pdt(val, rhs); } Int &operator/=(const int &rhs) { DIV(val, rhs); rTs; } Int operator/(const int &rhs) const { return qtt(val, rhs); } Int operator-() const { return MOD - *this; } }; } // namespace NT using namespace NT; //} //} /** I/O Accelerator Interface .. **/ //{ #define g (c = getchar()) #define d isdigit(g) #define p x = x * 10 + c - '0' #define n x = x * 10 + '0' - c #define pp l /= 10, p #define nn l /= 10, n template <class T> inline T &RD(T &x) { char c; while (!d) ; x = c - '0'; while (d) p; return x; } template <class T> inline T &RDD(T &x) { char c; while (g, c != '-' && !isdigit(c)) ; if (c == '-') { x = '0' - g; while (d) n; } else { x = c - '0'; while (d) p; } return x; } inline DB &RF(DB &x) { // scanf("%lf", &x); char c; while (g, c != '-' && c != '.' && !isdigit(c)) ; if (c == '-') if (g == '.') { x = 0; DB l = 1; while (d) nn; x *= l; } else { x = '0' - c; while (d) n; if (c == '.') { DB l = 1; while (d) nn; x *= l; } } else if (c == '.') { x = 0; DB l = 1; while (d) pp; x *= l; } else { x = c - '0'; while (d) p; if (c == '.') { DB l = 1; while (d) pp; x *= l; } } return x; } #undef nn #undef pp #undef n #undef p #undef d #undef g inline char *RS(char *s) { // gets(s); scanf("%s", s); return s; } LL last_ans; int Case; template <class T> inline void OT(const T &x) { // printf("Case #%d: ", ++Case); printf("%lld\n", x); // printf("%I64d\n", x); // printf("%.9f\n", x); // printf("%d\n", x); // cout << x << endl; // last_ans = x; } //}/* //.................................................................................................................................. //*/ const int N = int(2e5) + 9; vector<pair<LL, LL>> a; VI b; int LV = 30; LL dp[N]; int n, T; int fb(LL t) { int n = SZ(b); REP(i, n) { t += b[i]; if (t > T) return i; } return n; } int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif RD(n, T); ++T; DO(n) { LL x, y; RD(x, y); ++y; if (x) a.PB({x, y}); else b.PB(y); } // bi + (bi+1)*aj + bj < // bj + (bj+1)*ai + bi n = SZ(a); a.PB({1, 0}); SRT(a, [](const auto &x, const auto &y) { return (LL)x.se * y.fi < (LL)y.se * x.fi; }); FLC(dp, 0x3f); dp[0] = 1; REP_1(ai, n) { int x = a[ai].fi, y = a[ai].se; DWN(i, LV, 0) if (dp[i] <= T) { checkMin(dp[i + 1], dp[i] * x + dp[i] + y); } } SRT(b); int z = 0; REP(i, LV) if (dp[i] <= T) { checkMax(z, i + fb(dp[i])); } cout << z << endl; }
/* This code has been written by MinakoKojima, feel free to ask me question. Blog: http://www.shuizilong.com/house Template Date: 2015.10.12 Note: ... */ #pragma comment(linker, "/STACK:36777216") // #pragma GCC optimize ("O2") #define LOCAL #include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> // #include <tr1/unordered_set> // #include <tr1/unordered_map> // #include <array> 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 DWN(i, b, a) for (int i = b - 1; i >= a; --i) #define REP_1(i, n) for (int i = 1; i <= n; ++i) #define FOR_1(i, a, b) for (int i = a; i <= b; ++i) #define DWN_1(i, b, a) for (int i = b; i >= a; --i) #define REP_C(i, n) for (int n____ = n, i = 0; i < n____; ++i) #define FOR_C(i, a, b) for (int b____ = b, i = a; i < b____; ++i) #define DWN_C(i, b, a) for (int a____ = a, i = b - 1; i >= a____; --i) #define REP_N(i, n) for (i = 0; i < n; ++i) #define FOR_N(i, a, b) for (i = a; i < b; ++i) #define DWN_N(i, b, a) for (i = b - 1; i >= a; --i) #define REP_1_C(i, n) for (int n____ = n, i = 1; i <= n____; ++i) #define FOR_1_C(i, a, b) for (int b____ = b, i = a; i <= b____; ++i) #define DWN_1_C(i, b, a) for (int a____ = a, i = b; i >= a____; --i) #define REP_1_N(i, n) for (i = 1; i <= n; ++i) #define FOR_1_N(i, a, b) for (i = a; i <= b; ++i) #define DWN_1_N(i, b, a) for (i = b; i >= a; --i) #define REP_C_N(i, n) for (int n____ = (i = 0, n); i < n____; ++i) #define FOR_C_N(i, a, b) for (int b____ = (i = 0, b); i < b____; ++i) #define DWN_C_N(i, b, a) for (int a____ = (i = b - 1, a); i >= a____; --i) #define REP_1_C_N(i, n) for (int n____ = (i = 1, n); i <= n____; ++i) #define FOR_1_C_N(i, a, b) for (int b____ = (i = a, b); i <= b____; ++i) #define DWN_1_C_N(i, b, a) for (int a____ = (i = b, a); i >= a____; --i) #define ECH(it, A) \ for (__typeof((A).begin()) it = (A).begin(); it != (A).end(); ++it) #define rECH(it, A) \ for (__typeof((A).rbegin()) it = (A).rbegin(); it != (A).rend(); ++it) #define REP_S(i, str) for (char *i = str; *i; ++i) #define REP_L(i, hd, suc) for (int i = hd; i; i = suc[i]) #define REP_G(i, u) REP_L(i, hd[u], suc) #define REP_SS(x, s) for (int x = s; x; x = (x - 1) & s) #define DO(n) for (int ____n = n; ____n-- > 0;) #define REP_2(i, j, n, m) REP(i, n) REP(j, m) #define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m) #define REP_3(i, j, k, n, m, l) REP(i, n) REP(j, m) REP(k, l) #define REP_3_1(i, j, k, n, m, l) REP_1(i, n) REP_1(j, m) REP_1(k, l) #define REP_4(i, j, k, ii, n, m, l, nn) \ REP(i, n) REP(j, m) REP(k, l) REP(ii, nn) #define REP_4_1(i, j, k, ii, n, m, l, nn) \ REP_1(i, n) REP_1(j, m) REP_1(k, l) REP_1(ii, nn) #define ALL(A) A.begin(), A.end() #define LLA(A) A.rbegin(), A.rend() #define CPY(A, B) memcpy(A, B, sizeof(A)) #define INS(A, P, B) A.insert(A.begin() + P, B) #define ERS(A, P) A.erase(A.begin() + P) #define LBD(A, x) (lower_bound(ALL(A), x) - A.begin()) #define UBD(A, x) (upper_bound(ALL(A), x) - A.begin()) #define CTN(T, x) (T.find(x) != T.end()) #define SZ(A) int((A).size()) #define PB push_back #define MP(A, B) make_pair(A, B) #define PTT pair<T, T> #define Ts *this #define rTs return Ts #define fi first #define se second #define re real() #define im imag() #define Rush for (int ____T = RD(); ____T--;) #define Display(A, n, m) \ { \ REP(i, n) { \ REP(j, m - 1) cout << A[i][j] << " "; \ cout << A[i][m - 1] << endl; \ } \ } #define Display_1(A, n, m) \ { \ REP_1(i, n) { \ REP_1(j, m - 1) cout << A[i][j] << " "; \ cout << A[i][m] << endl; \ } \ } typedef long long LL; // typedef long double DB; typedef double DB; typedef unsigned uint; typedef unsigned long long uLL; typedef vector<int> VI; typedef vector<char> VC; typedef vector<string> VS; typedef vector<LL> VL; typedef vector<DB> VF; typedef set<int> SI; typedef set<string> SS; typedef map<int, int> MII; typedef map<string, int> MSI; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef vector<PII> VII; typedef vector<VI> VVI; typedef vector<VII> VVII; template <class T> inline T &RD(T &); template <class T> inline void OT(const T &); // inline int RD(){int x; return RD(x);} inline LL RD() { LL x; return RD(x); } inline DB &RF(DB &); inline DB RF() { DB x; return RF(x); } inline char *RS(char *s); inline char &RC(char &c); inline char RC(); inline char &RC(char &c) { scanf(" %c", &c); return c; } inline char RC() { char c; return RC(c); } // inline char& RC(char &c){c = getchar(); return c;} // inline char RC(){return getchar();} template <class T> inline T &RDD(T &); inline LL RDD() { LL x; return RDD(x); } template <class T0, class T1> inline T0 &RD(T0 &x0, T1 &x1) { RD(x0), RD(x1); return x0; } template <class T0, class T1, class T2> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2) { RD(x0), RD(x1), RD(x2); return x0; } template <class T0, class T1, class T2, class T3> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3) { RD(x0), RD(x1), RD(x2), RD(x3); return x0; } template <class T0, class T1, class T2, class T3, class T4> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4) { RD(x0), RD(x1), RD(x2), RD(x3), RD(x4); return x0; } template <class T0, class T1, class T2, class T3, class T4, class T5> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5) { RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5); return x0; } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6) { RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6); return x0; } template <class T0, class T1> inline void OT(const T0 &x0, const T1 &x1) { OT(x0), OT(x1); } template <class T0, class T1, class T2> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2) { OT(x0), OT(x1), OT(x2); } template <class T0, class T1, class T2, class T3> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3) { OT(x0), OT(x1), OT(x2), OT(x3); } template <class T0, class T1, class T2, class T3, class T4> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4) { OT(x0), OT(x1), OT(x2), OT(x3), OT(x4); } template <class T0, class T1, class T2, class T3, class T4, class T5> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5) { OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5); } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5, const T6 &x6) { OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6); } inline char &RC(char &a, char &b) { RC(a), RC(b); return a; } inline char &RC(char &a, char &b, char &c) { RC(a), RC(b), RC(c); return a; } inline char &RC(char &a, char &b, char &c, char &d) { RC(a), RC(b), RC(c), RC(d); return a; } inline char &RC(char &a, char &b, char &c, char &d, char &e) { RC(a), RC(b), RC(c), RC(d), RC(e); return a; } inline char &RC(char &a, char &b, char &c, char &d, char &e, char &f) { RC(a), RC(b), RC(c), RC(d), RC(e), RC(f); return a; } inline char &RC(char &a, char &b, char &c, char &d, char &e, char &f, char &g) { RC(a), RC(b), RC(c), RC(d), RC(e), RC(f), RC(g); return a; } inline DB &RF(DB &a, DB &b) { RF(a), RF(b); return a; } inline DB &RF(DB &a, DB &b, DB &c) { RF(a), RF(b), RF(c); return a; } inline DB &RF(DB &a, DB &b, DB &c, DB &d) { RF(a), RF(b), RF(c), RF(d); return a; } inline DB &RF(DB &a, DB &b, DB &c, DB &d, DB &e) { RF(a), RF(b), RF(c), RF(d), RF(e); return a; } inline DB &RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f) { RF(a), RF(b), RF(c), RF(d), RF(e), RF(f); return a; } inline DB &RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f, DB &g) { RF(a), RF(b), RF(c), RF(d), RF(e), RF(f), RF(g); return a; } inline void RS(char *s1, char *s2) { RS(s1), RS(s2); } inline void RS(char *s1, char *s2, char *s3) { RS(s1), RS(s2), RS(s3); } template <class T0, class T1> inline T0 &RDD(T0 &a, T1 &b) { RDD(a), RDD(b); return a; } template <class T0, class T1, class T2> inline T1 &RDD(T0 &a, T1 &b, T2 &c) { RDD(a), RDD(b), RDD(c); return a; } template <class T> inline void RST(T &A) { memset(A, 0, sizeof(A)); } template <class T> inline void FLC(T &A, int x) { memset(A, x, sizeof(A)); } template <class T> inline void CLR(T &A) { A.clear(); } template <class T0, class T1> inline void RST(T0 &A0, T1 &A1) { RST(A0), RST(A1); } template <class T0, class T1, class T2> inline void RST(T0 &A0, T1 &A1, T2 &A2) { RST(A0), RST(A1), RST(A2); } template <class T0, class T1, class T2, class T3> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3) { RST(A0), RST(A1), RST(A2), RST(A3); } template <class T0, class T1, class T2, class T3, class T4> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4) { RST(A0), RST(A1), RST(A2), RST(A3), RST(A4); } template <class T0, class T1, class T2, class T3, class T4, class T5> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5) { RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5); } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6) { RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6); } template <class T0, class T1> inline void FLC(T0 &A0, T1 &A1, int x) { FLC(A0, x), FLC(A1, x); } template <class T0, class T1, class T2> inline void FLC(T0 &A0, T1 &A1, T2 &A2, int x) { FLC(A0, x), FLC(A1, x), FLC(A2, x); } template <class T0, class T1, class T2, class T3> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, int x) { FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x); } template <class T0, class T1, class T2, class T3, class T4> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, int x) { FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x); } template <class T0, class T1, class T2, class T3, class T4, class T5> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, int x) { FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x); } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6, int x) { FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x), FLC(A6, x); } template <class T> inline void CLR(priority_queue<T> &Q) { while (!Q.empty()) Q.pop(); } template <class T> inline void CLR(stack<T> &S) { while (!S.empty()) S.pop(); } template <class T> inline void CLR(queue<T> &Q) { while (!Q.empty()) Q.pop(); } template <class T0, class T1> inline void CLR(T0 &A0, T1 &A1) { CLR(A0), CLR(A1); } template <class T0, class T1, class T2> inline void CLR(T0 &A0, T1 &A1, T2 &A2) { CLR(A0), CLR(A1), CLR(A2); } template <class T0, class T1, class T2, class T3> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3) { CLR(A0), CLR(A1), CLR(A2), CLR(A3); } template <class T0, class T1, class T2, class T3, class T4> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4) { CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4); } template <class T0, class T1, class T2, class T3, class T4, class T5> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5) { CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5); } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6) { CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6); } template <class T> inline void CLR(T &A, int n) { REP(i, n) CLR(A[i]); } template <class T> inline bool EPT(T &a) { return a.empty(); } template <class T> inline T &SRT(T &A) { sort(ALL(A)); return A; } template <class T, class C> inline T &SRT(T &A, C cmp) { sort(ALL(A), cmp); return A; } template <class T> inline T &RVS(T &A) { reverse(ALL(A)); return A; } template <class T> inline T &UNQQ(T &A) { A.resize(unique(ALL(A)) - A.begin()); return A; } template <class T> inline T &UNQ(T &A) { SRT(A); return UNQQ(A); } template <class T, class C> inline T &UNQ(T &A, C cmp) { SRT(A, cmp); return UNQQ(A); } //} /** Constant List .. **/ //{ // const int MOD = int(1e9) + 7; const int MOD = 998244353; // int(1e9) + 1; const int INF = 0x3f3f3f3f; const LL INFF = 0x3f3f3f3f3f3f3f3fLL; const DB EPS = 1e-9; const DB OO = 1e20; const DB PI = acos(-1.0); // M_PI; const int dx[] = {-2, -2, -1, -1, 1, 1, 2, 2}; const int dy[] = {-1, 1, -2, 2, -2, 2, -1, 1}; //} /** Add On .. **/ //{ // <<= '0. Nichi Joo ., //{ template <class T> inline bool checkMin(T &a, const T b) { return b < a ? a = b, 1 : 0; } template <class T> inline bool checkMax(T &a, const T b) { return a < b ? a = b, 1 : 0; } template <class T, class C> inline bool checkUpd(T &a, const T b, C c) { return c(b, a) ? a = b, 1 : 0; } template <class T> inline T min(T a, T b, T c) { return min(min(a, b), c); } template <class T> inline T max(T a, T b, T c) { return max(max(a, b), c); } template <class T> inline T min(T a, T b, T c, T d) { return min(min(a, b), min(c, d)); } template <class T> inline T max(T a, T b, T c, T d) { return max(max(a, b), max(c, d)); } template <class T> inline T min(T a, T b, T c, T d, T e) { return min(min(min(a, b), min(c, d)), e); } template <class T> inline T max(T a, T b, T c, T d, T e) { return max(max(max(a, b), max(c, d)), e); } template <class T> inline T sqr(T a) { return a * a; } template <class T> inline T cub(T a) { return a * a * a; } template <class T> inline T ceil(T x, T y) { return (x + y - 1) / y; } template <class T> T abs(T x) { return x > 0 ? x : -x; } inline int sgn(DB x) { return x < -EPS ? -1 : x > EPS; } inline int sgn(DB x, DB y) { return sgn(x - y); } inline DB cos(DB a, DB b, DB c) { return (sqr(a) + sqr(b) - sqr(c)) / (2 * a * b); } inline DB cot(DB x) { return 1. / tan(x); }; inline DB sec(DB x) { return 1. / cos(x); }; inline DB csc(DB x) { return 1. / sin(x); }; //} // <<= '1. Bitwise Operation ., //{ namespace BO { inline bool _1(int x, int i) { return bool(x & 1 << i); } inline bool _1(LL x, int i) { return bool(x & 1LL << i); } inline LL _1(int i) { return 1LL << i; } inline LL _U(int i) { return _1(i) - 1; }; inline int reverse_bits(int x) { x = ((x >> 1) & 0x55555555) | ((x << 1) & 0xaaaaaaaa); x = ((x >> 2) & 0x33333333) | ((x << 2) & 0xcccccccc); x = ((x >> 4) & 0x0f0f0f0f) | ((x << 4) & 0xf0f0f0f0); x = ((x >> 8) & 0x00ff00ff) | ((x << 8) & 0xff00ff00); x = ((x >> 16) & 0x0000ffff) | ((x << 16) & 0xffff0000); return x; } inline LL reverse_bits(LL x) { x = ((x >> 1) & 0x5555555555555555LL) | ((x << 1) & 0xaaaaaaaaaaaaaaaaLL); x = ((x >> 2) & 0x3333333333333333LL) | ((x << 2) & 0xccccccccccccccccLL); x = ((x >> 4) & 0x0f0f0f0f0f0f0f0fLL) | ((x << 4) & 0xf0f0f0f0f0f0f0f0LL); x = ((x >> 8) & 0x00ff00ff00ff00ffLL) | ((x << 8) & 0xff00ff00ff00ff00LL); x = ((x >> 16) & 0x0000ffff0000ffffLL) | ((x << 16) & 0xffff0000ffff0000LL); x = ((x >> 32) & 0x00000000ffffffffLL) | ((x << 32) & 0xffffffff00000000LL); return x; } template <class T> inline bool odd(T x) { return x & 1; } template <class T> inline bool even(T x) { return !odd(x); } template <class T> inline T low_bit(T x) { return x & -x; } template <class T> inline T high_bit(T x) { T p = low_bit(x); while (p != x) x -= p, p = low_bit(x); return p; } template <class T> inline T cover_bit(T x) { T p = 1; while (p < x) p <<= 1; return p; } template <class T> inline int cover_idx(T x) { int p = 0; while (_1(p) < x) ++p; return p; } inline int clz(int x) { return __builtin_clz(x); } inline int clz(LL x) { return __builtin_clzll(x); } inline int ctz(int x) { return __builtin_ctz(x); } inline int ctz(LL x) { return __builtin_ctzll(x); } inline int lg2(int x) { return !x ? -1 : 31 - clz(x); } inline int lg2(LL x) { return !x ? -1 : 63 - clz(x); } inline int low_idx(int x) { return !x ? -1 : ctz(x); } inline int low_idx(LL x) { return !x ? -1 : ctz(x); } inline int high_idx(int x) { return lg2(x); } inline int high_idx(LL x) { return lg2(x); } inline int parity(int x) { return __builtin_parity(x); } inline int parity(LL x) { return __builtin_parityll(x); } inline int count_bits(int x) { return __builtin_popcount(x); } inline int count_bits(LL x) { return __builtin_popcountll(x); } } // namespace BO using namespace BO; //} // <<= '2. Number Theory .,//{ namespace NT { #define gcd __gcd inline LL lcm(LL a, LL b) { return a * b / gcd(a, b); } inline void INC(int &a, int b) { a += b; if (a >= MOD) a -= MOD; } inline int sum(int a, int b) { a += b; if (a >= MOD) a -= MOD; return a; } /* 模数两倍刚好超 int 时。 inline int sum(uint a, int b){a += b; a %= MOD;if (a < 0) a += MOD; return a;} inline void INC(int &a, int b){a = sum(a, b);} */ inline void DEC(int &a, int b) { a -= b; if (a < 0) a += MOD; } inline int dff(int a, int b) { a -= b; if (a < 0) a += MOD; return a; } inline void MUL(int &a, int b) { a = (LL)a * b % MOD; } // inline int pdt(int a, int b){return (LL)a * b % MOD;} inline int pdt(int x, int y) { int ret; __asm__ __volatile__("\tmull %%ebx\n\tdivl %%ecx\n" : "=d"(ret) : "a"(x), "b"(y), "c"(MOD)); return ret; } inline int gcd(int m, int n, int &x, int &y) { x = 1, y = 0; int xx = 0, yy = 1, q; while (1) { q = m / n, m %= n; if (!m) { x = xx, y = yy; return n; } DEC(x, pdt(q, xx)), DEC(y, pdt(q, yy)); q = n / m, n %= m; if (!n) return m; DEC(xx, pdt(q, x)), DEC(yy, pdt(q, y)); } } inline int sum(int a, int b, int c) { return sum(a, sum(b, c)); } inline int sum(int a, int b, int c, int d) { return sum(sum(a, b), sum(c, d)); } inline int pdt(int a, int b, int c) { return pdt(a, pdt(b, c)); } inline int pdt(int a, int b, int c, int d) { return pdt(pdt(a, b), pdt(c, d)); } inline int pow(int a, LL b) { int c(1); while (b) { if (b & 1) MUL(c, a); MUL(a, a), b >>= 1; } return c; } template <class T> inline T pow(T a, LL b) { T c(1); while (b) { if (b & 1) c *= a; a *= a, b >>= 1; } return c; } template <class T> inline T pow(T a, int b) { return pow(a, (LL)b); } inline int _I(int b) { int a = MOD, x1 = 0, x2 = 1, q; while (1) { q = a / b, a %= b; if (!a) return x2; DEC(x1, pdt(q, x2)); q = b / a, b %= a; if (!b) return x1; DEC(x2, pdt(q, x1)); } } inline void DIV(int &a, int b) { MUL(a, _I(b)); } inline int qtt(int a, int b) { return pdt(a, _I(b)); } struct Int { int val; operator int() const { return val; } Int(int _val = 0) : val(_val) { val %= MOD; if (val < 0) val += MOD; } Int(LL _val) : val(_val) { _val %= MOD; if (_val < 0) _val += MOD; val = _val; } Int &operator+=(const int &rhs) { INC(val, rhs); rTs; } Int operator+(const int &rhs) const { return sum(val, rhs); } Int &operator-=(const int &rhs) { DEC(val, rhs); rTs; } Int operator-(const int &rhs) const { return dff(val, rhs); } Int &operator*=(const int &rhs) { MUL(val, rhs); rTs; } Int operator*(const int &rhs) const { return pdt(val, rhs); } Int &operator/=(const int &rhs) { DIV(val, rhs); rTs; } Int operator/(const int &rhs) const { return qtt(val, rhs); } Int operator-() const { return MOD - *this; } }; } // namespace NT using namespace NT; //} //} /** I/O Accelerator Interface .. **/ //{ #define g (c = getchar()) #define d isdigit(g) #define p x = x * 10 + c - '0' #define n x = x * 10 + '0' - c #define pp l /= 10, p #define nn l /= 10, n template <class T> inline T &RD(T &x) { char c; while (!d) ; x = c - '0'; while (d) p; return x; } template <class T> inline T &RDD(T &x) { char c; while (g, c != '-' && !isdigit(c)) ; if (c == '-') { x = '0' - g; while (d) n; } else { x = c - '0'; while (d) p; } return x; } inline DB &RF(DB &x) { // scanf("%lf", &x); char c; while (g, c != '-' && c != '.' && !isdigit(c)) ; if (c == '-') if (g == '.') { x = 0; DB l = 1; while (d) nn; x *= l; } else { x = '0' - c; while (d) n; if (c == '.') { DB l = 1; while (d) nn; x *= l; } } else if (c == '.') { x = 0; DB l = 1; while (d) pp; x *= l; } else { x = c - '0'; while (d) p; if (c == '.') { DB l = 1; while (d) pp; x *= l; } } return x; } #undef nn #undef pp #undef n #undef p #undef d #undef g inline char *RS(char *s) { // gets(s); scanf("%s", s); return s; } LL last_ans; int Case; template <class T> inline void OT(const T &x) { // printf("Case #%d: ", ++Case); printf("%lld\n", x); // printf("%I64d\n", x); // printf("%.9f\n", x); // printf("%d\n", x); // cout << x << endl; // last_ans = x; } //}/* //.................................................................................................................................. //*/ const int N = int(2e5) + 9; vector<pair<LL, LL>> a; VI b; int LV = 30; LL dp[N]; int n, T; int fb(LL t) { int n = SZ(b); REP(i, n) { t += b[i]; if (t > T) return i; } return n; } int main() { RD(n, T); ++T; DO(n) { LL x, y; RD(x, y); ++y; if (x) a.PB({x, y}); else b.PB(y); } // bi + (bi+1)*aj + bj < // bj + (bj+1)*ai + bi n = SZ(a); a.PB({1, 0}); SRT(a, [](const auto &x, const auto &y) { return (LL)x.se * y.fi < (LL)y.se * x.fi; }); FLC(dp, 0x3f); dp[0] = 1; REP_1(ai, n) { int x = a[ai].fi, y = a[ai].se; DWN(i, LV, 0) if (dp[i] <= T) { checkMin(dp[i + 1], dp[i] * x + dp[i] + y); } } SRT(b); int z = 0; REP(i, LV) if (dp[i] <= T) { checkMax(z, i + fb(dp[i])); } cout << z << endl; }
delete
794
799
794
794
TLE
p02750
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair using namespace std; typedef pair<int, int> pii; const int N = 35; pii a[200010]; long long dp[200010][40]; long long sum[200010]; bool cmp(pii a, pii b) { return (long double)a.fi / (a.se + 1) > (long double)b.fi / (b.se + 1); } int main() { int n, T; scanf("%d%d", &n, &T); for (int i = 0; i < n; i++) { scanf("%d%d", &a[i].fi, &a[i].se); } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { if (i == j || j == k || i == k) continue; if (cmp(a[i], a[j]) && cmp(a[j], a[k]) && !cmp(a[i], a[k])) assert(0); if (!cmp(a[i], a[j]) && !cmp(a[j], a[k]) && cmp(a[i], a[k])) assert(0); } } } sort(a, a + n, cmp); int mid = 0; while (mid < n && a[mid].fi != 0) mid++; sort(a + mid, a + n); for (int i = mid; i < n; i++) { sum[i] = a[i].se + 1; if (i != mid) sum[i] += sum[i - 1]; } for (int i = 0; i <= N; i++) { dp[0][i] = 0x3f3f3f3f; } dp[0][0] = 0; int ans = 0; for (int i = 0; i < mid; i++) { for (int j = N; j >= 1; j--) { long long tmp = dp[i][j - 1]; tmp++, tmp += tmp * a[i].fi + a[i].se; tmp = min(tmp, (long long)T + 1); dp[i + 1][j] = min(dp[i][j], tmp); int pos = upper_bound(sum + mid, sum + n, T - dp[i][j]) - sum; if (dp[i][j] <= T) ans = max(ans, j + pos - mid); } } for (int j = 0; j <= N; j++) { long long minj = 0x3f3f3f3f; for (int i = 0; i <= mid; i++) { minj = min(minj, dp[i][j]); } int pos = upper_bound(sum + mid, sum + n, T - minj) - sum; if (minj <= T) ans = max(ans, j + pos - mid); } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair using namespace std; typedef pair<int, int> pii; const int N = 35; pii a[200010]; long long dp[200010][40]; long long sum[200010]; bool cmp(pii a, pii b) { return (long double)a.fi / (a.se + 1) > (long double)b.fi / (b.se + 1); } int main() { int n, T; scanf("%d%d", &n, &T); for (int i = 0; i < n; i++) { scanf("%d%d", &a[i].fi, &a[i].se); } sort(a, a + n, cmp); int mid = 0; while (mid < n && a[mid].fi != 0) mid++; sort(a + mid, a + n); for (int i = mid; i < n; i++) { sum[i] = a[i].se + 1; if (i != mid) sum[i] += sum[i - 1]; } for (int i = 0; i <= N; i++) { dp[0][i] = 0x3f3f3f3f; } dp[0][0] = 0; int ans = 0; for (int i = 0; i < mid; i++) { for (int j = N; j >= 1; j--) { long long tmp = dp[i][j - 1]; tmp++, tmp += tmp * a[i].fi + a[i].se; tmp = min(tmp, (long long)T + 1); dp[i + 1][j] = min(dp[i][j], tmp); int pos = upper_bound(sum + mid, sum + n, T - dp[i][j]) - sum; if (dp[i][j] <= T) ans = max(ans, j + pos - mid); } } for (int j = 0; j <= N; j++) { long long minj = 0x3f3f3f3f; for (int i = 0; i <= mid; i++) { minj = min(minj, dp[i][j]); } int pos = upper_bound(sum + mid, sum + n, T - minj) - sum; if (minj <= T) ans = max(ans, j + pos - mid); } printf("%d\n", ans); return 0; }
delete
23
35
23
23
TLE
p02750
C++
Runtime Error
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools #include <bits/stdc++.h> using namespace std; using i64 = long long; const i64 MOD = 1e9 + 7; const i64 INF = i64(1e18) + 7; template <typename T> bool chmin(T &x, T y) { if (x > y) { x = y; return true; } return false; } template <typename T> bool chmax(T &x, T y) { if (x < y) { x = y; return true; } return false; } void solve(long long n, long long t, std::vector<long long> a, std::vector<long long> b) { for (int i = 0; i < n; ++i) ++a[i]; auto comp = [&](int i, int j) { i64 x = (b[i] + 1) * a[j] + b[j]; i64 y = (b[j] + 1) * a[i] + b[i]; return x < y; }; vector<int> idxes(n); iota(idxes.begin(), idxes.end(), 0); sort(idxes.begin(), idxes.end(), comp); auto aa = a, bb = b; int cnt = 0; for (int i = 0; i < n; ++i) { if (aa[idxes[i]] != 1) { a[cnt] = aa[idxes[i]]; b[cnt] = bb[idxes[i]]; ++cnt; } } int border = cnt; for (int i = 0; i < n; ++i) { if (aa[idxes[i]] == 1) { a[cnt] = aa[idxes[i]]; b[cnt] = bb[idxes[i]]; ++cnt; } } vector<vector<i64>> dp(border + 1, vector<i64>(33, INF)); dp[0][0] = 0; for (int i = 0; i < border; ++i) { for (int j = 0; j <= 32; ++j) { chmin(dp[i + 1][j], dp[i][j]); if (j != 32) { i64 time = dp[i][j] + 1; if (time > t) continue; chmin(dp[i + 1][j + 1], a[i] * time + b[i]); } } } vector<i64> res = dp.back(); auto comp2 = [&](int i, int j) { assert(a[i] == 1); assert(a[j] == 1); return b[i] < b[j]; }; sort(next(idxes.begin(), border), idxes.end(), comp2); bb = b; for (int i = border; i < n; ++i) { a[i] = 1; b[i] = bb[idxes[i]]; } vector<i64> v(1, 0); for (int i = border; i < n; ++i) v.push_back(v.back() + b[i] + 1); int ans = 0; for (int i = 0; i <= 32; ++i) { if (res[i] > t) continue; auto it = upper_bound(v.begin(), v.end(), t - res[i]); int d = distance(v.begin(), it) - 1; chmax(ans, i + d); } cout << ans << endl; } signed main() { long long N; scanf("%lld", &N); long long T; scanf("%lld", &T); std::vector<long long> a(N); std::vector<long long> b(N); for (int i = 0; i < N; i++) { scanf("%lld", &a[i]); scanf("%lld", &b[i]); } solve(N, T, std::move(a), std::move(b)); return 0; }
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools #include <bits/stdc++.h> using namespace std; using i64 = long long; const i64 MOD = 1e9 + 7; const i64 INF = i64(1e18) + 7; template <typename T> bool chmin(T &x, T y) { if (x > y) { x = y; return true; } return false; } template <typename T> bool chmax(T &x, T y) { if (x < y) { x = y; return true; } return false; } void solve(long long n, long long t, std::vector<long long> a, std::vector<long long> b) { for (int i = 0; i < n; ++i) ++a[i]; auto comp = [&](int i, int j) { i64 x = (b[i] + 1) * a[j] + b[j]; i64 y = (b[j] + 1) * a[i] + b[i]; return x < y; }; vector<int> idxes(n); iota(idxes.begin(), idxes.end(), 0); sort(idxes.begin(), idxes.end(), comp); auto aa = a, bb = b; int cnt = 0; for (int i = 0; i < n; ++i) { if (aa[idxes[i]] != 1) { a[cnt] = aa[idxes[i]]; b[cnt] = bb[idxes[i]]; ++cnt; } } int border = cnt; for (int i = 0; i < n; ++i) { if (aa[idxes[i]] == 1) { a[cnt] = aa[idxes[i]]; b[cnt] = bb[idxes[i]]; ++cnt; } } vector<vector<i64>> dp(border + 1, vector<i64>(33, INF)); dp[0][0] = 0; for (int i = 0; i < border; ++i) { for (int j = 0; j <= 32; ++j) { chmin(dp[i + 1][j], dp[i][j]); if (j != 32) { i64 time = dp[i][j] + 1; if (time > t) continue; chmin(dp[i + 1][j + 1], a[i] * time + b[i]); } } } vector<i64> res = dp.back(); auto comp2 = [&](int i, int j) { assert(a[i] == 1); assert(a[j] == 1); return b[i] < b[j]; }; iota(idxes.begin(), idxes.end(), 0); sort(next(idxes.begin(), border), idxes.end(), comp2); bb = b; for (int i = border; i < n; ++i) { a[i] = 1; b[i] = bb[idxes[i]]; } vector<i64> v(1, 0); for (int i = border; i < n; ++i) v.push_back(v.back() + b[i] + 1); int ans = 0; for (int i = 0; i <= 32; ++i) { if (res[i] > t) continue; auto it = upper_bound(v.begin(), v.end(), t - res[i]); int d = distance(v.begin(), it) - 1; chmax(ans, i + d); } cout << ans << endl; } signed main() { long long N; scanf("%lld", &N); long long T; scanf("%lld", &T); std::vector<long long> a(N); std::vector<long long> b(N); for (int i = 0; i < N; i++) { scanf("%lld", &a[i]); scanf("%lld", &b[i]); } solve(N, T, std::move(a), std::move(b)); return 0; }
insert
76
76
76
77
0
p02750
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long using namespace std; struct Data { ll a, b; bool operator<(const Data &other) const { if (a == other.a) return (b < other.b); return ((a * (other.b + 1)) > (other.a * (b + 1))); } }; int main() { // freopen("a.in", "r", stdin); ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; ll t; cin >> n >> t; vector<Data> v(n + 1, {0, 0}); for (int i = 1; i <= n; i++) cin >> v[i].a >> v[i].b; sort(v.begin() + 1, v.end()); int m = n; n = 1; while (n <= m && v[n].a != 0) n++; n--; int lim = (int)log2(t) + 5; vector<vector<ll>> dp(n + 1, vector<ll>(lim + 1, t + 5)); dp[0][0] = 0; for (int i = 1; i <= n; i++) { dp[i][0] = 0; for (int j = 1; j <= min(lim, i); j++) dp[i][j] = min(dp[i - 1][j], (dp[i - 1][j - 1] + 1) * (v[i].a + 1) + v[i].b); } int ans = 0; for (int i = 0; i <= lim; i++) { int j = n + 1; while (j <= m && dp[n][i] + 1 + v[j].b <= t) { dp[n][i] += (1 + v[j].b); j++; } if (dp[n][i] <= t) ans = max(ans, i + j - n - 1); } cout << ans; return 0; }
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long using namespace std; struct Data { ll a, b; bool operator<(const Data &other) const { if (a == other.a) return (b < other.b); return ((a * (other.b + 1)) > (other.a * (b + 1))); } }; int main() { // freopen("a.in", "r", stdin); ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; ll t; cin >> n >> t; vector<Data> v(n + 1, {0, 0}); for (int i = 1; i <= n; i++) cin >> v[i].a >> v[i].b; sort(v.begin() + 1, v.end()); int m = n; n = 1; while (n <= m && v[n].a != 0) n++; n--; int lim = 5; if (t > 0) lim = (int)log2(t) + 5; vector<vector<ll>> dp(n + 1, vector<ll>(lim + 1, t + 5)); dp[0][0] = 0; for (int i = 1; i <= n; i++) { dp[i][0] = 0; for (int j = 1; j <= min(lim, i); j++) dp[i][j] = min(dp[i - 1][j], (dp[i - 1][j - 1] + 1) * (v[i].a + 1) + v[i].b); } int ans = 0; for (int i = 0; i <= lim; i++) { int j = n + 1; while (j <= m && dp[n][i] + 1 + v[j].b <= t) { dp[n][i] += (1 + v[j].b); j++; } if (dp[n][i] <= t) ans = max(ans, i + j - n - 1); } cout << ans; return 0; }
replace
36
37
36
39
0
p02750
C++
Runtime Error
// Zory-2020 #include <bits/stdc++.h> using namespace std; typedef long long ll; // typedef __int128 ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define FR first #define SE second #define MP make_pair #define PB push_back #define vc vector #define db double #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define bin(x) (1ll << (x)) #define fo(i, l, r) for (int i = (l), I = (r); i <= I; i++) #define fd(i, r, l) for (int i = (r), I = (l); i >= I; i--) #define mem(x, val) memset(x, val, sizeof x) #define Swap(a, b, n) \ for (int I = 0; I <= n; I++) \ swap(a[I], b[I]) #define PC __builtin_popcountll #ifdef DEBUG #define debug(A, args...) fprintf(stderr, A, ##args) #else #define debug(A, args...) printf("") #endif #define deb debug("line %d\n", __LINE__) namespace mine { ll qread() { ll ans = 0, f = 1; char c = getchar(); while (c < '0' or c > '9') { if (c == '-') f = -1; c = getchar(); } while ('0' <= c and c <= '9') ans = ans * 10 + c - '0', c = getchar(); return ans * f; } void write(ll num) { if (num < 0) putchar('-'), num = -num; if (num >= 10) write(num / 10); putchar('0' + num % 10); } void write1(ll num) { write(num); putchar(' '); } void write2(ll num) { write(num); putchar('\n'); } template <typename T> inline bool chmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } template <typename T> inline bool chmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } bool IN(ll x, ll l, ll r) { return l <= x and x <= r; } void GG() { puts("-1"); exit(0); } const db eps = 1e-8; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; int mm(const int x) { return x >= MOD ? x - MOD : x; } template <typename T> void add(T &x, const int &y) { x = (x + y >= MOD ? x + y - MOD : x + y); } ll qpower(ll x, ll e, int mod = MOD) { ll ans = 1; while (e) { if (e & 1) ans = ans * x % mod; x = x * x % mod; e >>= 1; } return ans; } ll invm(ll x) { return qpower(x, MOD - 2); } const int M = 1e6 + 10; ll fac[M], facinv[M], Inv[M]; ll C(int n, int m) { return n < 0 or n < m ? 0 : fac[n] * facinv[m] % MOD * facinv[n - m] % MOD; } void PRE() { fac[0] = 1; fo(i, 1, M - 1) fac[i] = fac[i - 1] * i % MOD; facinv[M - 1] = invm(fac[M - 1]); fd(i, M - 1, 1) facinv[i - 1] = facinv[i] * i % MOD; Inv[1] = 1; fo(i, 2, M - 1) Inv[i] = (MOD - MOD / i) * Inv[MOD % i] % MOD; } const int N = 3e5 + 10; //------------------FIXED------------------ pll a[N]; int dp[N][50]; vc<ll> hh; void main() { int n = qread(), T = qread(), m = 0; fo(i, 1, n) { pll t; t.FR = qread() + 1, t.SE = qread() + 1; if (t.FR != 1) a[++m] = t; else hh.PB(t.SE); } hh.PB(0); sort(all(hh)); fo(i, 1, sz(hh) - 1) hh[i] += hh[i - 1]; sort(a + 1, a + m + 1, [&](pll a, pll b) { return b.SE * (a.FR - 1) <= a.SE * (b.FR - 1); }); mem(dp, 0x3f); dp[m + 1][0] = 1; fd(i, m, 1) fo(ct, 0, 38) { chmin(dp[i][ct], dp[i + 1][ct]); dp[i][ct + 1] = min(1ll * dp[i][ct + 1], 1ll * dp[i + 1][ct] * a[i].FR + a[i].SE); } int ans = 0; fo(ct, 0, 39) fo(i, 0, sz(hh) - 1) if (dp[1][ct] + hh[i] <= T + 1) chmax(ans, ct + i); write(ans); } }; // namespace mine signed main() { #ifdef DEBUG // freopen("a.in","r",stdin); freopen("z.txt", "r", stdin); // freopen("a.out","w",stdout); #endif srand(time(0)); mine::PRE(); // 线性预处理模意义 mine::main(); debug("\n---------------------Zory---------------------\nTime: %.2lf s", 1.0 * clock() / CLOCKS_PER_SEC); }
// Zory-2020 #include <bits/stdc++.h> using namespace std; typedef long long ll; // typedef __int128 ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define FR first #define SE second #define MP make_pair #define PB push_back #define vc vector #define db double #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define bin(x) (1ll << (x)) #define fo(i, l, r) for (int i = (l), I = (r); i <= I; i++) #define fd(i, r, l) for (int i = (r), I = (l); i >= I; i--) #define mem(x, val) memset(x, val, sizeof x) #define Swap(a, b, n) \ for (int I = 0; I <= n; I++) \ swap(a[I], b[I]) #define PC __builtin_popcountll #ifdef DEBUG #define debug(A, args...) fprintf(stderr, A, ##args) #else #define debug(A, args...) printf("") #endif #define deb debug("line %d\n", __LINE__) namespace mine { ll qread() { ll ans = 0, f = 1; char c = getchar(); while (c < '0' or c > '9') { if (c == '-') f = -1; c = getchar(); } while ('0' <= c and c <= '9') ans = ans * 10 + c - '0', c = getchar(); return ans * f; } void write(ll num) { if (num < 0) putchar('-'), num = -num; if (num >= 10) write(num / 10); putchar('0' + num % 10); } void write1(ll num) { write(num); putchar(' '); } void write2(ll num) { write(num); putchar('\n'); } template <typename T> inline bool chmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } template <typename T> inline bool chmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; } bool IN(ll x, ll l, ll r) { return l <= x and x <= r; } void GG() { puts("-1"); exit(0); } const db eps = 1e-8; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; int mm(const int x) { return x >= MOD ? x - MOD : x; } template <typename T> void add(T &x, const int &y) { x = (x + y >= MOD ? x + y - MOD : x + y); } ll qpower(ll x, ll e, int mod = MOD) { ll ans = 1; while (e) { if (e & 1) ans = ans * x % mod; x = x * x % mod; e >>= 1; } return ans; } ll invm(ll x) { return qpower(x, MOD - 2); } const int M = 1e6 + 10; ll fac[M], facinv[M], Inv[M]; ll C(int n, int m) { return n < 0 or n < m ? 0 : fac[n] * facinv[m] % MOD * facinv[n - m] % MOD; } void PRE() { fac[0] = 1; fo(i, 1, M - 1) fac[i] = fac[i - 1] * i % MOD; facinv[M - 1] = invm(fac[M - 1]); fd(i, M - 1, 1) facinv[i - 1] = facinv[i] * i % MOD; Inv[1] = 1; fo(i, 2, M - 1) Inv[i] = (MOD - MOD / i) * Inv[MOD % i] % MOD; } const int N = 3e5 + 10; //------------------FIXED------------------ pll a[N]; int dp[N][50]; vc<ll> hh; void main() { int n = qread(), T = qread(), m = 0; fo(i, 1, n) { pll t; t.FR = qread() + 1, t.SE = qread() + 1; if (t.FR != 1) a[++m] = t; else hh.PB(t.SE); } hh.PB(0); sort(all(hh)); fo(i, 1, sz(hh) - 1) hh[i] += hh[i - 1]; sort(a + 1, a + m + 1, [&](pll a, pll b) { return b.SE * (a.FR - 1) < a.SE * (b.FR - 1); }); mem(dp, 0x3f); dp[m + 1][0] = 1; fd(i, m, 1) fo(ct, 0, 38) { chmin(dp[i][ct], dp[i + 1][ct]); dp[i][ct + 1] = min(1ll * dp[i][ct + 1], 1ll * dp[i + 1][ct] * a[i].FR + a[i].SE); } int ans = 0; fo(ct, 0, 39) fo(i, 0, sz(hh) - 1) if (dp[1][ct] + hh[i] <= T + 1) chmax(ans, ct + i); write(ans); } }; // namespace mine signed main() { #ifdef DEBUG // freopen("a.in","r",stdin); freopen("z.txt", "r", stdin); // freopen("a.out","w",stdout); #endif srand(time(0)); mine::PRE(); // 线性预处理模意义 mine::main(); debug("\n---------------------Zory---------------------\nTime: %.2lf s", 1.0 * clock() / CLOCKS_PER_SEC); }
replace
121
122
121
122
0
p02750
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int maxi = 1e6 + 10; const long long inf = 1e9 + 10; int n; long long t; pair<long long, long long> a[maxi]; long long dp[41][maxi]; bool cmp(pair<long long, long long> x, pair<long long, long long> y) { // if (x.first == 0 && y.first == 0) return x.second < y.second; // if (x.first == 0) return 0; // if (y.first == 0) return 1; if (!x.first && y.first) return x.second < y.second; return y.first * (x.second + 1) < x.first * (y.second + 1); } int main() { cin >> n >> t; for (int i = 1; i <= n; i++) scanf("%lld%lld", &a[i].first, &a[i].second); sort(a + 1, a + n + 1, cmp); for (int i = 0; i <= 40; i++) for (int j = 0; j <= n; j++) dp[i][j] = inf; dp[0][0] = 0; int poz = n + 1; for (int i = 1; i <= n; i++) { if (!a[i].first) { poz = i; break; } for (int j = 0; j <= 40; j++) if (!j) dp[0][i] = 0; else { dp[j][i] = min(dp[j][i - 1], (dp[j - 1][i - 1] + 1) * (a[i].first + 1) + a[i].second); dp[j][i] = min(dp[j][i], inf); } } int ans = 0; for (int k = 0; k <= 40; k++) { if (dp[k][poz - 1] > t) continue; long long val = dp[k][poz - 1]; int cnt = k; for (int i = poz; i <= n; i++) if (val + a[i].second + 1 <= t) { val += a[i].second + 1; cnt++; } ans = max(cnt, ans); } printf("%d\n", ans); } // 1 3 // 0 3
#include <bits/stdc++.h> using namespace std; const int maxi = 1e6 + 10; const long long inf = 1e9 + 10; int n; long long t; pair<long long, long long> a[maxi]; long long dp[41][maxi]; bool cmp(pair<long long, long long> x, pair<long long, long long> y) { if (!x.first && !y.first) return x.second < y.second; return y.first * (x.second + 1) < x.first * (y.second + 1); } int main() { cin >> n >> t; for (int i = 1; i <= n; i++) scanf("%lld%lld", &a[i].first, &a[i].second); sort(a + 1, a + n + 1, cmp); for (int i = 0; i <= 40; i++) for (int j = 0; j <= n; j++) dp[i][j] = inf; dp[0][0] = 0; int poz = n + 1; for (int i = 1; i <= n; i++) { if (!a[i].first) { poz = i; break; } for (int j = 0; j <= 40; j++) if (!j) dp[0][i] = 0; else { dp[j][i] = min(dp[j][i - 1], (dp[j - 1][i - 1] + 1) * (a[i].first + 1) + a[i].second); dp[j][i] = min(dp[j][i], inf); } } int ans = 0; for (int k = 0; k <= 40; k++) { if (dp[k][poz - 1] > t) continue; long long val = dp[k][poz - 1]; int cnt = k; for (int i = poz; i <= n; i++) if (val + a[i].second + 1 <= t) { val += a[i].second + 1; cnt++; } ans = max(cnt, ans); } printf("%d\n", ans); } // 1 3 // 0 3
replace
12
16
12
13
-11
p02750
C++
Time Limit Exceeded
/* This code has been written by MinakoKojima, feel free to ask me question. Blog: http://www.shuizilong.com/house Template Date: 2015.10.12 Note: ... */ #pragma comment(linker, "/STACK:36777216") // #pragma GCC optimize ("O2") #define LOCAL #include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> // #include <tr1/unordered_set> // #include <tr1/unordered_map> // #include <array> 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 DWN(i, b, a) for (int i = b - 1; i >= a; --i) #define REP_1(i, n) for (int i = 1; i <= n; ++i) #define FOR_1(i, a, b) for (int i = a; i <= b; ++i) #define DWN_1(i, b, a) for (int i = b; i >= a; --i) #define REP_C(i, n) for (int n____ = n, i = 0; i < n____; ++i) #define FOR_C(i, a, b) for (int b____ = b, i = a; i < b____; ++i) #define DWN_C(i, b, a) for (int a____ = a, i = b - 1; i >= a____; --i) #define REP_N(i, n) for (i = 0; i < n; ++i) #define FOR_N(i, a, b) for (i = a; i < b; ++i) #define DWN_N(i, b, a) for (i = b - 1; i >= a; --i) #define REP_1_C(i, n) for (int n____ = n, i = 1; i <= n____; ++i) #define FOR_1_C(i, a, b) for (int b____ = b, i = a; i <= b____; ++i) #define DWN_1_C(i, b, a) for (int a____ = a, i = b; i >= a____; --i) #define REP_1_N(i, n) for (i = 1; i <= n; ++i) #define FOR_1_N(i, a, b) for (i = a; i <= b; ++i) #define DWN_1_N(i, b, a) for (i = b; i >= a; --i) #define REP_C_N(i, n) for (int n____ = (i = 0, n); i < n____; ++i) #define FOR_C_N(i, a, b) for (int b____ = (i = 0, b); i < b____; ++i) #define DWN_C_N(i, b, a) for (int a____ = (i = b - 1, a); i >= a____; --i) #define REP_1_C_N(i, n) for (int n____ = (i = 1, n); i <= n____; ++i) #define FOR_1_C_N(i, a, b) for (int b____ = (i = a, b); i <= b____; ++i) #define DWN_1_C_N(i, b, a) for (int a____ = (i = b, a); i >= a____; --i) #define ECH(it, A) \ for (__typeof((A).begin()) it = (A).begin(); it != (A).end(); ++it) #define rECH(it, A) \ for (__typeof((A).rbegin()) it = (A).rbegin(); it != (A).rend(); ++it) #define REP_S(i, str) for (char *i = str; *i; ++i) #define REP_L(i, hd, suc) for (int i = hd; i; i = suc[i]) #define REP_G(i, u) REP_L(i, hd[u], suc) #define REP_SS(x, s) for (int x = s; x; x = (x - 1) & s) #define DO(n) for (int ____n = n; ____n-- > 0;) #define REP_2(i, j, n, m) REP(i, n) REP(j, m) #define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m) #define REP_3(i, j, k, n, m, l) REP(i, n) REP(j, m) REP(k, l) #define REP_3_1(i, j, k, n, m, l) REP_1(i, n) REP_1(j, m) REP_1(k, l) #define REP_4(i, j, k, ii, n, m, l, nn) \ REP(i, n) REP(j, m) REP(k, l) REP(ii, nn) #define REP_4_1(i, j, k, ii, n, m, l, nn) \ REP_1(i, n) REP_1(j, m) REP_1(k, l) REP_1(ii, nn) #define ALL(A) A.begin(), A.end() #define LLA(A) A.rbegin(), A.rend() #define CPY(A, B) memcpy(A, B, sizeof(A)) #define INS(A, P, B) A.insert(A.begin() + P, B) #define ERS(A, P) A.erase(A.begin() + P) #define LBD(A, x) (lower_bound(ALL(A), x) - A.begin()) #define UBD(A, x) (upper_bound(ALL(A), x) - A.begin()) #define CTN(T, x) (T.find(x) != T.end()) #define SZ(A) int((A).size()) #define PB push_back #define MP(A, B) make_pair(A, B) #define PTT pair<T, T> #define Ts *this #define rTs return Ts #define fi first #define se second #define re real() #define im imag() #define Rush for (int ____T = RD(); ____T--;) #define Display(A, n, m) \ { \ REP(i, n) { \ REP(j, m - 1) cout << A[i][j] << " "; \ cout << A[i][m - 1] << endl; \ } \ } #define Display_1(A, n, m) \ { \ REP_1(i, n) { \ REP_1(j, m - 1) cout << A[i][j] << " "; \ cout << A[i][m] << endl; \ } \ } typedef long long LL; // typedef long double DB; typedef double DB; typedef unsigned uint; typedef unsigned long long uLL; typedef vector<int> VI; typedef vector<char> VC; typedef vector<string> VS; typedef vector<LL> VL; typedef vector<DB> VF; typedef set<int> SI; typedef set<string> SS; typedef map<int, int> MII; typedef map<string, int> MSI; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef vector<PII> VII; typedef vector<VI> VVI; typedef vector<VII> VVII; template <class T> inline T &RD(T &); template <class T> inline void OT(const T &); // inline int RD(){int x; return RD(x);} inline LL RD() { LL x; return RD(x); } inline DB &RF(DB &); inline DB RF() { DB x; return RF(x); } inline char *RS(char *s); inline char &RC(char &c); inline char RC(); inline char &RC(char &c) { scanf(" %c", &c); return c; } inline char RC() { char c; return RC(c); } // inline char& RC(char &c){c = getchar(); return c;} // inline char RC(){return getchar();} template <class T> inline T &RDD(T &); inline LL RDD() { LL x; return RDD(x); } template <class T0, class T1> inline T0 &RD(T0 &x0, T1 &x1) { RD(x0), RD(x1); return x0; } template <class T0, class T1, class T2> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2) { RD(x0), RD(x1), RD(x2); return x0; } template <class T0, class T1, class T2, class T3> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3) { RD(x0), RD(x1), RD(x2), RD(x3); return x0; } template <class T0, class T1, class T2, class T3, class T4> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4) { RD(x0), RD(x1), RD(x2), RD(x3), RD(x4); return x0; } template <class T0, class T1, class T2, class T3, class T4, class T5> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5) { RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5); return x0; } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6) { RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6); return x0; } template <class T0, class T1> inline void OT(const T0 &x0, const T1 &x1) { OT(x0), OT(x1); } template <class T0, class T1, class T2> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2) { OT(x0), OT(x1), OT(x2); } template <class T0, class T1, class T2, class T3> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3) { OT(x0), OT(x1), OT(x2), OT(x3); } template <class T0, class T1, class T2, class T3, class T4> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4) { OT(x0), OT(x1), OT(x2), OT(x3), OT(x4); } template <class T0, class T1, class T2, class T3, class T4, class T5> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5) { OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5); } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5, const T6 &x6) { OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6); } inline char &RC(char &a, char &b) { RC(a), RC(b); return a; } inline char &RC(char &a, char &b, char &c) { RC(a), RC(b), RC(c); return a; } inline char &RC(char &a, char &b, char &c, char &d) { RC(a), RC(b), RC(c), RC(d); return a; } inline char &RC(char &a, char &b, char &c, char &d, char &e) { RC(a), RC(b), RC(c), RC(d), RC(e); return a; } inline char &RC(char &a, char &b, char &c, char &d, char &e, char &f) { RC(a), RC(b), RC(c), RC(d), RC(e), RC(f); return a; } inline char &RC(char &a, char &b, char &c, char &d, char &e, char &f, char &g) { RC(a), RC(b), RC(c), RC(d), RC(e), RC(f), RC(g); return a; } inline DB &RF(DB &a, DB &b) { RF(a), RF(b); return a; } inline DB &RF(DB &a, DB &b, DB &c) { RF(a), RF(b), RF(c); return a; } inline DB &RF(DB &a, DB &b, DB &c, DB &d) { RF(a), RF(b), RF(c), RF(d); return a; } inline DB &RF(DB &a, DB &b, DB &c, DB &d, DB &e) { RF(a), RF(b), RF(c), RF(d), RF(e); return a; } inline DB &RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f) { RF(a), RF(b), RF(c), RF(d), RF(e), RF(f); return a; } inline DB &RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f, DB &g) { RF(a), RF(b), RF(c), RF(d), RF(e), RF(f), RF(g); return a; } inline void RS(char *s1, char *s2) { RS(s1), RS(s2); } inline void RS(char *s1, char *s2, char *s3) { RS(s1), RS(s2), RS(s3); } template <class T0, class T1> inline T0 &RDD(T0 &a, T1 &b) { RDD(a), RDD(b); return a; } template <class T0, class T1, class T2> inline T1 &RDD(T0 &a, T1 &b, T2 &c) { RDD(a), RDD(b), RDD(c); return a; } template <class T> inline void RST(T &A) { memset(A, 0, sizeof(A)); } template <class T> inline void FLC(T &A, int x) { memset(A, x, sizeof(A)); } template <class T> inline void CLR(T &A) { A.clear(); } template <class T0, class T1> inline void RST(T0 &A0, T1 &A1) { RST(A0), RST(A1); } template <class T0, class T1, class T2> inline void RST(T0 &A0, T1 &A1, T2 &A2) { RST(A0), RST(A1), RST(A2); } template <class T0, class T1, class T2, class T3> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3) { RST(A0), RST(A1), RST(A2), RST(A3); } template <class T0, class T1, class T2, class T3, class T4> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4) { RST(A0), RST(A1), RST(A2), RST(A3), RST(A4); } template <class T0, class T1, class T2, class T3, class T4, class T5> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5) { RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5); } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6) { RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6); } template <class T0, class T1> inline void FLC(T0 &A0, T1 &A1, int x) { FLC(A0, x), FLC(A1, x); } template <class T0, class T1, class T2> inline void FLC(T0 &A0, T1 &A1, T2 &A2, int x) { FLC(A0, x), FLC(A1, x), FLC(A2, x); } template <class T0, class T1, class T2, class T3> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, int x) { FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x); } template <class T0, class T1, class T2, class T3, class T4> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, int x) { FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x); } template <class T0, class T1, class T2, class T3, class T4, class T5> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, int x) { FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x); } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6, int x) { FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x), FLC(A6, x); } template <class T> inline void CLR(priority_queue<T> &Q) { while (!Q.empty()) Q.pop(); } template <class T> inline void CLR(stack<T> &S) { while (!S.empty()) S.pop(); } template <class T> inline void CLR(queue<T> &Q) { while (!Q.empty()) Q.pop(); } template <class T0, class T1> inline void CLR(T0 &A0, T1 &A1) { CLR(A0), CLR(A1); } template <class T0, class T1, class T2> inline void CLR(T0 &A0, T1 &A1, T2 &A2) { CLR(A0), CLR(A1), CLR(A2); } template <class T0, class T1, class T2, class T3> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3) { CLR(A0), CLR(A1), CLR(A2), CLR(A3); } template <class T0, class T1, class T2, class T3, class T4> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4) { CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4); } template <class T0, class T1, class T2, class T3, class T4, class T5> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5) { CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5); } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6) { CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6); } template <class T> inline void CLR(T &A, int n) { REP(i, n) CLR(A[i]); } template <class T> inline bool EPT(T &a) { return a.empty(); } template <class T> inline T &SRT(T &A) { sort(ALL(A)); return A; } template <class T, class C> inline T &SRT(T &A, C cmp) { sort(ALL(A), cmp); return A; } template <class T> inline T &RVS(T &A) { reverse(ALL(A)); return A; } template <class T> inline T &UNQQ(T &A) { A.resize(unique(ALL(A)) - A.begin()); return A; } template <class T> inline T &UNQ(T &A) { SRT(A); return UNQQ(A); } template <class T, class C> inline T &UNQ(T &A, C cmp) { SRT(A, cmp); return UNQQ(A); } //} /** Constant List .. **/ //{ // const int MOD = int(1e9) + 7; const int MOD = 998244353; // int(1e9) + 1; const int INF = 0x3f3f3f3f; const LL INFF = 0x3f3f3f3f3f3f3f3fLL; const DB EPS = 1e-9; const DB OO = 1e20; const DB PI = acos(-1.0); // M_PI; const int dx[] = {-2, -2, -1, -1, 1, 1, 2, 2}; const int dy[] = {-1, 1, -2, 2, -2, 2, -1, 1}; //} /** Add On .. **/ //{ // <<= '0. Nichi Joo ., //{ template <class T> inline bool checkMin(T &a, const T b) { return b < a ? a = b, 1 : 0; } template <class T> inline bool checkMax(T &a, const T b) { return a < b ? a = b, 1 : 0; } template <class T, class C> inline bool checkUpd(T &a, const T b, C c) { return c(b, a) ? a = b, 1 : 0; } template <class T> inline T min(T a, T b, T c) { return min(min(a, b), c); } template <class T> inline T max(T a, T b, T c) { return max(max(a, b), c); } template <class T> inline T min(T a, T b, T c, T d) { return min(min(a, b), min(c, d)); } template <class T> inline T max(T a, T b, T c, T d) { return max(max(a, b), max(c, d)); } template <class T> inline T min(T a, T b, T c, T d, T e) { return min(min(min(a, b), min(c, d)), e); } template <class T> inline T max(T a, T b, T c, T d, T e) { return max(max(max(a, b), max(c, d)), e); } template <class T> inline T sqr(T a) { return a * a; } template <class T> inline T cub(T a) { return a * a * a; } template <class T> inline T ceil(T x, T y) { return (x + y - 1) / y; } template <class T> T abs(T x) { return x > 0 ? x : -x; } inline int sgn(DB x) { return x < -EPS ? -1 : x > EPS; } inline int sgn(DB x, DB y) { return sgn(x - y); } inline DB cos(DB a, DB b, DB c) { return (sqr(a) + sqr(b) - sqr(c)) / (2 * a * b); } inline DB cot(DB x) { return 1. / tan(x); }; inline DB sec(DB x) { return 1. / cos(x); }; inline DB csc(DB x) { return 1. / sin(x); }; //} // <<= '1. Bitwise Operation ., //{ namespace BO { inline bool _1(int x, int i) { return bool(x & 1 << i); } inline bool _1(LL x, int i) { return bool(x & 1LL << i); } inline LL _1(int i) { return 1LL << i; } inline LL _U(int i) { return _1(i) - 1; }; inline int reverse_bits(int x) { x = ((x >> 1) & 0x55555555) | ((x << 1) & 0xaaaaaaaa); x = ((x >> 2) & 0x33333333) | ((x << 2) & 0xcccccccc); x = ((x >> 4) & 0x0f0f0f0f) | ((x << 4) & 0xf0f0f0f0); x = ((x >> 8) & 0x00ff00ff) | ((x << 8) & 0xff00ff00); x = ((x >> 16) & 0x0000ffff) | ((x << 16) & 0xffff0000); return x; } inline LL reverse_bits(LL x) { x = ((x >> 1) & 0x5555555555555555LL) | ((x << 1) & 0xaaaaaaaaaaaaaaaaLL); x = ((x >> 2) & 0x3333333333333333LL) | ((x << 2) & 0xccccccccccccccccLL); x = ((x >> 4) & 0x0f0f0f0f0f0f0f0fLL) | ((x << 4) & 0xf0f0f0f0f0f0f0f0LL); x = ((x >> 8) & 0x00ff00ff00ff00ffLL) | ((x << 8) & 0xff00ff00ff00ff00LL); x = ((x >> 16) & 0x0000ffff0000ffffLL) | ((x << 16) & 0xffff0000ffff0000LL); x = ((x >> 32) & 0x00000000ffffffffLL) | ((x << 32) & 0xffffffff00000000LL); return x; } template <class T> inline bool odd(T x) { return x & 1; } template <class T> inline bool even(T x) { return !odd(x); } template <class T> inline T low_bit(T x) { return x & -x; } template <class T> inline T high_bit(T x) { T p = low_bit(x); while (p != x) x -= p, p = low_bit(x); return p; } template <class T> inline T cover_bit(T x) { T p = 1; while (p < x) p <<= 1; return p; } template <class T> inline int cover_idx(T x) { int p = 0; while (_1(p) < x) ++p; return p; } inline int clz(int x) { return __builtin_clz(x); } inline int clz(LL x) { return __builtin_clzll(x); } inline int ctz(int x) { return __builtin_ctz(x); } inline int ctz(LL x) { return __builtin_ctzll(x); } inline int lg2(int x) { return !x ? -1 : 31 - clz(x); } inline int lg2(LL x) { return !x ? -1 : 63 - clz(x); } inline int low_idx(int x) { return !x ? -1 : ctz(x); } inline int low_idx(LL x) { return !x ? -1 : ctz(x); } inline int high_idx(int x) { return lg2(x); } inline int high_idx(LL x) { return lg2(x); } inline int parity(int x) { return __builtin_parity(x); } inline int parity(LL x) { return __builtin_parityll(x); } inline int count_bits(int x) { return __builtin_popcount(x); } inline int count_bits(LL x) { return __builtin_popcountll(x); } } // namespace BO using namespace BO; //} // <<= '2. Number Theory .,//{ namespace NT { #define gcd __gcd inline LL lcm(LL a, LL b) { return a * b / gcd(a, b); } inline void INC(int &a, int b) { a += b; if (a >= MOD) a -= MOD; } inline int sum(int a, int b) { a += b; if (a >= MOD) a -= MOD; return a; } /* 模数两倍刚好超 int 时。 inline int sum(uint a, int b){a += b; a %= MOD;if (a < 0) a += MOD; return a;} inline void INC(int &a, int b){a = sum(a, b);} */ inline void DEC(int &a, int b) { a -= b; if (a < 0) a += MOD; } inline int dff(int a, int b) { a -= b; if (a < 0) a += MOD; return a; } inline void MUL(int &a, int b) { a = (LL)a * b % MOD; } // inline int pdt(int a, int b){return (LL)a * b % MOD;} inline int pdt(int x, int y) { int ret; __asm__ __volatile__("\tmull %%ebx\n\tdivl %%ecx\n" : "=d"(ret) : "a"(x), "b"(y), "c"(MOD)); return ret; } inline int gcd(int m, int n, int &x, int &y) { x = 1, y = 0; int xx = 0, yy = 1, q; while (1) { q = m / n, m %= n; if (!m) { x = xx, y = yy; return n; } DEC(x, pdt(q, xx)), DEC(y, pdt(q, yy)); q = n / m, n %= m; if (!n) return m; DEC(xx, pdt(q, x)), DEC(yy, pdt(q, y)); } } inline int sum(int a, int b, int c) { return sum(a, sum(b, c)); } inline int sum(int a, int b, int c, int d) { return sum(sum(a, b), sum(c, d)); } inline int pdt(int a, int b, int c) { return pdt(a, pdt(b, c)); } inline int pdt(int a, int b, int c, int d) { return pdt(pdt(a, b), pdt(c, d)); } inline int pow(int a, LL b) { int c(1); while (b) { if (b & 1) MUL(c, a); MUL(a, a), b >>= 1; } return c; } template <class T> inline T pow(T a, LL b) { T c(1); while (b) { if (b & 1) c *= a; a *= a, b >>= 1; } return c; } template <class T> inline T pow(T a, int b) { return pow(a, (LL)b); } inline int _I(int b) { int a = MOD, x1 = 0, x2 = 1, q; while (1) { q = a / b, a %= b; if (!a) return x2; DEC(x1, pdt(q, x2)); q = b / a, b %= a; if (!b) return x1; DEC(x2, pdt(q, x1)); } } inline void DIV(int &a, int b) { MUL(a, _I(b)); } inline int qtt(int a, int b) { return pdt(a, _I(b)); } struct Int { int val; operator int() const { return val; } Int(int _val = 0) : val(_val) { val %= MOD; if (val < 0) val += MOD; } Int(LL _val) : val(_val) { _val %= MOD; if (_val < 0) _val += MOD; val = _val; } Int &operator+=(const int &rhs) { INC(val, rhs); rTs; } Int operator+(const int &rhs) const { return sum(val, rhs); } Int &operator-=(const int &rhs) { DEC(val, rhs); rTs; } Int operator-(const int &rhs) const { return dff(val, rhs); } Int &operator*=(const int &rhs) { MUL(val, rhs); rTs; } Int operator*(const int &rhs) const { return pdt(val, rhs); } Int &operator/=(const int &rhs) { DIV(val, rhs); rTs; } Int operator/(const int &rhs) const { return qtt(val, rhs); } Int operator-() const { return MOD - *this; } }; } // namespace NT using namespace NT; //} //} /** I/O Accelerator Interface .. **/ //{ #define g (c = getchar()) #define d isdigit(g) #define p x = x * 10 + c - '0' #define n x = x * 10 + '0' - c #define pp l /= 10, p #define nn l /= 10, n template <class T> inline T &RD(T &x) { char c; while (!d) ; x = c - '0'; while (d) p; return x; } template <class T> inline T &RDD(T &x) { char c; while (g, c != '-' && !isdigit(c)) ; if (c == '-') { x = '0' - g; while (d) n; } else { x = c - '0'; while (d) p; } return x; } inline DB &RF(DB &x) { // scanf("%lf", &x); char c; while (g, c != '-' && c != '.' && !isdigit(c)) ; if (c == '-') if (g == '.') { x = 0; DB l = 1; while (d) nn; x *= l; } else { x = '0' - c; while (d) n; if (c == '.') { DB l = 1; while (d) nn; x *= l; } } else if (c == '.') { x = 0; DB l = 1; while (d) pp; x *= l; } else { x = c - '0'; while (d) p; if (c == '.') { DB l = 1; while (d) pp; x *= l; } } return x; } #undef nn #undef pp #undef n #undef p #undef d #undef g inline char *RS(char *s) { // gets(s); scanf("%s", s); return s; } LL last_ans; int Case; template <class T> inline void OT(const T &x) { // printf("Case #%d: ", ++Case); printf("%lld\n", x); // printf("%I64d\n", x); // printf("%.9f\n", x); // printf("%d\n", x); // cout << x << endl; // last_ans = x; } //}/* //.................................................................................................................................. //*/ const int N = int(2e5) + 9; vector<pair<LL, LL>> a; VI b; int LV = 30; LL dp[N]; int n, T; int fb(LL t) { int n = SZ(b); REP(i, n) { if ((t += b[i]) > T) return i; } return n; } int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif RD(n, T); ++T; DO(n) { LL x, y; RD(x, y); ++y; if (x) a.PB({x, y}); else b.PB(y); } // bi + (bi+1)*aj + bj < // bj + (bj+1)*ai + bi n = SZ(a); a.PB({1, 0}); SRT(a, [](const auto &x, const auto &y) { return (LL)x.se * y.fi < (LL)y.se * x.fi; }); FLC(dp, 0x3f); dp[0] = 1; REP_1(ai, n) { int x = a[ai].fi + 1, y = a[ai].se; DWN(i, LV, 0) if (dp[i] <= T) { checkMin(dp[i + 1], dp[i] * x + y); } } SRT(b); int z = 0; REP(i, LV) if (dp[i] <= T) { checkMax(z, i + fb(dp[i])); } cout << z << endl; }
/* This code has been written by MinakoKojima, feel free to ask me question. Blog: http://www.shuizilong.com/house Template Date: 2015.10.12 Note: ... */ #pragma comment(linker, "/STACK:36777216") // #pragma GCC optimize ("O2") #define LOCAL #include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> // #include <tr1/unordered_set> // #include <tr1/unordered_map> // #include <array> 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 DWN(i, b, a) for (int i = b - 1; i >= a; --i) #define REP_1(i, n) for (int i = 1; i <= n; ++i) #define FOR_1(i, a, b) for (int i = a; i <= b; ++i) #define DWN_1(i, b, a) for (int i = b; i >= a; --i) #define REP_C(i, n) for (int n____ = n, i = 0; i < n____; ++i) #define FOR_C(i, a, b) for (int b____ = b, i = a; i < b____; ++i) #define DWN_C(i, b, a) for (int a____ = a, i = b - 1; i >= a____; --i) #define REP_N(i, n) for (i = 0; i < n; ++i) #define FOR_N(i, a, b) for (i = a; i < b; ++i) #define DWN_N(i, b, a) for (i = b - 1; i >= a; --i) #define REP_1_C(i, n) for (int n____ = n, i = 1; i <= n____; ++i) #define FOR_1_C(i, a, b) for (int b____ = b, i = a; i <= b____; ++i) #define DWN_1_C(i, b, a) for (int a____ = a, i = b; i >= a____; --i) #define REP_1_N(i, n) for (i = 1; i <= n; ++i) #define FOR_1_N(i, a, b) for (i = a; i <= b; ++i) #define DWN_1_N(i, b, a) for (i = b; i >= a; --i) #define REP_C_N(i, n) for (int n____ = (i = 0, n); i < n____; ++i) #define FOR_C_N(i, a, b) for (int b____ = (i = 0, b); i < b____; ++i) #define DWN_C_N(i, b, a) for (int a____ = (i = b - 1, a); i >= a____; --i) #define REP_1_C_N(i, n) for (int n____ = (i = 1, n); i <= n____; ++i) #define FOR_1_C_N(i, a, b) for (int b____ = (i = a, b); i <= b____; ++i) #define DWN_1_C_N(i, b, a) for (int a____ = (i = b, a); i >= a____; --i) #define ECH(it, A) \ for (__typeof((A).begin()) it = (A).begin(); it != (A).end(); ++it) #define rECH(it, A) \ for (__typeof((A).rbegin()) it = (A).rbegin(); it != (A).rend(); ++it) #define REP_S(i, str) for (char *i = str; *i; ++i) #define REP_L(i, hd, suc) for (int i = hd; i; i = suc[i]) #define REP_G(i, u) REP_L(i, hd[u], suc) #define REP_SS(x, s) for (int x = s; x; x = (x - 1) & s) #define DO(n) for (int ____n = n; ____n-- > 0;) #define REP_2(i, j, n, m) REP(i, n) REP(j, m) #define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m) #define REP_3(i, j, k, n, m, l) REP(i, n) REP(j, m) REP(k, l) #define REP_3_1(i, j, k, n, m, l) REP_1(i, n) REP_1(j, m) REP_1(k, l) #define REP_4(i, j, k, ii, n, m, l, nn) \ REP(i, n) REP(j, m) REP(k, l) REP(ii, nn) #define REP_4_1(i, j, k, ii, n, m, l, nn) \ REP_1(i, n) REP_1(j, m) REP_1(k, l) REP_1(ii, nn) #define ALL(A) A.begin(), A.end() #define LLA(A) A.rbegin(), A.rend() #define CPY(A, B) memcpy(A, B, sizeof(A)) #define INS(A, P, B) A.insert(A.begin() + P, B) #define ERS(A, P) A.erase(A.begin() + P) #define LBD(A, x) (lower_bound(ALL(A), x) - A.begin()) #define UBD(A, x) (upper_bound(ALL(A), x) - A.begin()) #define CTN(T, x) (T.find(x) != T.end()) #define SZ(A) int((A).size()) #define PB push_back #define MP(A, B) make_pair(A, B) #define PTT pair<T, T> #define Ts *this #define rTs return Ts #define fi first #define se second #define re real() #define im imag() #define Rush for (int ____T = RD(); ____T--;) #define Display(A, n, m) \ { \ REP(i, n) { \ REP(j, m - 1) cout << A[i][j] << " "; \ cout << A[i][m - 1] << endl; \ } \ } #define Display_1(A, n, m) \ { \ REP_1(i, n) { \ REP_1(j, m - 1) cout << A[i][j] << " "; \ cout << A[i][m] << endl; \ } \ } typedef long long LL; // typedef long double DB; typedef double DB; typedef unsigned uint; typedef unsigned long long uLL; typedef vector<int> VI; typedef vector<char> VC; typedef vector<string> VS; typedef vector<LL> VL; typedef vector<DB> VF; typedef set<int> SI; typedef set<string> SS; typedef map<int, int> MII; typedef map<string, int> MSI; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef vector<PII> VII; typedef vector<VI> VVI; typedef vector<VII> VVII; template <class T> inline T &RD(T &); template <class T> inline void OT(const T &); // inline int RD(){int x; return RD(x);} inline LL RD() { LL x; return RD(x); } inline DB &RF(DB &); inline DB RF() { DB x; return RF(x); } inline char *RS(char *s); inline char &RC(char &c); inline char RC(); inline char &RC(char &c) { scanf(" %c", &c); return c; } inline char RC() { char c; return RC(c); } // inline char& RC(char &c){c = getchar(); return c;} // inline char RC(){return getchar();} template <class T> inline T &RDD(T &); inline LL RDD() { LL x; return RDD(x); } template <class T0, class T1> inline T0 &RD(T0 &x0, T1 &x1) { RD(x0), RD(x1); return x0; } template <class T0, class T1, class T2> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2) { RD(x0), RD(x1), RD(x2); return x0; } template <class T0, class T1, class T2, class T3> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3) { RD(x0), RD(x1), RD(x2), RD(x3); return x0; } template <class T0, class T1, class T2, class T3, class T4> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4) { RD(x0), RD(x1), RD(x2), RD(x3), RD(x4); return x0; } template <class T0, class T1, class T2, class T3, class T4, class T5> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5) { RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5); return x0; } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline T0 &RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6) { RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6); return x0; } template <class T0, class T1> inline void OT(const T0 &x0, const T1 &x1) { OT(x0), OT(x1); } template <class T0, class T1, class T2> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2) { OT(x0), OT(x1), OT(x2); } template <class T0, class T1, class T2, class T3> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3) { OT(x0), OT(x1), OT(x2), OT(x3); } template <class T0, class T1, class T2, class T3, class T4> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4) { OT(x0), OT(x1), OT(x2), OT(x3), OT(x4); } template <class T0, class T1, class T2, class T3, class T4, class T5> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5) { OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5); } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5, const T6 &x6) { OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6); } inline char &RC(char &a, char &b) { RC(a), RC(b); return a; } inline char &RC(char &a, char &b, char &c) { RC(a), RC(b), RC(c); return a; } inline char &RC(char &a, char &b, char &c, char &d) { RC(a), RC(b), RC(c), RC(d); return a; } inline char &RC(char &a, char &b, char &c, char &d, char &e) { RC(a), RC(b), RC(c), RC(d), RC(e); return a; } inline char &RC(char &a, char &b, char &c, char &d, char &e, char &f) { RC(a), RC(b), RC(c), RC(d), RC(e), RC(f); return a; } inline char &RC(char &a, char &b, char &c, char &d, char &e, char &f, char &g) { RC(a), RC(b), RC(c), RC(d), RC(e), RC(f), RC(g); return a; } inline DB &RF(DB &a, DB &b) { RF(a), RF(b); return a; } inline DB &RF(DB &a, DB &b, DB &c) { RF(a), RF(b), RF(c); return a; } inline DB &RF(DB &a, DB &b, DB &c, DB &d) { RF(a), RF(b), RF(c), RF(d); return a; } inline DB &RF(DB &a, DB &b, DB &c, DB &d, DB &e) { RF(a), RF(b), RF(c), RF(d), RF(e); return a; } inline DB &RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f) { RF(a), RF(b), RF(c), RF(d), RF(e), RF(f); return a; } inline DB &RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f, DB &g) { RF(a), RF(b), RF(c), RF(d), RF(e), RF(f), RF(g); return a; } inline void RS(char *s1, char *s2) { RS(s1), RS(s2); } inline void RS(char *s1, char *s2, char *s3) { RS(s1), RS(s2), RS(s3); } template <class T0, class T1> inline T0 &RDD(T0 &a, T1 &b) { RDD(a), RDD(b); return a; } template <class T0, class T1, class T2> inline T1 &RDD(T0 &a, T1 &b, T2 &c) { RDD(a), RDD(b), RDD(c); return a; } template <class T> inline void RST(T &A) { memset(A, 0, sizeof(A)); } template <class T> inline void FLC(T &A, int x) { memset(A, x, sizeof(A)); } template <class T> inline void CLR(T &A) { A.clear(); } template <class T0, class T1> inline void RST(T0 &A0, T1 &A1) { RST(A0), RST(A1); } template <class T0, class T1, class T2> inline void RST(T0 &A0, T1 &A1, T2 &A2) { RST(A0), RST(A1), RST(A2); } template <class T0, class T1, class T2, class T3> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3) { RST(A0), RST(A1), RST(A2), RST(A3); } template <class T0, class T1, class T2, class T3, class T4> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4) { RST(A0), RST(A1), RST(A2), RST(A3), RST(A4); } template <class T0, class T1, class T2, class T3, class T4, class T5> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5) { RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5); } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6) { RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6); } template <class T0, class T1> inline void FLC(T0 &A0, T1 &A1, int x) { FLC(A0, x), FLC(A1, x); } template <class T0, class T1, class T2> inline void FLC(T0 &A0, T1 &A1, T2 &A2, int x) { FLC(A0, x), FLC(A1, x), FLC(A2, x); } template <class T0, class T1, class T2, class T3> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, int x) { FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x); } template <class T0, class T1, class T2, class T3, class T4> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, int x) { FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x); } template <class T0, class T1, class T2, class T3, class T4, class T5> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, int x) { FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x); } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6, int x) { FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x), FLC(A6, x); } template <class T> inline void CLR(priority_queue<T> &Q) { while (!Q.empty()) Q.pop(); } template <class T> inline void CLR(stack<T> &S) { while (!S.empty()) S.pop(); } template <class T> inline void CLR(queue<T> &Q) { while (!Q.empty()) Q.pop(); } template <class T0, class T1> inline void CLR(T0 &A0, T1 &A1) { CLR(A0), CLR(A1); } template <class T0, class T1, class T2> inline void CLR(T0 &A0, T1 &A1, T2 &A2) { CLR(A0), CLR(A1), CLR(A2); } template <class T0, class T1, class T2, class T3> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3) { CLR(A0), CLR(A1), CLR(A2), CLR(A3); } template <class T0, class T1, class T2, class T3, class T4> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4) { CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4); } template <class T0, class T1, class T2, class T3, class T4, class T5> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5) { CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5); } template <class T0, class T1, class T2, class T3, class T4, class T5, class T6> inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6) { CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6); } template <class T> inline void CLR(T &A, int n) { REP(i, n) CLR(A[i]); } template <class T> inline bool EPT(T &a) { return a.empty(); } template <class T> inline T &SRT(T &A) { sort(ALL(A)); return A; } template <class T, class C> inline T &SRT(T &A, C cmp) { sort(ALL(A), cmp); return A; } template <class T> inline T &RVS(T &A) { reverse(ALL(A)); return A; } template <class T> inline T &UNQQ(T &A) { A.resize(unique(ALL(A)) - A.begin()); return A; } template <class T> inline T &UNQ(T &A) { SRT(A); return UNQQ(A); } template <class T, class C> inline T &UNQ(T &A, C cmp) { SRT(A, cmp); return UNQQ(A); } //} /** Constant List .. **/ //{ // const int MOD = int(1e9) + 7; const int MOD = 998244353; // int(1e9) + 1; const int INF = 0x3f3f3f3f; const LL INFF = 0x3f3f3f3f3f3f3f3fLL; const DB EPS = 1e-9; const DB OO = 1e20; const DB PI = acos(-1.0); // M_PI; const int dx[] = {-2, -2, -1, -1, 1, 1, 2, 2}; const int dy[] = {-1, 1, -2, 2, -2, 2, -1, 1}; //} /** Add On .. **/ //{ // <<= '0. Nichi Joo ., //{ template <class T> inline bool checkMin(T &a, const T b) { return b < a ? a = b, 1 : 0; } template <class T> inline bool checkMax(T &a, const T b) { return a < b ? a = b, 1 : 0; } template <class T, class C> inline bool checkUpd(T &a, const T b, C c) { return c(b, a) ? a = b, 1 : 0; } template <class T> inline T min(T a, T b, T c) { return min(min(a, b), c); } template <class T> inline T max(T a, T b, T c) { return max(max(a, b), c); } template <class T> inline T min(T a, T b, T c, T d) { return min(min(a, b), min(c, d)); } template <class T> inline T max(T a, T b, T c, T d) { return max(max(a, b), max(c, d)); } template <class T> inline T min(T a, T b, T c, T d, T e) { return min(min(min(a, b), min(c, d)), e); } template <class T> inline T max(T a, T b, T c, T d, T e) { return max(max(max(a, b), max(c, d)), e); } template <class T> inline T sqr(T a) { return a * a; } template <class T> inline T cub(T a) { return a * a * a; } template <class T> inline T ceil(T x, T y) { return (x + y - 1) / y; } template <class T> T abs(T x) { return x > 0 ? x : -x; } inline int sgn(DB x) { return x < -EPS ? -1 : x > EPS; } inline int sgn(DB x, DB y) { return sgn(x - y); } inline DB cos(DB a, DB b, DB c) { return (sqr(a) + sqr(b) - sqr(c)) / (2 * a * b); } inline DB cot(DB x) { return 1. / tan(x); }; inline DB sec(DB x) { return 1. / cos(x); }; inline DB csc(DB x) { return 1. / sin(x); }; //} // <<= '1. Bitwise Operation ., //{ namespace BO { inline bool _1(int x, int i) { return bool(x & 1 << i); } inline bool _1(LL x, int i) { return bool(x & 1LL << i); } inline LL _1(int i) { return 1LL << i; } inline LL _U(int i) { return _1(i) - 1; }; inline int reverse_bits(int x) { x = ((x >> 1) & 0x55555555) | ((x << 1) & 0xaaaaaaaa); x = ((x >> 2) & 0x33333333) | ((x << 2) & 0xcccccccc); x = ((x >> 4) & 0x0f0f0f0f) | ((x << 4) & 0xf0f0f0f0); x = ((x >> 8) & 0x00ff00ff) | ((x << 8) & 0xff00ff00); x = ((x >> 16) & 0x0000ffff) | ((x << 16) & 0xffff0000); return x; } inline LL reverse_bits(LL x) { x = ((x >> 1) & 0x5555555555555555LL) | ((x << 1) & 0xaaaaaaaaaaaaaaaaLL); x = ((x >> 2) & 0x3333333333333333LL) | ((x << 2) & 0xccccccccccccccccLL); x = ((x >> 4) & 0x0f0f0f0f0f0f0f0fLL) | ((x << 4) & 0xf0f0f0f0f0f0f0f0LL); x = ((x >> 8) & 0x00ff00ff00ff00ffLL) | ((x << 8) & 0xff00ff00ff00ff00LL); x = ((x >> 16) & 0x0000ffff0000ffffLL) | ((x << 16) & 0xffff0000ffff0000LL); x = ((x >> 32) & 0x00000000ffffffffLL) | ((x << 32) & 0xffffffff00000000LL); return x; } template <class T> inline bool odd(T x) { return x & 1; } template <class T> inline bool even(T x) { return !odd(x); } template <class T> inline T low_bit(T x) { return x & -x; } template <class T> inline T high_bit(T x) { T p = low_bit(x); while (p != x) x -= p, p = low_bit(x); return p; } template <class T> inline T cover_bit(T x) { T p = 1; while (p < x) p <<= 1; return p; } template <class T> inline int cover_idx(T x) { int p = 0; while (_1(p) < x) ++p; return p; } inline int clz(int x) { return __builtin_clz(x); } inline int clz(LL x) { return __builtin_clzll(x); } inline int ctz(int x) { return __builtin_ctz(x); } inline int ctz(LL x) { return __builtin_ctzll(x); } inline int lg2(int x) { return !x ? -1 : 31 - clz(x); } inline int lg2(LL x) { return !x ? -1 : 63 - clz(x); } inline int low_idx(int x) { return !x ? -1 : ctz(x); } inline int low_idx(LL x) { return !x ? -1 : ctz(x); } inline int high_idx(int x) { return lg2(x); } inline int high_idx(LL x) { return lg2(x); } inline int parity(int x) { return __builtin_parity(x); } inline int parity(LL x) { return __builtin_parityll(x); } inline int count_bits(int x) { return __builtin_popcount(x); } inline int count_bits(LL x) { return __builtin_popcountll(x); } } // namespace BO using namespace BO; //} // <<= '2. Number Theory .,//{ namespace NT { #define gcd __gcd inline LL lcm(LL a, LL b) { return a * b / gcd(a, b); } inline void INC(int &a, int b) { a += b; if (a >= MOD) a -= MOD; } inline int sum(int a, int b) { a += b; if (a >= MOD) a -= MOD; return a; } /* 模数两倍刚好超 int 时。 inline int sum(uint a, int b){a += b; a %= MOD;if (a < 0) a += MOD; return a;} inline void INC(int &a, int b){a = sum(a, b);} */ inline void DEC(int &a, int b) { a -= b; if (a < 0) a += MOD; } inline int dff(int a, int b) { a -= b; if (a < 0) a += MOD; return a; } inline void MUL(int &a, int b) { a = (LL)a * b % MOD; } // inline int pdt(int a, int b){return (LL)a * b % MOD;} inline int pdt(int x, int y) { int ret; __asm__ __volatile__("\tmull %%ebx\n\tdivl %%ecx\n" : "=d"(ret) : "a"(x), "b"(y), "c"(MOD)); return ret; } inline int gcd(int m, int n, int &x, int &y) { x = 1, y = 0; int xx = 0, yy = 1, q; while (1) { q = m / n, m %= n; if (!m) { x = xx, y = yy; return n; } DEC(x, pdt(q, xx)), DEC(y, pdt(q, yy)); q = n / m, n %= m; if (!n) return m; DEC(xx, pdt(q, x)), DEC(yy, pdt(q, y)); } } inline int sum(int a, int b, int c) { return sum(a, sum(b, c)); } inline int sum(int a, int b, int c, int d) { return sum(sum(a, b), sum(c, d)); } inline int pdt(int a, int b, int c) { return pdt(a, pdt(b, c)); } inline int pdt(int a, int b, int c, int d) { return pdt(pdt(a, b), pdt(c, d)); } inline int pow(int a, LL b) { int c(1); while (b) { if (b & 1) MUL(c, a); MUL(a, a), b >>= 1; } return c; } template <class T> inline T pow(T a, LL b) { T c(1); while (b) { if (b & 1) c *= a; a *= a, b >>= 1; } return c; } template <class T> inline T pow(T a, int b) { return pow(a, (LL)b); } inline int _I(int b) { int a = MOD, x1 = 0, x2 = 1, q; while (1) { q = a / b, a %= b; if (!a) return x2; DEC(x1, pdt(q, x2)); q = b / a, b %= a; if (!b) return x1; DEC(x2, pdt(q, x1)); } } inline void DIV(int &a, int b) { MUL(a, _I(b)); } inline int qtt(int a, int b) { return pdt(a, _I(b)); } struct Int { int val; operator int() const { return val; } Int(int _val = 0) : val(_val) { val %= MOD; if (val < 0) val += MOD; } Int(LL _val) : val(_val) { _val %= MOD; if (_val < 0) _val += MOD; val = _val; } Int &operator+=(const int &rhs) { INC(val, rhs); rTs; } Int operator+(const int &rhs) const { return sum(val, rhs); } Int &operator-=(const int &rhs) { DEC(val, rhs); rTs; } Int operator-(const int &rhs) const { return dff(val, rhs); } Int &operator*=(const int &rhs) { MUL(val, rhs); rTs; } Int operator*(const int &rhs) const { return pdt(val, rhs); } Int &operator/=(const int &rhs) { DIV(val, rhs); rTs; } Int operator/(const int &rhs) const { return qtt(val, rhs); } Int operator-() const { return MOD - *this; } }; } // namespace NT using namespace NT; //} //} /** I/O Accelerator Interface .. **/ //{ #define g (c = getchar()) #define d isdigit(g) #define p x = x * 10 + c - '0' #define n x = x * 10 + '0' - c #define pp l /= 10, p #define nn l /= 10, n template <class T> inline T &RD(T &x) { char c; while (!d) ; x = c - '0'; while (d) p; return x; } template <class T> inline T &RDD(T &x) { char c; while (g, c != '-' && !isdigit(c)) ; if (c == '-') { x = '0' - g; while (d) n; } else { x = c - '0'; while (d) p; } return x; } inline DB &RF(DB &x) { // scanf("%lf", &x); char c; while (g, c != '-' && c != '.' && !isdigit(c)) ; if (c == '-') if (g == '.') { x = 0; DB l = 1; while (d) nn; x *= l; } else { x = '0' - c; while (d) n; if (c == '.') { DB l = 1; while (d) nn; x *= l; } } else if (c == '.') { x = 0; DB l = 1; while (d) pp; x *= l; } else { x = c - '0'; while (d) p; if (c == '.') { DB l = 1; while (d) pp; x *= l; } } return x; } #undef nn #undef pp #undef n #undef p #undef d #undef g inline char *RS(char *s) { // gets(s); scanf("%s", s); return s; } LL last_ans; int Case; template <class T> inline void OT(const T &x) { // printf("Case #%d: ", ++Case); printf("%lld\n", x); // printf("%I64d\n", x); // printf("%.9f\n", x); // printf("%d\n", x); // cout << x << endl; // last_ans = x; } //}/* //.................................................................................................................................. //*/ const int N = int(2e5) + 9; vector<pair<LL, LL>> a; VI b; int LV = 30; LL dp[N]; int n, T; int fb(LL t) { int n = SZ(b); REP(i, n) { if ((t += b[i]) > T) return i; } return n; } int main() { #ifndef ONLINE_JUDGE // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif RD(n, T); ++T; DO(n) { LL x, y; RD(x, y); ++y; if (x) a.PB({x, y}); else b.PB(y); } // bi + (bi+1)*aj + bj < // bj + (bj+1)*ai + bi n = SZ(a); a.PB({1, 0}); SRT(a, [](const auto &x, const auto &y) { return (LL)x.se * y.fi < (LL)y.se * x.fi; }); FLC(dp, 0x3f); dp[0] = 1; REP_1(ai, n) { int x = a[ai].fi + 1, y = a[ai].se; DWN(i, LV, 0) if (dp[i] <= T) { checkMin(dp[i + 1], dp[i] * x + y); } } SRT(b); int z = 0; REP(i, LV) if (dp[i] <= T) { checkMax(z, i + fb(dp[i])); } cout << z << endl; }
replace
794
795
794
795
TLE
p02750
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define pb push_back #define int long long #define F first #define S second typedef pair<int, int> P; const int N = 30 + 5, INF = 0x3f3f3f3f; inline int read() { int x = 0, f = 0; char ch = 0; while (!isdigit(ch)) f |= ch == '-', ch = getchar(); while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar(); return f ? -x : x; } bool cmp(P a, P b) { return b.F * (a.S + 1) < a.F * (b.S + 1); } vector<P> a; vector<int> b; int f[N]; signed main() { int n = read(), T = read(); for (int i = 1; i <= n; i++) { int x = read(), y = read(); if (x) a.pb(make_pair(x, y)); else b.pb(y + 1); } sort(a.begin(), a.end(), cmp); sort(b.begin(), b.end()); for (int i = 1; i < b.size(); i++) b[i] += b[i - 1]; for (int i = 1; i <= 30; i++) f[i] = T + 1; for (int i = 0; i < a.size(); i++) for (int j = 30; j; j--) f[j] = min(f[j], (f[j - 1] + 1) * (a[i].F + 1) + a[i].S); int ans = 0; for (int i = 0; i <= 30; i++) if (f[i] <= T) ans = max(ans, i + (b.empty() ? 0 : *(upper_bound(b.begin(), b.end(), T - f[i]) - *b.begin()))); printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define int long long #define F first #define S second typedef pair<int, int> P; const int N = 30 + 5, INF = 0x3f3f3f3f; inline int read() { int x = 0, f = 0; char ch = 0; while (!isdigit(ch)) f |= ch == '-', ch = getchar(); while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar(); return f ? -x : x; } bool cmp(P a, P b) { return b.F * (a.S + 1) < a.F * (b.S + 1); } vector<P> a; vector<int> b; int f[N]; signed main() { int n = read(), T = read(); for (int i = 1; i <= n; i++) { int x = read(), y = read(); if (x) a.pb(make_pair(x, y)); else b.pb(y + 1); } sort(a.begin(), a.end(), cmp); sort(b.begin(), b.end()); for (int i = 1; i < b.size(); i++) b[i] += b[i - 1]; for (int i = 1; i <= 30; i++) f[i] = T + 1; for (int i = 0; i < a.size(); i++) for (int j = 30; j; j--) f[j] = min(f[j], (f[j - 1] + 1) * (a[i].F + 1) + a[i].S); int ans = 0; for (int i = 0; i <= 30; i++) if (f[i] <= T) ans = max(ans, i + (b.empty() ? 0 : upper_bound(b.begin(), b.end(), T - f[i]) - b.begin())); printf("%lld\n", ans); return 0; }
replace
42
47
42
46
0
p02750
Python
Time Limit Exceeded
def main(): # input N, T = map(int, input().split()) a, b = [], [] a0_b = [] for i in range(N): a_in, b_in = map(int, input().split()) if a_in == 0: a0_b.append(b_in) else: a.append(a_in) b.append(b_in) L = len(a) # sort ab_ratio = [a[i] / (b[i] + 1) for i in range(L)] key = sorted(range(L), key=lambda x: -ab_ratio[x]) a = [a[i] for i in key] b = [b[i] for i in key] a0_b.sort() # --- case a >= 1 --- # # dp[for i shops][passed j shops] := min time # j:29 for T < 10^9 J_MAX = min(L + 1, 29) dp = [[float("inf") for _ in range(J_MAX)] for _ in range(L + 1)] dp[0][0] = 0 for i in range(L): for j in range(J_MAX): if j > 0: dt = 1 + a[i] * (dp[i][j - 1] + 1) + b[i] if dp[i][j - 1] + dt <= T: dp[i + 1][j] = min(dp[i][j], dp[i][j - 1] + dt) else: dp[i + 1][j] = dp[i][j] else: dp[i + 1][j] = dp[i][j] # --- case a = 0 --- # ans = 0 for i in range(J_MAX): if dp[L][i] == float("inf"): break else: time_cnt = dp[L][i] shop_cnt = i for t_b in a0_b: if time_cnt + 1 + t_b <= T: time_cnt += 1 + t_b shop_cnt += 1 if ans < shop_cnt: ans = shop_cnt print(ans) if __name__ == "__main__": main()
import sys input = sys.stdin.readline def main(): # input N, T = map(int, input().split()) a, b = [], [] a0_b = [] for i in range(N): a_in, b_in = map(int, input().split()) if a_in == 0: a0_b.append(b_in) else: a.append(a_in) b.append(b_in) L = len(a) # sort ab_ratio = [a[i] / (b[i] + 1) for i in range(L)] key = sorted(range(L), key=lambda x: -ab_ratio[x]) a = [a[i] for i in key] b = [b[i] for i in key] a0_b.sort() # --- case a >= 1 --- # # dp[for i shops][passed j shops] := min time # j:29 for T < 10^9 J_MAX = min(L + 1, 29) dp = [[float("inf") for _ in range(J_MAX)] for _ in range(L + 1)] dp[0][0] = 0 for i in range(L): for j in range(J_MAX): if j > 0: dt = 1 + a[i] * (dp[i][j - 1] + 1) + b[i] if dp[i][j - 1] + dt <= T: dp[i + 1][j] = min(dp[i][j], dp[i][j - 1] + dt) else: dp[i + 1][j] = dp[i][j] else: dp[i + 1][j] = dp[i][j] # --- case a = 0 --- # ans = 0 for i in range(J_MAX): if dp[L][i] == float("inf"): break else: time_cnt = dp[L][i] shop_cnt = i for t_b in a0_b: if time_cnt + 1 + t_b <= T: time_cnt += 1 + t_b shop_cnt += 1 if ans < shop_cnt: ans = shop_cnt print(ans) if __name__ == "__main__": main()
insert
0
0
0
5
TLE
p02750
C++
Runtime Error
// #include <bits/stdc++.h> #include "bits/stdc++.h" using namespace std; typedef long long ll; // #include "boost/multiprecision/cpp_int.hpp" // typedef boost::multiprecision::cpp_int LL; typedef long double dd; #define i_7 (ll)(1E9 + 7) // #define i_7 998244353 #define i_5 i_7 - 2 ll mod(ll a) { ll c = a % i_7; if (c >= 0) return c; return c + i_7; } typedef pair<ll, ll> l_l; typedef pair<dd, dd> d_d; ll inf = (ll)1E16; #define rep(i, l, r) for (ll i = l; i <= r; i++) #define pb push_back ll max(ll a, ll b) { if (a < b) return b; else return a; } ll min(ll a, ll b) { if (a > b) return b; else return a; } void Max(ll &pos, ll val) { pos = max(pos, val); } // Max(dp[n],dp[n-1]); void Min(ll &pos, ll val) { pos = min(pos, val); } void Add(ll &pos, ll val) { pos = mod(pos + val); } dd EPS = 1E-9; #define fastio \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define fi first #define se second #define endl "\n" #define SORT(v) sort(v.begin(), v.end()) #define ERASE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define POSL(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin()) #define POSU(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin()) template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } void mod_print(ll k) { ll P = 1000; rep(y, 1, P) { ll x = mod(y * k); if (x + P >= i_7) { x -= i_7; } if (abs(x) <= P) { cout << x << "/" << y << endl; return; } } cout << "nun" << endl; } ////////////////////////// struct shop { ll a, b; dd cmp; }; bool comp(shop x, shop y) { // return x.a*(y.b+1)>=y.a*(x.b+1); return x.cmp >= y.cmp; } int main() { fastio ll n, t; cin >> n >> t; vector<shop> v; vector<ll> last; rep(i, 0, n - 1) { shop s; cin >> s.a >> s.b; s.cmp = (dd)s.a / (dd)(s.b + 1); if (s.a == 0) { last.pb(s.b); } else { v.pb(s); } } sort(v.begin(), v.end(), comp); // for(auto x:v)cout<<x.a<<" "<<x.b<<endl; ll M = 32; ll vs = v.size(); ll dp[2][M]; rep(i, 0, 1) rep(j, 0, M - 1) dp[i][j] = inf; dp[0][0] = 0; rep(i, 0, vs - 1) { rep(j, 0, M - 1) dp[(i + 1) & 1][j] = inf; shop s = v[i]; rep(j, 0, M - 1) { if (dp[i & 1][j] == inf) continue; chmin(dp[(i + 1) & 1][j], dp[i & 1][j]); ll nxt = (dp[i & 1][j] + 1) * (s.a + 1) + s.b; if (nxt <= t && j + 1 <= M - 1) chmin(dp[(i + 1) & 1][j + 1], nxt); } // rep(j,0,M-1)cout<<dp[(i+1)&1][j]<<" ";cout<<endl; } ll ans = 0; SORT(last); ll sz = last.size(); vector<ll> a(sz + 1); a[0] = 0; rep(i, 0, sz - 1) { a[i + 1] = a[i] + (last[i] + 1); } rep(j, 0, M - 1) { ll res = t - dp[vs & 1][j]; if (res < 0) continue; ll p = POSU(a, res) - 1; chmax(ans, p + j); } cout << ans << endl; return 0; }
// #include <bits/stdc++.h> #include "bits/stdc++.h" using namespace std; typedef long long ll; // #include "boost/multiprecision/cpp_int.hpp" // typedef boost::multiprecision::cpp_int LL; typedef long double dd; #define i_7 (ll)(1E9 + 7) // #define i_7 998244353 #define i_5 i_7 - 2 ll mod(ll a) { ll c = a % i_7; if (c >= 0) return c; return c + i_7; } typedef pair<ll, ll> l_l; typedef pair<dd, dd> d_d; ll inf = (ll)1E16; #define rep(i, l, r) for (ll i = l; i <= r; i++) #define pb push_back ll max(ll a, ll b) { if (a < b) return b; else return a; } ll min(ll a, ll b) { if (a > b) return b; else return a; } void Max(ll &pos, ll val) { pos = max(pos, val); } // Max(dp[n],dp[n-1]); void Min(ll &pos, ll val) { pos = min(pos, val); } void Add(ll &pos, ll val) { pos = mod(pos + val); } dd EPS = 1E-9; #define fastio \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define fi first #define se second #define endl "\n" #define SORT(v) sort(v.begin(), v.end()) #define ERASE(v) v.erase(unique(v.begin(), v.end()), v.end()) #define POSL(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin()) #define POSU(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin()) template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } void mod_print(ll k) { ll P = 1000; rep(y, 1, P) { ll x = mod(y * k); if (x + P >= i_7) { x -= i_7; } if (abs(x) <= P) { cout << x << "/" << y << endl; return; } } cout << "nun" << endl; } ////////////////////////// struct shop { ll a, b; dd cmp; }; bool comp(shop x, shop y) { // return x.a*(y.b+1)>=y.a*(x.b+1); return x.cmp > y.cmp; } int main() { fastio ll n, t; cin >> n >> t; vector<shop> v; vector<ll> last; rep(i, 0, n - 1) { shop s; cin >> s.a >> s.b; s.cmp = (dd)s.a / (dd)(s.b + 1); if (s.a == 0) { last.pb(s.b); } else { v.pb(s); } } sort(v.begin(), v.end(), comp); // for(auto x:v)cout<<x.a<<" "<<x.b<<endl; ll M = 32; ll vs = v.size(); ll dp[2][M]; rep(i, 0, 1) rep(j, 0, M - 1) dp[i][j] = inf; dp[0][0] = 0; rep(i, 0, vs - 1) { rep(j, 0, M - 1) dp[(i + 1) & 1][j] = inf; shop s = v[i]; rep(j, 0, M - 1) { if (dp[i & 1][j] == inf) continue; chmin(dp[(i + 1) & 1][j], dp[i & 1][j]); ll nxt = (dp[i & 1][j] + 1) * (s.a + 1) + s.b; if (nxt <= t && j + 1 <= M - 1) chmin(dp[(i + 1) & 1][j + 1], nxt); } // rep(j,0,M-1)cout<<dp[(i+1)&1][j]<<" ";cout<<endl; } ll ans = 0; SORT(last); ll sz = last.size(); vector<ll> a(sz + 1); a[0] = 0; rep(i, 0, sz - 1) { a[i + 1] = a[i] + (last[i] + 1); } rep(j, 0, M - 1) { ll res = t - dp[vs & 1][j]; if (res < 0) continue; ll p = POSU(a, res) - 1; chmax(ans, p + j); } cout << ans << endl; return 0; }
replace
85
86
85
86
0
p02750
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define FOR(i, x, y) for (int i = (x); i < (y); ++i) #define REP(i, x, y) for (int i = (x); i <= (y); ++i) #define MP make_pair #define PB push_back #define PH push #define fst first #define snd second typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int, int> pii; const int INF = 1e9 + 7; const int maxn = 2e5 + 5; const int logn = 45; class Shop { public: int a, b; bool operator<(const Shop &oth) const { return 1ll * a * (oth.b + 1) > 1ll * oth.a / (b + 1); } } s[maxn]; int n, T, ans; int sum[maxn]; int dp[maxn][logn]; inline int go(int t, Shop cur) { ll ret = min(1ll * T + 1, t + 1 + 1ll * cur.a * (t + 1) + cur.b); return ret; } int main() { scanf("%d%d", &n, &T); FOR(i, 0, n) { scanf("%d%d", &s[i].a, &s[i].b); } sort(s, s + n); memset(dp, 0x3f, sizeof(dp)); dp[0][0] = 0; FOR(i, 0, n) { if (!s[i].a) { FOR(j, i, n) sum[j] = min(T + 1, (j == i ? 0 : sum[j - 1]) + 1 + s[j].b); FOR(j, 0, logn) if (dp[i][j] <= T) { int pos = upper_bound(sum + i, sum + n, T - dp[i][j]) - sum - i; ans = max(ans, j + pos); } break; } FOR(j, 0, logn) if (dp[i][j] <= T) { dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); if (go(dp[i][j], s[i]) <= T) dp[i + 1][j + 1] = min(dp[i + 1][j + 1], go(dp[i][j], s[i])); } } if (s[n - 1].a) { FOR(j, 0, logn) if (dp[n][j] <= T) ans = j; } printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, x, y) for (int i = (x); i < (y); ++i) #define REP(i, x, y) for (int i = (x); i <= (y); ++i) #define MP make_pair #define PB push_back #define PH push #define fst first #define snd second typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int, int> pii; const int INF = 1e9 + 7; const int maxn = 2e5 + 5; const int logn = 45; class Shop { public: int a, b; bool operator<(const Shop &oth) const { if (!a && !oth.a) return b < oth.b; return 1ll * a * (oth.b + 1) > 1ll * oth.a * (b + 1); } } s[maxn]; int n, T, ans; int sum[maxn]; int dp[maxn][logn]; inline int go(int t, Shop cur) { ll ret = min(1ll * T + 1, t + 1 + 1ll * cur.a * (t + 1) + cur.b); return ret; } int main() { scanf("%d%d", &n, &T); FOR(i, 0, n) { scanf("%d%d", &s[i].a, &s[i].b); } sort(s, s + n); memset(dp, 0x3f, sizeof(dp)); dp[0][0] = 0; FOR(i, 0, n) { if (!s[i].a) { FOR(j, i, n) sum[j] = min(T + 1, (j == i ? 0 : sum[j - 1]) + 1 + s[j].b); FOR(j, 0, logn) if (dp[i][j] <= T) { int pos = upper_bound(sum + i, sum + n, T - dp[i][j]) - sum - i; ans = max(ans, j + pos); } break; } FOR(j, 0, logn) if (dp[i][j] <= T) { dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]); if (go(dp[i][j], s[i]) <= T) dp[i + 1][j + 1] = min(dp[i + 1][j + 1], go(dp[i][j], s[i])); } } if (s[n - 1].a) { FOR(j, 0, logn) if (dp[n][j] <= T) ans = j; } printf("%d\n", ans); return 0; }
replace
25
26
25
28
0
p02751
C++
Runtime Error
// #pragma GCC optimize("Ofast") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2") #include <algorithm> #include <bitset> #include <cassert> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <string> #include <time.h> #include <unordered_map> #include <unordered_set> #include <vector> // #include <any> #define prev asasddlsa #define rank aljds #define rep(i, l, r) for (int i = l; i < r; i++) #define repb(i, r, l) for (int i = r; i >= l; i++) using namespace std; typedef long long ll; typedef double dbl; template <typename T> void print(const vector<T> &s) { for (auto x : s) cout << x << ""; cout << endl; } template <class T> void print(const T *s, int n) { for (int i = 0; i < n; i++) cout << s[i] << ""; cout << endl; } template <class T> void print(vector<vector<T>> s) { for (int i = 0; i < s.size(); i++) print(s[i]); } auto build(int n, int m, int t) { if (n == 0 || m == 0) return vector<vector<int>>(); auto kek = build(n - 1, m - 1, t ^ 1); // print(kek); int nn = (1 << (n - 1)) - 1, mm = (1 << (m - 1)) - 1; n = (1 << n) - 1, m = (1 << m) - 1; vector<vector<int>> s(n, vector<int>(m)); if (t) { for (int i = 0; i < n; i++) s[i][m / 2] = 1; for (int i = 0; i < m; i++) s[n / 2][i] = 1; } s[n / 2][m / 2] = 1; for (int x = 0; x < 2; x++) { for (int y = 0; y < 2; y++) { for (int i = 0; i < nn; i++) { for (int j = 0; j < mm; j++) { s[x * (nn + 1) + i][y * (mm + 1) + j] = kek[i][j]; } } } } return s; } int solve() { int n, m; cin >> n >> m; assert(n < 5 && m < 5); auto res = build(n, m, 0); print(res); return 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.precision(10); cout << fixed; int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
// #pragma GCC optimize("Ofast") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2") #include <algorithm> #include <bitset> #include <cassert> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <string> #include <time.h> #include <unordered_map> #include <unordered_set> #include <vector> // #include <any> #define prev asasddlsa #define rank aljds #define rep(i, l, r) for (int i = l; i < r; i++) #define repb(i, r, l) for (int i = r; i >= l; i++) using namespace std; typedef long long ll; typedef double dbl; template <typename T> void print(const vector<T> &s) { for (auto x : s) cout << x << ""; cout << endl; } template <class T> void print(const T *s, int n) { for (int i = 0; i < n; i++) cout << s[i] << ""; cout << endl; } template <class T> void print(vector<vector<T>> s) { for (int i = 0; i < s.size(); i++) print(s[i]); } auto build(int n, int m, int t) { if (n == 0 || m == 0) return vector<vector<int>>(); auto kek = build(n - 1, m - 1, t ^ 1); // print(kek); int nn = (1 << (n - 1)) - 1, mm = (1 << (m - 1)) - 1; n = (1 << n) - 1, m = (1 << m) - 1; vector<vector<int>> s(n, vector<int>(m)); if (t) { for (int i = 0; i < n; i++) s[i][m / 2] = 1; for (int i = 0; i < m; i++) s[n / 2][i] = 1; } s[n / 2][m / 2] = 1; for (int x = 0; x < 2; x++) { for (int y = 0; y < 2; y++) { for (int i = 0; i < nn; i++) { for (int j = 0; j < mm; j++) { s[x * (nn + 1) + i][y * (mm + 1) + j] = kek[i][j]; } } } } return s; } int solve() { int n, m; cin >> n >> m; auto res = build(n, m, min(n, m) & 1); print(res); return 0; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.precision(10); cout << fixed; int t = 1; // cin >> t; while (t--) { solve(); } return 0; }
replace
79
81
79
80
0
p02751
C++
Runtime Error
#pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") #pragma GCC optimize("inline") #pragma GCC optimize("-fgcse") #pragma GCC optimize("-fgcse-lm") #pragma GCC optimize("-fipa-sra") #pragma GCC optimize("-ftree-pre") #pragma GCC optimize("-ftree-vrp") #pragma GCC optimize("-fpeephole2") #pragma GCC optimize("-ffast-math") #pragma GCC optimize("-fsched-spec") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("-falign-jumps") #pragma GCC optimize("-falign-loops") #pragma GCC optimize("-falign-labels") #pragma GCC optimize("-fdevirtualize") #pragma GCC optimize("-fcaller-saves") #pragma GCC optimize("-fcrossjumping") #pragma GCC optimize("-fthread-jumps") #pragma GCC optimize("-funroll-loops") #pragma GCC optimize("-fwhole-program") #pragma GCC optimize("-freorder-blocks") #pragma GCC optimize("-fschedule-insns") #pragma GCC optimize("inline-functions") #pragma GCC optimize("-ftree-tail-merge") #pragma GCC optimize("-fschedule-insns2") #pragma GCC optimize("-fstrict-aliasing") #pragma GCC optimize("-fstrict-overflow") #pragma GCC optimize("-falign-functions") #pragma GCC optimize("-fcse-skip-blocks") #pragma GCC optimize("-fcse-follow-jumps") #pragma GCC optimize("-fsched-interblock") #pragma GCC optimize("-fpartial-inlining") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("-freorder-functions") #pragma GCC optimize("-findirect-inlining") #pragma GCC optimize("-fhoist-adjacent-loads") #pragma GCC optimize("-frerun-cse-after-loop") #pragma GCC optimize("inline-small-functions") #pragma GCC optimize("-finline-small-functions") #pragma GCC optimize("-ftree-switch-conversion") #pragma GCC optimize("-foptimize-sibling-calls") #pragma GCC optimize("-fexpensive-optimizations") #pragma GCC optimize("-funsafe-loop-optimizations") #pragma GCC optimize("inline-functions-called-once") #pragma GCC optimize("-fdelete-null-pointer-checks") #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #define re register using namespace std; int n, m; int mp[2052][2052]; inline void work(re int x, re int y, re int X, re int Y) { if (x == X && y == Y) { mp[x][y] = 1; return; } mp[x + X >> 1][y + Y >> 1] = 1; int midx = x + X >> 1, midy = y + Y >> 1; work(x, y, midx - 1, midy - 1); work(midx + 1, y, X, midy - 1); work(x, midy + 1, midx - 1, Y); work(midx + 1, midy + 1, X, Y); } signed main() { int tmp = 0; scanf("%d%d", &n, &m); if (n < m) { for (re int i = 1; i <= (1 << m); i += (1 << n)) { work(1, i, (1 << n) - 1, i + (1 << n) - 2); } } else { for (re int i = 1; i <= (1 << n); i += (1 << m)) { work(i, 1, i + (1 << m) - 1, (1 << m) - 2); } } for (re int i = 1; i < (1 << n); ++i) { for (re int j = 1; j < (1 << m); ++j) printf("%d", mp[i][j]); putchar('\n'); } }
#pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize("Ofast") #pragma GCC optimize("inline") #pragma GCC optimize("-fgcse") #pragma GCC optimize("-fgcse-lm") #pragma GCC optimize("-fipa-sra") #pragma GCC optimize("-ftree-pre") #pragma GCC optimize("-ftree-vrp") #pragma GCC optimize("-fpeephole2") #pragma GCC optimize("-ffast-math") #pragma GCC optimize("-fsched-spec") #pragma GCC optimize("unroll-loops") #pragma GCC optimize("-falign-jumps") #pragma GCC optimize("-falign-loops") #pragma GCC optimize("-falign-labels") #pragma GCC optimize("-fdevirtualize") #pragma GCC optimize("-fcaller-saves") #pragma GCC optimize("-fcrossjumping") #pragma GCC optimize("-fthread-jumps") #pragma GCC optimize("-funroll-loops") #pragma GCC optimize("-fwhole-program") #pragma GCC optimize("-freorder-blocks") #pragma GCC optimize("-fschedule-insns") #pragma GCC optimize("inline-functions") #pragma GCC optimize("-ftree-tail-merge") #pragma GCC optimize("-fschedule-insns2") #pragma GCC optimize("-fstrict-aliasing") #pragma GCC optimize("-fstrict-overflow") #pragma GCC optimize("-falign-functions") #pragma GCC optimize("-fcse-skip-blocks") #pragma GCC optimize("-fcse-follow-jumps") #pragma GCC optimize("-fsched-interblock") #pragma GCC optimize("-fpartial-inlining") #pragma GCC optimize("no-stack-protector") #pragma GCC optimize("-freorder-functions") #pragma GCC optimize("-findirect-inlining") #pragma GCC optimize("-fhoist-adjacent-loads") #pragma GCC optimize("-frerun-cse-after-loop") #pragma GCC optimize("inline-small-functions") #pragma GCC optimize("-finline-small-functions") #pragma GCC optimize("-ftree-switch-conversion") #pragma GCC optimize("-foptimize-sibling-calls") #pragma GCC optimize("-fexpensive-optimizations") #pragma GCC optimize("-funsafe-loop-optimizations") #pragma GCC optimize("inline-functions-called-once") #pragma GCC optimize("-fdelete-null-pointer-checks") #include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #define re register using namespace std; int n, m; int mp[2052][2052]; inline void work(re int x, re int y, re int X, re int Y) { if (x == X && y == Y) { mp[x][y] = 1; return; } mp[x + X >> 1][y + Y >> 1] = 1; int midx = x + X >> 1, midy = y + Y >> 1; work(x, y, midx - 1, midy - 1); work(midx + 1, y, X, midy - 1); work(x, midy + 1, midx - 1, Y); work(midx + 1, midy + 1, X, Y); } signed main() { int tmp = 0; scanf("%d%d", &n, &m); if (n < m) { for (re int i = 1; i <= (1 << m); i += (1 << n)) { work(1, i, (1 << n) - 1, i + (1 << n) - 2); } } else { for (re int i = 1; i <= (1 << n); i += (1 << m)) { work(i, 1, i + (1 << m) - 2, (1 << m) - 1); } } for (re int i = 1; i < (1 << n); ++i) { for (re int j = 1; j < (1 << m); ++j) printf("%d", mp[i][j]); putchar('\n'); } }
replace
78
79
78
79
0
p02751
C++
Runtime Error
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #include <bits/stdc++.h> using namespace std; template <class t> inline t read(t &x) { char c = getchar(); bool f = 0; x = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); if (f) x = -x; return x; } template <class t, class... A> inline void read(t &x, A &...a) { read(x); read(a...); } template <class t> inline void write(t x) { if (x < 0) putchar('-'), write(-x); else { if (x > 9) write(x / 10); putchar('0' + x % 10); } } const int N = 2005; int n, m, ans[N][N]; void diq(int a, int b, int c, int d) { if (a == c || b == d) return; int x = a + b >> 1, y = c + d >> 1; ans[x][y] = 0; diq(a, b, x - 1, y - 1); diq(a, y + 1, x - 1, d); diq(x + 1, b, c, y - 1); diq(x + 1, y + 1, c, d); } signed main() { read(n, m); n = 1 << n; m = 1 << m; n--; m--; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) ans[i][j] = 1; diq(1, 1, n, m); for (int i = 1; i <= n; i++, puts("")) for (int j = 1; j <= m; j++) write(ans[i][j]); }
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #include <bits/stdc++.h> using namespace std; template <class t> inline t read(t &x) { char c = getchar(); bool f = 0; x = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); if (f) x = -x; return x; } template <class t, class... A> inline void read(t &x, A &...a) { read(x); read(a...); } template <class t> inline void write(t x) { if (x < 0) putchar('-'), write(-x); else { if (x > 9) write(x / 10); putchar('0' + x % 10); } } const int N = 2005; int n, m, ans[N][N]; void diq(int a, int b, int c, int d) { if (a == c || b == d) return; int x = a + c >> 1, y = b + d >> 1; ans[x][y] = 0; diq(a, b, x - 1, y - 1); diq(a, y + 1, x - 1, d); diq(x + 1, b, c, y - 1); diq(x + 1, y + 1, c, d); } signed main() { read(n, m); n = 1 << n; m = 1 << m; n--; m--; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) ans[i][j] = 1; diq(1, 1, n, m); for (int i = 1; i <= n; i++, puts("")) for (int j = 1; j <= m; j++) write(ans[i][j]); }
replace
35
36
35
36
0
p02751
C++
Runtime Error
// includes #include <bits/stdc++.h> using namespace std; // macros #define pb emplace_back #define mk make_pair #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr) #define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr) #define whole(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define bit(n) (1LL << (n)) // functions template <typename T> void unique(T &c) { c.erase(std::unique(c.begin(), c.end()), c.end()); } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (int i = 0; i < vec.size(); i++) { os << vec[i]; if (i + 1 != vec.size()) os << " "; } return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &st) { for (auto itr = st.begin(); itr != st.end(); ++itr) { os << *itr; auto titr = itr; if (++titr != st.end()) os << " "; } return os; } template <typename T> ostream &operator<<(ostream &os, const unordered_set<T> &st) { for (auto itr = st.begin(); itr != st.end(); ++itr) { os << *itr; auto titr = itr; if (++titr != st.end()) os << " "; } return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &st) { for (auto itr = st.begin(); itr != st.end(); ++itr) { os << *itr; auto titr = itr; if (++titr != st.end()) os << " "; } return os; } template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &st) { for (auto itr = st.begin(); itr != st.end(); ++itr) { os << *itr; auto titr = itr; if (++titr != st.end()) os << " "; } return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp) { for (auto itr = mp.begin(); itr != mp.end(); ++itr) { os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if (++titr != mp.end()) os << " "; } return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp) { for (auto itr = mp.begin(); itr != mp.end(); ++itr) { os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if (++titr != mp.end()) os << " "; } return os; } // types using ll = long long int; using P = pair<int, int>; // constants const int inf = 1e9; const ll linf = 1LL << 50; const double EPS = 1e-10; const int mod = 1000000007; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0, 1}; // io struct fast_io { fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20); } } fast_io_; int f[1025][1025]; int main(int argc, char const *argv[]) { int n, m; cin >> n >> m; int l = max(n, m); f[1][1] = 1; for (int i = 1; i <= l; i++) { for (int j = 0; j < (1 << i); j++) { for (int k = 0; k < (1 << i); k++) { f[j][k + (1 << i)] = f[j][k]; f[j + (1 << i)][k] = f[j][k]; f[j + (1 << i)][k + (1 << i)] = 1 - f[j][k]; } } } for (int i = (1 << l) - 1; i >= 0; i--) { for (int j = (1 << l) - 1; j > 0; j--) { f[i][j] -= f[i][j - 1]; } } for (int i = (1 << l) - 1; i > 0; i--) { for (int j = (1 << l) - 1; j >= 0; j--) { f[i][j] -= f[i - 1][j]; } } for (int i = 0; i < (1 << n) - 1; i++) { for (int j = 0; j < (1 << m) - 1; j++) { cout << (f[i + 1][j + 1] & 1); } cout << endl; } return 0; }
// includes #include <bits/stdc++.h> using namespace std; // macros #define pb emplace_back #define mk make_pair #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) FOR(i, 0, n) #define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr) #define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr) #define whole(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define bit(n) (1LL << (n)) // functions template <typename T> void unique(T &c) { c.erase(std::unique(c.begin(), c.end()), c.end()); } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (auto &v : vec) is >> v; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (int i = 0; i < vec.size(); i++) { os << vec[i]; if (i + 1 != vec.size()) os << " "; } return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &st) { for (auto itr = st.begin(); itr != st.end(); ++itr) { os << *itr; auto titr = itr; if (++titr != st.end()) os << " "; } return os; } template <typename T> ostream &operator<<(ostream &os, const unordered_set<T> &st) { for (auto itr = st.begin(); itr != st.end(); ++itr) { os << *itr; auto titr = itr; if (++titr != st.end()) os << " "; } return os; } template <typename T> ostream &operator<<(ostream &os, const multiset<T> &st) { for (auto itr = st.begin(); itr != st.end(); ++itr) { os << *itr; auto titr = itr; if (++titr != st.end()) os << " "; } return os; } template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &st) { for (auto itr = st.begin(); itr != st.end(); ++itr) { os << *itr; auto titr = itr; if (++titr != st.end()) os << " "; } return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp) { for (auto itr = mp.begin(); itr != mp.end(); ++itr) { os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if (++titr != mp.end()) os << " "; } return os; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp) { for (auto itr = mp.begin(); itr != mp.end(); ++itr) { os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if (++titr != mp.end()) os << " "; } return os; } // types using ll = long long int; using P = pair<int, int>; // constants const int inf = 1e9; const ll linf = 1LL << 50; const double EPS = 1e-10; const int mod = 1000000007; const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0, 1}; // io struct fast_io { fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20); } } fast_io_; int f[2065][2065]; int main(int argc, char const *argv[]) { int n, m; cin >> n >> m; int l = max(n, m); f[1][1] = 1; for (int i = 1; i <= l; i++) { for (int j = 0; j < (1 << i); j++) { for (int k = 0; k < (1 << i); k++) { f[j][k + (1 << i)] = f[j][k]; f[j + (1 << i)][k] = f[j][k]; f[j + (1 << i)][k + (1 << i)] = 1 - f[j][k]; } } } for (int i = (1 << l) - 1; i >= 0; i--) { for (int j = (1 << l) - 1; j > 0; j--) { f[i][j] -= f[i][j - 1]; } } for (int i = (1 << l) - 1; i > 0; i--) { for (int j = (1 << l) - 1; j >= 0; j--) { f[i][j] -= f[i - 1][j]; } } for (int i = 0; i < (1 << n) - 1; i++) { for (int j = 0; j < (1 << m) - 1; j++) { cout << (f[i + 1][j + 1] & 1); } cout << endl; } return 0; }
replace
128
129
128
129
0
p02752
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define MOD 998244353 template <typename ty1, typename ty2> inline int add(ty1 x, ty2 y) { if (y >= MOD) y %= MOD; if (x >= MOD) x %= MOD; x += y; return x < MOD ? x : x - MOD; } template <typename ty1, typename ty2> inline void addto(ty1 &x, ty2 y) { if (y >= MOD) y %= MOD; if (x >= MOD) x %= MOD; x += y; if (x >= MOD) x -= MOD; } template <typename ty1, typename ty2> inline int sub(ty1 x, ty2 y) { if (y >= MOD) y %= MOD; if (x >= MOD) x %= MOD; x -= y; return x < 0 ? x + MOD : x; } template <typename ty1, typename ty2> inline void subto(ty1 &x, ty2 y) { if (y >= MOD) y %= MOD; if (x >= MOD) x %= MOD; x -= y; if (x < 0) x += MOD; } template <typename ty1, typename ty2> inline int mul(ty1 x, ty2 y) { if (y >= MOD) y %= MOD; if (x >= MOD) x %= MOD; return 1ll * x * y % MOD; } template <typename ty1, typename ty2> void multo(ty1 &x, ty2 y) { if (y >= MOD) y %= MOD; if (x >= MOD) x %= MOD; x = 1ll * x * y % MOD; } long long int gcd(long long int a, long long int b) { if (a > b) { swap(a, b); } while (a) { swap(a, b); a %= b; } return b; } long long int lcm(long long int a, long long int b) { return a / gcd(a, b) * b; } long long int ppow(long long int i, long long int j) { long long int res = 1LL; while (j) { if ((j & 1LL)) { res *= i; if (res >= MOD) { res %= MOD; } } j >>= 1; i *= i; if (i >= MOD) { i %= MOD; } } return res; } class Combination { public: vector<long long int> k; vector<long long int> r; void resize(int N) { k.resize(N + 2); r.resize(N + 2); k[0] = 1; for (int i = 1; i < N + 2; i++) { k[i] = k[i - 1]; k[i] *= i; if (k[i] >= MOD) k[i] %= MOD; } long long int al = k[k.size() - 1]; long long int iv = ppow(k[k.size() - 1], MOD - 2); r[k.size() - 1] = iv; for (int i = (int)(r.size()) - 2; i >= 0; i--) { r[i] = r[i + 1] * (i + 1); if (r[i] >= MOD) { r[i] %= MOD; } } } long long int C(int a, int b) { if (a < b) return 0; long long int up = k[a]; long long int dw = r[b] * r[a - b]; dw %= MOD; up *= dw; up %= MOD; return up; } long long int H(int a, int b) { return C(a + b - 1, b); } long long int catalan_number(int n) { return (C(2 * n, n) + MOD - C(2 * n, n - 1)) % MOD; } }; Combination C; #define MAX 200002 int n; struct treediameter { // 直径は色々いい性質がある // 中心から(2頂点の場合それをくっつける)同じ距離のびた2つの頂点間が直径 // 直径は最大長であることにも注意 const vector<vector<int>> &g; int r1, r2; vector<int> d1, d2; // 両端からのdist int dia; void dfs(int v, int p, int cur, vector<int> &d) { d[v] = cur; for (auto e : g[v]) if (e != p) dfs(e, v, cur + 1, d); } treediameter(const vector<vector<int>> &gg) : g(gg), d1(g.size()), d2(g.size()) { dfs(0, -1, 0, d1); r1 = max_element(d1.begin(), d1.end()) - d1.begin(); dfs(r1, -1, 0, d1); r2 = max_element(d1.begin(), d1.end()) - d1.begin(); dfs(r2, -1, 0, d2); dia = d1[r2]; } vector<int> find_centre() { // 直径の中心をさがす 1頂点 or // 2頂点 直径は必ずこれらすべてを通る vector<int> ret; for (int i = 0; i < d1.size(); i++) { if (d1[i] + d2[i] == dia && abs(d1[i] - d2[i]) <= 1) { ret.push_back(i); } } return ret; } }; // treediameter(v) vector<vector<int>> v; bool flag[MAX]; // 0:none with only one type of operation // 1:positive without substraction // 2: none with mix int dp[MAX][3]; bool us[MAX][3]; int target; inline int dfs(int b, int ty, int pr = -1, int d = 0) { if (us[b][ty]) { return dp[b][ty]; } us[b][ty] = true; int ava = 0; vector<int> can; for (int go : v[b]) { if (go == pr || flag[go]) continue; ava++; can.push_back(go); } assert(d <= target); if (ava == 0) { // leaf if (ty == 1) { if (d == target) { dp[b][ty] = 1; return 1; } dp[b][ty] = 0; return 0; } if (ty == 0) { if (d == target) { dp[b][ty] = 0; return 0; } dp[b][ty] = 1; return 1; } if (ty == 2) { dp[b][ty] = 1; return 1; } exit(1); } if (ty == 1) { if (true) { for (int go : can) { auto ret = dfs(go, 1, b, d + 1); for (int goo : can) { if (go != goo) { multo(ret, add(dfs(goo, 0, b, d + 1), mul(2, dfs(goo, 2, b, d + 1)))); } } addto(dp[b][ty], ret); } } else { for (int go : can) { auto ret = dfs(go, 1, b, d + 1); for (int goo : can) { if (go != goo) { multo(ret, add(mul(2, dfs(goo, 0, b, d + 1)), mul(1, dfs(goo, 2, b, d + 1)))); } } addto(dp[b][ty], ret); } } } if (ty == 2) { dp[b][ty] = 1; for (int goo : can) { multo(dp[b][ty], mul(3, dfs(goo, 2, b, d + 1))); } } if (ty == 0) { dp[b][ty] = 1; for (int goo : can) { multo(dp[b][ty], add(dfs(goo, 0, b, d + 1), mul(2, dfs(goo, 2, b, d + 1)))); } } return dp[b][ty]; } int main() { cin >> n; v.resize(n); for (int i = 1; i < n; i++) { int a, b; scanf("%d%d", &a, &b); a--; b--; v[a].push_back(b); v[b].push_back(a); } auto dia = treediameter(v); auto centre = dia.find_centre(); for (auto el : centre) { flag[el] = true; } if (centre.size() == 1) { int pos = centre[0]; target = dia.dia / 2; long long int ans = 0; vector<int> ml; int overall = 1; for (int el3 : v[pos]) { ml.push_back( add(mul(2, dfs(el3, 0, pos, 1)), mul(1, dfs(el3, 2, pos, 1)))); multo(overall, ml.back()); } int i = 0; for (int el1 : v[pos]) { int j = 0; for (int el2 : v[pos]) { if (el1 != el2) { auto ret = mul(dfs(el1, 1, pos, 1), dfs(el2, 1, pos, 1)); multo(ret, overall); multo(ret, ppow(ml[i], MOD - 2)); multo(ret, ppow(ml[j], MOD - 2)); addto(ans, ret); } j++; } i++; } multo(ans, ppow(2, MOD - 2)); ans %= MOD; printf("%lld\n", ans); } else { cerr << centre[0] << " " << centre[1] << endl; cerr << dia.dia << endl; target = dia.dia / 2; long long int ans = 0; cerr << target << " " << dfs(centre[0], 1) << " " << dfs(centre[1], 1) << endl; addto(ans, mul(dfs(centre[0], 1), dfs(centre[1], 1))); printf("%lld\n", ans); } return 0; }
#include <bits/stdc++.h> using namespace std; #define MOD 998244353 template <typename ty1, typename ty2> inline int add(ty1 x, ty2 y) { if (y >= MOD) y %= MOD; if (x >= MOD) x %= MOD; x += y; return x < MOD ? x : x - MOD; } template <typename ty1, typename ty2> inline void addto(ty1 &x, ty2 y) { if (y >= MOD) y %= MOD; if (x >= MOD) x %= MOD; x += y; if (x >= MOD) x -= MOD; } template <typename ty1, typename ty2> inline int sub(ty1 x, ty2 y) { if (y >= MOD) y %= MOD; if (x >= MOD) x %= MOD; x -= y; return x < 0 ? x + MOD : x; } template <typename ty1, typename ty2> inline void subto(ty1 &x, ty2 y) { if (y >= MOD) y %= MOD; if (x >= MOD) x %= MOD; x -= y; if (x < 0) x += MOD; } template <typename ty1, typename ty2> inline int mul(ty1 x, ty2 y) { if (y >= MOD) y %= MOD; if (x >= MOD) x %= MOD; return 1ll * x * y % MOD; } template <typename ty1, typename ty2> void multo(ty1 &x, ty2 y) { if (y >= MOD) y %= MOD; if (x >= MOD) x %= MOD; x = 1ll * x * y % MOD; } long long int gcd(long long int a, long long int b) { if (a > b) { swap(a, b); } while (a) { swap(a, b); a %= b; } return b; } long long int lcm(long long int a, long long int b) { return a / gcd(a, b) * b; } long long int ppow(long long int i, long long int j) { long long int res = 1LL; while (j) { if ((j & 1LL)) { res *= i; if (res >= MOD) { res %= MOD; } } j >>= 1; i *= i; if (i >= MOD) { i %= MOD; } } return res; } class Combination { public: vector<long long int> k; vector<long long int> r; void resize(int N) { k.resize(N + 2); r.resize(N + 2); k[0] = 1; for (int i = 1; i < N + 2; i++) { k[i] = k[i - 1]; k[i] *= i; if (k[i] >= MOD) k[i] %= MOD; } long long int al = k[k.size() - 1]; long long int iv = ppow(k[k.size() - 1], MOD - 2); r[k.size() - 1] = iv; for (int i = (int)(r.size()) - 2; i >= 0; i--) { r[i] = r[i + 1] * (i + 1); if (r[i] >= MOD) { r[i] %= MOD; } } } long long int C(int a, int b) { if (a < b) return 0; long long int up = k[a]; long long int dw = r[b] * r[a - b]; dw %= MOD; up *= dw; up %= MOD; return up; } long long int H(int a, int b) { return C(a + b - 1, b); } long long int catalan_number(int n) { return (C(2 * n, n) + MOD - C(2 * n, n - 1)) % MOD; } }; Combination C; #define MAX 200002 int n; struct treediameter { // 直径は色々いい性質がある // 中心から(2頂点の場合それをくっつける)同じ距離のびた2つの頂点間が直径 // 直径は最大長であることにも注意 const vector<vector<int>> &g; int r1, r2; vector<int> d1, d2; // 両端からのdist int dia; void dfs(int v, int p, int cur, vector<int> &d) { d[v] = cur; for (auto e : g[v]) if (e != p) dfs(e, v, cur + 1, d); } treediameter(const vector<vector<int>> &gg) : g(gg), d1(g.size()), d2(g.size()) { dfs(0, -1, 0, d1); r1 = max_element(d1.begin(), d1.end()) - d1.begin(); dfs(r1, -1, 0, d1); r2 = max_element(d1.begin(), d1.end()) - d1.begin(); dfs(r2, -1, 0, d2); dia = d1[r2]; } vector<int> find_centre() { // 直径の中心をさがす 1頂点 or // 2頂点 直径は必ずこれらすべてを通る vector<int> ret; for (int i = 0; i < d1.size(); i++) { if (d1[i] + d2[i] == dia && abs(d1[i] - d2[i]) <= 1) { ret.push_back(i); } } return ret; } }; // treediameter(v) vector<vector<int>> v; bool flag[MAX]; // 0:none with only one type of operation // 1:positive without substraction // 2: none with mix int dp[MAX][3]; bool us[MAX][3]; int target; inline int dfs(int b, int ty, int pr = -1, int d = 0) { if (us[b][ty]) { return dp[b][ty]; } us[b][ty] = true; int ava = 0; vector<int> can; for (int go : v[b]) { if (go == pr || flag[go]) continue; ava++; can.push_back(go); } assert(d <= target); if (ava == 0) { // leaf if (ty == 1) { if (d == target) { dp[b][ty] = 1; return 1; } dp[b][ty] = 0; return 0; } if (ty == 0) { if (d == target) { dp[b][ty] = 0; return 0; } dp[b][ty] = 1; return 1; } if (ty == 2) { dp[b][ty] = 1; return 1; } exit(1); } if (ty == 1) { if (true) { for (int go : can) { auto ret = dfs(go, 1, b, d + 1); for (int goo : can) { if (go != goo) { multo(ret, add(dfs(goo, 0, b, d + 1), mul(2, dfs(goo, 2, b, d + 1)))); } } addto(dp[b][ty], ret); } } else { for (int go : can) { auto ret = dfs(go, 1, b, d + 1); for (int goo : can) { if (go != goo) { multo(ret, add(mul(2, dfs(goo, 0, b, d + 1)), mul(1, dfs(goo, 2, b, d + 1)))); } } addto(dp[b][ty], ret); } } } if (ty == 2) { dp[b][ty] = 1; for (int goo : can) { multo(dp[b][ty], mul(3, dfs(goo, 2, b, d + 1))); } } if (ty == 0) { dp[b][ty] = 1; for (int goo : can) { multo(dp[b][ty], add(dfs(goo, 0, b, d + 1), mul(2, dfs(goo, 2, b, d + 1)))); } } return dp[b][ty]; } int main() { cin >> n; v.resize(n); for (int i = 1; i < n; i++) { int a, b; scanf("%d%d", &a, &b); a--; b--; v[a].push_back(b); v[b].push_back(a); } auto dia = treediameter(v); auto centre = dia.find_centre(); for (auto el : centre) { flag[el] = true; } if (centre.size() == 1) { int pos = centre[0]; target = dia.dia / 2; long long int ans = 0; vector<int> ml; int overall = 1; for (int el3 : v[pos]) { ml.push_back( add(mul(2, dfs(el3, 0, pos, 1)), mul(1, dfs(el3, 2, pos, 1)))); multo(overall, ml.back()); } int tmp = 0; for (int i = 0; i < v[pos].size(); i++) { auto ret1 = mul(dfs(v[pos][i], 1, pos, 1), ppow(ml[i], MOD - 2)); addto(ans, mul(tmp, ret1)); addto(tmp, ret1); } multo(ans, overall); ans %= MOD; printf("%lld\n", ans); } else { cerr << centre[0] << " " << centre[1] << endl; cerr << dia.dia << endl; target = dia.dia / 2; long long int ans = 0; cerr << target << " " << dfs(centre[0], 1) << " " << dfs(centre[1], 1) << endl; addto(ans, mul(dfs(centre[0], 1), dfs(centre[1], 1))); printf("%lld\n", ans); } return 0; }
replace
280
296
280
287
TLE
p02752
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define REP(i, a, b) for (int i = (a), _ed = (b); i <= _ed; ++i) #define DREP(i, a, b) for (int i = (a), _ed = (b); i >= _ed; --i) #define mp(x, y) make_pair((x), (y)) #define sz(x) (int)(x).size() #define pb push_back typedef long long ll; typedef pair<int, int> pii; inline int read() { register int x = 0, f = 1; register char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = 0; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + (ch ^ '0'); ch = getchar(); } return f ? x : -x; } const int N = 2e5 + 5, mod = 998244353; int n, c[2], mxd[N], f[N][3][3], g[3][3]; vector<int> E[N]; inline void inc(int &x, int y) { x = x + y < mod ? x + y : x + y - mod; } namespace getcore { int d[N], fa[N], stk[N], tp, tmp; void dfs(int u, int pa, int dis, int &rt) { d[u] = dis, fa[u] = pa; if (d[u] > d[rt]) rt = u; for (int v : E[u]) { if (v == pa) continue; dfs(v, u, dis + 1, rt); } } void Main() { dfs(1, 0, 0, tmp); dfs(tmp, 0, 0, tmp); while (tmp) stk[++tp] = tmp, tmp = fa[tmp]; c[0] = stk[(tp + 1) >> 1]; if (~tp & 1) c[1] = stk[((tp + 1) >> 1) + 1]; // 想清楚啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊 } } // namespace getcore int dfs(int u, int pa, int dep) { mxd[u] = dep; for (int v : E[u]) { if (v == pa || v == c[0] || v == c[1]) continue; mxd[u] = max(mxd[u], dfs(v, u, dep + 1)); } if (mxd[u] == dep) f[u][1][1] = 1; else f[u][0][0] = 1; for (int v : E[u]) { if (v == pa || v == c[0] || v == c[1]) continue; REP(i, 0, 2) REP(j, 0, 2) g[i][j] = 0; REP(a, 0, 2) REP(b, 0, 2) REP(p, 0, 2) REP(q, 0, 2) { int flg = mxd[u] == mxd[v]; int s = a, t = b, val = 1ll * f[u][a][b] * f[v][p][q] % mod; inc(g[s][t], val); s = flg ? min(2, a + p) : a, t = b; inc(g[s][t], val); s = a, t = flg ? min(2, b + q) : b; inc(g[s][t], val); } REP(i, 0, 2) REP(j, 0, 2) f[u][i][j] = g[i][j]; } return mxd[u]; } int main() { freopen("in.in", "r", stdin); freopen("out.out", "w", stdout); n = read(); REP(i, 1, n - 1) { int u = read(), v = read(); E[u].pb(v), E[v].pb(u); } getcore::Main(); int sum = 0; dfs(c[0], 0, 0); if (!c[1]) sum = f[c[0]][1][1]; else { dfs(c[1], 0, 0); REP(i, 0, 2) REP(j, 0, 2) inc(sum, 1ll * f[c[0]][1][i] * f[c[1]][j][1] % mod); REP(i, 0, 2) REP(j, 0, 2) inc(sum, 1ll * f[c[0]][i][1] * f[c[1]][1][j] % mod); } sum = 1ll * sum * (mod + 1) / 2 % mod; printf("%d\n", sum); return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, a, b) for (int i = (a), _ed = (b); i <= _ed; ++i) #define DREP(i, a, b) for (int i = (a), _ed = (b); i >= _ed; --i) #define mp(x, y) make_pair((x), (y)) #define sz(x) (int)(x).size() #define pb push_back typedef long long ll; typedef pair<int, int> pii; inline int read() { register int x = 0, f = 1; register char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = 0; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + (ch ^ '0'); ch = getchar(); } return f ? x : -x; } const int N = 2e5 + 5, mod = 998244353; int n, c[2], mxd[N], f[N][3][3], g[3][3]; vector<int> E[N]; inline void inc(int &x, int y) { x = x + y < mod ? x + y : x + y - mod; } namespace getcore { int d[N], fa[N], stk[N], tp, tmp; void dfs(int u, int pa, int dis, int &rt) { d[u] = dis, fa[u] = pa; if (d[u] > d[rt]) rt = u; for (int v : E[u]) { if (v == pa) continue; dfs(v, u, dis + 1, rt); } } void Main() { dfs(1, 0, 0, tmp); dfs(tmp, 0, 0, tmp); while (tmp) stk[++tp] = tmp, tmp = fa[tmp]; c[0] = stk[(tp + 1) >> 1]; if (~tp & 1) c[1] = stk[((tp + 1) >> 1) + 1]; // 想清楚啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊 } } // namespace getcore int dfs(int u, int pa, int dep) { mxd[u] = dep; for (int v : E[u]) { if (v == pa || v == c[0] || v == c[1]) continue; mxd[u] = max(mxd[u], dfs(v, u, dep + 1)); } if (mxd[u] == dep) f[u][1][1] = 1; else f[u][0][0] = 1; for (int v : E[u]) { if (v == pa || v == c[0] || v == c[1]) continue; REP(i, 0, 2) REP(j, 0, 2) g[i][j] = 0; REP(a, 0, 2) REP(b, 0, 2) REP(p, 0, 2) REP(q, 0, 2) { int flg = mxd[u] == mxd[v]; int s = a, t = b, val = 1ll * f[u][a][b] * f[v][p][q] % mod; inc(g[s][t], val); s = flg ? min(2, a + p) : a, t = b; inc(g[s][t], val); s = a, t = flg ? min(2, b + q) : b; inc(g[s][t], val); } REP(i, 0, 2) REP(j, 0, 2) f[u][i][j] = g[i][j]; } return mxd[u]; } int main() { // freopen("in.in","r",stdin); // freopen("out.out","w",stdout); n = read(); REP(i, 1, n - 1) { int u = read(), v = read(); E[u].pb(v), E[v].pb(u); } getcore::Main(); int sum = 0; dfs(c[0], 0, 0); if (!c[1]) sum = f[c[0]][1][1]; else { dfs(c[1], 0, 0); REP(i, 0, 2) REP(j, 0, 2) inc(sum, 1ll * f[c[0]][1][i] * f[c[1]][j][1] % mod); REP(i, 0, 2) REP(j, 0, 2) inc(sum, 1ll * f[c[0]][i][1] * f[c[1]][1][j] % mod); } sum = 1ll * sum * (mod + 1) / 2 % mod; printf("%d\n", sum); return 0; }
replace
83
85
83
85
TLE
p02753
C++
Runtime Error
#include <algorithm> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> #include <float.h> #include <time.h> #define loop(i, n) for (i = 0; i < n; i++) #define loop1(i, n) for (i = 1; i <= n; i++) #define loop2(i, n, start) for (i = start; i <= n; i++) #define loopIterators(it, vec) for (it = (vec).begin(); it != (vec).end(); it++) #define loopRev(i, n) for (i = (n - 1); i >= 0; i--) #define FLASH \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define testCases(t) \ cin >> t; \ while (t--) #define PN(n) cout << (n) #define PN1(n) cout << (n) << " " #define PN2(a, b) cout << (a) << " " << (b) << " " #define PNN1(n) cout << (n) << endl #define PNN2(a, b) cout << (a) << " " << (b) << endl #define PNN3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl #define PrintArray(ar, n) \ for (i = 0; i < n; i++) \ cout << ar[i] << " "; \ cout << endl #define PrintSet(ar, it) \ for (it = ar.begin(); it != ar.end(); it++) \ cout << *it << " "; \ cout << endl #define PrintMap(map, it) \ for (it = map.begin(); it != map.end(); it++) \ PNN2(it->first, it->second) #define sz(a) sizeof(a) #define IN1(n) cin >> n #define IN2(a, b) cin >> a >> b #define IN3(a, b, c) cin >> a >> b >> c #define ALL(s) s.begin(), s.end() #define SWAP(a, b, c) \ c = a; \ a = b; \ b = c #define STRSP(s) scanf("%[^\n]%*c", s) #define ENTER PNN1(""); #define MOD7 1000000007 #define MOD9 10000009 #define MAX 100005 #define llPair std::pair<lli, lli> #define iiPair std::pair<int, int> typedef long long int lli; typedef long int li; typedef unsigned long long int ulli; typedef long double ld; using namespace std; int main(void) { FLASH #ifndef ONLINE_JUDGE freopen("input-stream.txt", "r", stdin); freopen("output-stream.txt", "w", stdout); #endif std::string str; std::string::iterator it; IN1(str); int a = 0, b = 0; loopIterators(it, str) if (*it == 'A')++ a; else ++b; PNN1(a == 3 || b == 3 ? "No" : "Yes"); #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout); #endif return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <utility> #include <vector> #include <float.h> #include <time.h> #define loop(i, n) for (i = 0; i < n; i++) #define loop1(i, n) for (i = 1; i <= n; i++) #define loop2(i, n, start) for (i = start; i <= n; i++) #define loopIterators(it, vec) for (it = (vec).begin(); it != (vec).end(); it++) #define loopRev(i, n) for (i = (n - 1); i >= 0; i--) #define FLASH \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define testCases(t) \ cin >> t; \ while (t--) #define PN(n) cout << (n) #define PN1(n) cout << (n) << " " #define PN2(a, b) cout << (a) << " " << (b) << " " #define PNN1(n) cout << (n) << endl #define PNN2(a, b) cout << (a) << " " << (b) << endl #define PNN3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl #define PrintArray(ar, n) \ for (i = 0; i < n; i++) \ cout << ar[i] << " "; \ cout << endl #define PrintSet(ar, it) \ for (it = ar.begin(); it != ar.end(); it++) \ cout << *it << " "; \ cout << endl #define PrintMap(map, it) \ for (it = map.begin(); it != map.end(); it++) \ PNN2(it->first, it->second) #define sz(a) sizeof(a) #define IN1(n) cin >> n #define IN2(a, b) cin >> a >> b #define IN3(a, b, c) cin >> a >> b >> c #define ALL(s) s.begin(), s.end() #define SWAP(a, b, c) \ c = a; \ a = b; \ b = c #define STRSP(s) scanf("%[^\n]%*c", s) #define ENTER PNN1(""); #define MOD7 1000000007 #define MOD9 10000009 #define MAX 100005 #define llPair std::pair<lli, lli> #define iiPair std::pair<int, int> #define ONLINE_JUDGE typedef long long int lli; typedef long int li; typedef unsigned long long int ulli; typedef long double ld; using namespace std; int main(void) { FLASH #ifndef ONLINE_JUDGE freopen("input-stream.txt", "r", stdin); freopen("output-stream.txt", "w", stdout); #endif std::string str; std::string::iterator it; IN1(str); int a = 0, b = 0; loopIterators(it, str) if (*it == 'A')++ a; else ++b; PNN1(a == 3 || b == 3 ? "No" : "Yes"); #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout); #endif return 0; }
insert
65
65
65
66
0
p02753
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define sz(x) int(x.size()) #define pii pair<int, int> #define Task "abc" #define For(i, a, b) for (int i = (a), _b = (b); i <= b; ++i) #define Debug(X) cout << #X << " = " << X << '\n' #define All(x) (x).begin(), (x).end() #define mp make_pair typedef unsigned long long ull; typedef long long ll; const int maxn = 1e5 + 10; const int inf = 0x3f3f3f3f; const ll mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); freopen(Task ".inp", "r", stdin); // freopen(Task".out", "w", stdout); string s; cin >> s; map<char, int> m; for (auto c : s) m[c]++; if ((int)m.size() == 2) cout << "Yes"; else cout << "No"; }
#include <bits/stdc++.h> using namespace std; #define sz(x) int(x.size()) #define pii pair<int, int> #define Task "abc" #define For(i, a, b) for (int i = (a), _b = (b); i <= b; ++i) #define Debug(X) cout << #X << " = " << X << '\n' #define All(x) (x).begin(), (x).end() #define mp make_pair typedef unsigned long long ull; typedef long long ll; const int maxn = 1e5 + 10; const int inf = 0x3f3f3f3f; const ll mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen(Task".inp", "r", stdin); // freopen(Task".out", "w", stdout); string s; cin >> s; map<char, int> m; for (auto c : s) m[c]++; if ((int)m.size() == 2) cout << "Yes"; else cout << "No"; }
replace
22
23
22
23
0
p02753
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { string s; if (s.at(0) == s.at(1) && s.at(1) == s.at(2)) cout << "No" << endl; else cout << "Yes" << endl; }
#include <iostream> #include <string> using namespace std; int main() { string s; cin >> s; if (s.at(0) == s.at(1) && s.at(1) == s.at(2)) cout << "No" << endl; else cout << "Yes" << endl; }
insert
5
5
5
6
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::at: __n (which is 0) >= this->size() (which is 0)
p02753
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string S; char a = S.at(0); char b = S.at(1); char c = S.at(2); if (a == b && b == c) { cout << "No" << endl; } else { cout << "Yes" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; char a = S.at(0); char b = S.at(1); char c = S.at(2); if (a == b && b == c) { cout << "No" << endl; } else { cout << "Yes" << endl; } }
insert
5
5
5
6
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::at: __n (which is 0) >= this->size() (which is 0)
p02753
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; if (s.at(1) == 'A' && s.at(2) == 'A' && s.at(3) == 'A') { cout << "No" << endl; } else if (s.at(1) == 'B' && s.at(2) == 'B' && s.at(3) == 'B') { cout << "No" << endl; } else { cout << "Yes" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; bool k = true; for (int i = 0; i < 3; i++) { if (s.at(i) == 'A') { continue; } else if (s.at(1) == 'B') { break; } else if (s.at(i) == 'B') { k = false; break; } else { } } for (int i = 0; i < 3; i++) { if (s.at(i) == 'B') { continue; } else if (s.at(1) == 'A') { break; } else if (s.at(i) == 'A') { k = false; break; } else { } } if (k == true) { cout << "No" << endl; } else { cout << "Yes" << endl; } }
replace
6
9
6
30
0
p02753
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define mod 1000000007 int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "rt", stdin); freopen("output.txt", "w", stdout); #endif fast string s; cin >> s; int a = 0, b = 0; for (int i = 0; i < 3; i++) { if (s[i] == 'A') { a++; } else b++; } if (a == 3 || b == 3) cout << "No"; else cout << "Yes"; #ifndef ONLINE_JUDGE cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define mod 1000000007 int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "rt", stdin); // freopen("output.txt", "w", stdout); // #endif fast string s; cin >> s; int a = 0, b = 0; for (int i = 0; i < 3; i++) { if (s[i] == 'A') { a++; } else b++; } if (a == 3 || b == 3) cout << "No"; else cout << "Yes"; #ifndef ONLINE_JUDGE cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif }
replace
8
12
8
12
0
Time elapsed: 0.02945 s.
p02753
C++
Runtime Error
/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/ /*-------------------------------@greenindia-----------------------------------*/ // // _____ _ _ _ // / ____| | | (_) | | // | (___ __ _| |__ _ _ _ | | __ _ _ __ __ _ // \___ \ / _` | '_ \| | | | | _ | |/ _` | '_ \ / _` | // ____) | (_| | |_) | |_| | | | |__| | (_| | | | | (_| | // |_____/ \__,_|_.__/ \__,_| | \____/ \__,_|_| |_|\__,_| // _/ | // |__/ /*---------------------- Magic. Do not touch.-----------------------------*/ /*------------------------------God is * Great/\---------------------------------*/ #include <bits/stdc++.h> using namespace std; #define crap \ ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) // cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl; #define int long long int #define double long double #define PI acos(-1) void print1d(const vector<int> &vec) { for (auto val : vec) { cout << val << " "; } cout << endl; } void print2d(const vector<vector<int>> &vec) { for (auto row : vec) { for (auto val : row) { cout << val << " "; } cout << endl; } } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif crap; string str; cin >> str; if (str[0] == 'A' and str[1] == 'A' and str[2] == 'A') cout << "No" << endl; else if (str[0] == 'B' and str[1] == 'B' and str[2] == 'B') cout << "No" << endl; else cout << "Yes" << endl; return 0; }
/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/ /*-------------------------------@greenindia-----------------------------------*/ // // _____ _ _ _ // / ____| | | (_) | | // | (___ __ _| |__ _ _ _ | | __ _ _ __ __ _ // \___ \ / _` | '_ \| | | | | _ | |/ _` | '_ \ / _` | // ____) | (_| | |_) | |_| | | | |__| | (_| | | | | (_| | // |_____/ \__,_|_.__/ \__,_| | \____/ \__,_|_| |_|\__,_| // _/ | // |__/ /*---------------------- Magic. Do not touch.-----------------------------*/ /*------------------------------God is * Great/\---------------------------------*/ #include <bits/stdc++.h> using namespace std; #define crap \ ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) // cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl; #define int long long int #define double long double #define PI acos(-1) void print1d(const vector<int> &vec) { for (auto val : vec) { cout << val << " "; } cout << endl; } void print2d(const vector<vector<int>> &vec) { for (auto row : vec) { for (auto val : row) { cout << val << " "; } cout << endl; } } signed main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // #endif crap; string str; cin >> str; if (str[0] == 'A' and str[1] == 'A' and str[2] == 'A') cout << "No" << endl; else if (str[0] == 'B' and str[1] == 'B' and str[2] == 'B') cout << "No" << endl; else cout << "Yes" << endl; return 0; }
replace
42
45
42
45
0
p02753
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; if (S.at(1) == 'B' && S.at(2) == 'B' && S.at(3) == 'B') cout << "No" << endl; else cout << "Yes" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; if ((S.at(0) == 'B' && S.at(1) == 'B' && S.at(2) == 'B') || S.at(0) == 'A' && S.at(1) == 'A' && S.at(2) == 'A') cout << "No" << endl; else cout << "Yes" << endl; }
replace
5
6
5
7
0
p02753
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { string S; cin >> S; if (S == "AAA" || S == "BBB") { cout << "No" << endl; return -1; } cout << "Yes" << endl; }
#include <iostream> #include <string> using namespace std; int main() { string S; cin >> S; if (S == "AAA" || S == "BBB") { cout << "No" << endl; exit(0); } cout << "Yes" << endl; }
replace
11
12
11
12
0
p02753
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { vector<string> s; for (int i = 0; i < 3; i++) cin >> s[i]; if (s[0] == s[1] && s[1] == s[2] && s[2] == s[0]) cout << "No" << endl; else cout << "Yes" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; for (int i = 0; i < 3; i++) cin >> s[i]; if (s[0] == s[1] && s[1] == s[2] && s[2] == s[0]) cout << "No" << endl; else cout << "Yes" << endl; return 0; }
replace
4
5
4
5
-11
p02753
C++
Runtime Error
#include <bits/stdc++.h> #define mod 1000000007 #define db(a) cout << a << endl #define db2(a, b) cout << a << " " << b << endl #define dbp(a) cout << a.first << " " << a.second << endl #define adb(a) \ for (auto i : a) \ cout << i << " "; \ cout << endl #define adb2(a) \ for (auto i : a) \ cout << i.first << " " << i.second << endl; #define fastIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define N 100010 using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif fastIO; string s; cin >> s; if (s == "AAA" || s == "BBB") cout << "No" << endl; else cout << "Yes" << endl; }
#include <bits/stdc++.h> #define mod 1000000007 #define db(a) cout << a << endl #define db2(a, b) cout << a << " " << b << endl #define dbp(a) cout << a.first << " " << a.second << endl #define adb(a) \ for (auto i : a) \ cout << i << " "; \ cout << endl #define adb2(a) \ for (auto i : a) \ cout << i.first << " " << i.second << endl; #define fastIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define N 100010 using namespace std; int main() { fastIO; string s; cin >> s; if (s == "AAA" || s == "BBB") cout << "No" << endl; else cout << "Yes" << endl; }
delete
20
25
20
20
0
p02753
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int a, ans; string s; cin >> s; if (s.at(1) == s.at(2) && s.at(2) == s.at(3)) cout << "No"; else cout << "Yes"; // cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int a, ans; string s; cin >> s; if (s.at(1) == s.at(2) && s.at(0) == s.at(1)) cout << "No"; else cout << "Yes"; // cout << ans << "\n"; return 0; }
replace
7
8
7
8
0
p02753
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; if (S.at(1) == S.at(2) && S.at(2) == S.at(3)) cout << "No" << endl; else cout << "Yes" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; if (S.at(0) == S.at(1) && S.at(1) == S.at(2)) cout << "No" << endl; else cout << "Yes" << endl; }
replace
6
7
6
7
0
p02753
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; if (s.at(1) == s.at(2) && s.at(2) == s.at(3) && s.at(1) == s.at(3)) { cout << "No" << endl; } else { cout << "Yes" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; if (s == "AAA" || s == "BBB") { cout << "No" << endl; } else { cout << "Yes" << endl; } }
replace
5
6
5
6
0
p02753
C++
Runtime Error
#include <bits/stdc++.h> #define endl "\n" #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(0); using namespace std; typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> pi; #define F first #define S second #define pb push_back #define mp make_pair #define FOR(i, a, b) for (ll i = a; i <= b; i++) void solve() { string s; cin >> s; if (s[0] == s[1] && s[1] == s[2]) { cout << "No" << endl; } else { cout << "Yes" << endl; } return; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fastio ll t = 1; // cin >> t; while (t--) { solve(); } return 0; }
#include <bits/stdc++.h> #define endl "\n" #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(0); using namespace std; typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> pi; #define F first #define S second #define pb push_back #define mp make_pair #define FOR(i, a, b) for (ll i = a; i <= b; i++) void solve() { string s; cin >> s; if (s[0] == s[1] && s[1] == s[2]) { cout << "No" << endl; } else { cout << "Yes" << endl; } return; } int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif fastio ll t = 1; // cin >> t; while (t--) { solve(); } return 0; }
replace
32
36
32
36
0
p02753
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ll long long int main() { string s; if (s.at(0) == s.at(1) && s.at(1) == s.at(2)) cout << "No" << endl; else cout << "Yes" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ll long long int main() { string s; cin >> s; if (s.at(0) == s.at(1) && s.at(1) == s.at(2)) cout << "No" << endl; else cout << "Yes" << endl; return 0; }
insert
7
7
7
8
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::at: __n (which is 0) >= this->size() (which is 0)
p02753
C++
Runtime Error
/*Author : Kartik Bansal *Date : 07/09/19 *Time : 16:14 */ #include <bits/stdc++.h> using namespace std; typedef long long ll; #define tc \ int t; \ cin >> t; \ while (t--) #define pb push_back #define mp make_pair #define FOR(i, n) for (int i = 0; i < n; i++) #define loop(i, a, b) for (int i = a; i < b; i++) #define tra(a) \ for (auto it : a) \ cout << it << " "; #define all(v) v.begin(), v.end() #define vi vector<int> #define vll vector<long long> #define vpp vector<pair<int, int>> #define inf INT_MAX #define minf INT_MIN #define ss second #define ff first int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif string s; cin >> s; set<char> ss; FOR(i, 3) { ss.insert(s[i]); } if (ss.size() >= 2) cout << "Yes\n"; else cout << "No\n"; return 0; }
/*Author : Kartik Bansal *Date : 07/09/19 *Time : 16:14 */ #include <bits/stdc++.h> using namespace std; typedef long long ll; #define tc \ int t; \ cin >> t; \ while (t--) #define pb push_back #define mp make_pair #define FOR(i, n) for (int i = 0; i < n; i++) #define loop(i, a, b) for (int i = a; i < b; i++) #define tra(a) \ for (auto it : a) \ cout << it << " "; #define all(v) v.begin(), v.end() #define vi vector<int> #define vll vector<long long> #define vpp vector<pair<int, int>> #define inf INT_MAX #define minf INT_MIN #define ss second #define ff first int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif string s; cin >> s; set<char> ss; FOR(i, 3) { ss.insert(s[i]); } if (ss.size() >= 2) cout << "Yes\n"; else cout << "No\n"; return 0; }
replace
29
33
29
33
0
p02753
C++
Runtime Error
#include <iostream> #include <string> int main() { std::string str; std::cin >> str; for (int i = 0; i < 3; i++) for (int j = j + 1; j < 3; j++) if (str[i] != str[j]) { std::cout << "Yes" << std::endl; return 0; } std::cout << "No" << std::endl; }
#include <iostream> #include <string> int main() { std::string str; std::cin >> str; int ca = 0; int cb = 0; for (int i = 0; i < 3; ++i) if (str[i] == 'A') ca += 1; else cb += 1; if (ca == 3 || cb == 3) std::cout << "No" << std::endl; else std::cout << "Yes" << std::endl; }
replace
6
13
6
17
0
p02753
C++
Runtime Error
// Nguyen Anh Tu #include <bits/stdc++.h> #define FOR(x, a, b) for (int x = a; x <= b; x++) #define FORD(x, a, b) for (int x = a; x >= b; x--) #define maxn 100005 #define maxc 1000000007 #define MOD 1000000007 #define reset(x, y) memset(x, y, sizeof(x)) #define task "" #define mp make_pair #define pb push_back #define F first #define S second #define pii pair<int, int> #define ll long long #define bit(p, x) ((x >> p) & 1) #define remain(a, b) (a + b >= MOD) ? (a + b - MOD) : (a + b) using namespace std; string s; bool ok1, ok2; int main() { ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen(task ".inp", "r", stdin); freopen(task ".out", "w", stdout); #endif cin >> s; for (int i = 0; i <= 2; ++i) if (s[i] == 'A') ok1 = 1; else ok2 = 1; if (ok1 && ok2) cout << "Yes"; else cout << "No"; }
// Nguyen Anh Tu #include <bits/stdc++.h> #define FOR(x, a, b) for (int x = a; x <= b; x++) #define FORD(x, a, b) for (int x = a; x >= b; x--) #define maxn 100005 #define maxc 1000000007 #define MOD 1000000007 #define reset(x, y) memset(x, y, sizeof(x)) #define task "" #define mp make_pair #define pb push_back #define F first #define S second #define pii pair<int, int> #define ll long long #define bit(p, x) ((x >> p) & 1) #define remain(a, b) (a + b >= MOD) ? (a + b - MOD) : (a + b) using namespace std; string s; bool ok1, ok2; int main() { ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); cin >> s; for (int i = 0; i <= 2; ++i) if (s[i] == 'A') ok1 = 1; else ok2 = 1; if (ok1 && ok2) cout << "Yes"; else cout << "No"; }
delete
25
29
25
25
0
p02753
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define lli long long int int main() { lli n, i, j, flag = 0; cin >> n; string s; cin >> s; for (i = 0; i < s.size() - 1; i++) { if (s[i] != s[i + 1]) { flag = 1; break; } } if (flag == 0) cout << "No" << '\n'; else cout << "Yes" << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; #define lli long long int int main() { lli n, i, j, flag = 0; string s; cin >> s; for (i = 0; i < s.size() - 1; i++) { if (s[i] != s[i + 1]) { flag = 1; break; } } if (flag == 0) cout << "No" << '\n'; else cout << "Yes" << '\n'; return 0; }
delete
5
6
5
5
0
p02753
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ii> vii; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef vector<vii> vvii; #define fastIO ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define forw(i, l, r) for (int i = (l); i < (r); i++) #define forb(i, r, l) for (int i = (r); i > (l); i--) #define log2i(x) 32 - __builtin_clz((x)) - 1 #define log2ll(x) 64 - __builtin_clzll((x)) - 1 #define Pi acos(-1.0) #define sz(x) (int)x.size() #define pw(x, y) trunc(exp(log((x)) * (y))) #define mt make_tuple #define mp make_pair #define fi first #define se second #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() string st; int main() { #ifndef ONLINE_JUDGE freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); #endif fastIO; cin >> st; if (count(all(st), 'A') == 2 || count(all(st), 'B') == 2) cout << "Yes"; else cout << "No"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<ii> vii; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef vector<vii> vvii; #define fastIO ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define forw(i, l, r) for (int i = (l); i < (r); i++) #define forb(i, r, l) for (int i = (r); i > (l); i--) #define log2i(x) 32 - __builtin_clz((x)) - 1 #define log2ll(x) 64 - __builtin_clzll((x)) - 1 #define Pi acos(-1.0) #define sz(x) (int)x.size() #define pw(x, y) trunc(exp(log((x)) * (y))) #define mt make_tuple #define mp make_pair #define fi first #define se second #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() string st; int main() { #ifndef ONLINE_JUDGE // freopen("test.inp","r",stdin); // freopen("test.out","w",stdout); #endif fastIO; cin >> st; if (count(all(st), 'A') == 2 || count(all(st), 'B') == 2) cout << "Yes"; else cout << "No"; return 0; }
replace
35
37
35
37
0
p02753
C++
Runtime Error
#include <bits/stdc++.h> #define fup(i, a, b) for (int i = a; i <= b; ++i) #define fdw(i, a, b) for (int i = a; i >= b; --i) #define sync \ ios::sync_with_stdio(false); \ cin.tie(0) #define cl(a) memset(a, 0, sizeof(a)) #define gcd __gcd #define fi first #define se second #define pb push_back #pragma GCC optimize(2) using namespace std; typedef long long ll; // ll lcm(ll a,ll b){return a/gcd(a,b)*b;} // ll ksm(ll a,ll b,ll mod){ll res=1;a%=mod;for(;b;b>>=1){if(b&1) // res=res*a%mod;a=a*a%mod;}return res;} ll oula(ll n){ ll res=n;for(ll // i=2;i*i<=n;i++){if(n%i==0){ res=res-res/i;while(n%i==0) n/=i;}}if(n>1) // res=res-res/n;return res;} bool MRT(ll x){if(x==2)return true;fup(i,1,50){ll // now=rand()%(x-2)+2;if(ksm(now,x-1,x)!=1)return false;}return true;} void // shai(int n)fup(i,2,n){if(isprime[i]){v.push_back(i);for(int // j=2*i;j<=10000;j+=i)isprime[j]=0;}}//"埃氏筛筛选素数" const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; const double eps = 1e-7; const int N = 4e5 + 10; int main() { #ifdef ONLINE_JUDGE #else freopen("D:\\untitled3\\in", "r", stdin); #endif sync; string s; cin >> s; int t1 = 0, t2 = 0; fup(i, 0, 2) { if (s[i] == 'A') t1++; else t2++; } if (t1 && t2) { cout << "Yes" << endl; } else cout << "No" << endl; return 0; }
#include <bits/stdc++.h> #define fup(i, a, b) for (int i = a; i <= b; ++i) #define fdw(i, a, b) for (int i = a; i >= b; --i) #define sync \ ios::sync_with_stdio(false); \ cin.tie(0) #define cl(a) memset(a, 0, sizeof(a)) #define gcd __gcd #define fi first #define se second #define pb push_back #pragma GCC optimize(2) using namespace std; typedef long long ll; // ll lcm(ll a,ll b){return a/gcd(a,b)*b;} // ll ksm(ll a,ll b,ll mod){ll res=1;a%=mod;for(;b;b>>=1){if(b&1) // res=res*a%mod;a=a*a%mod;}return res;} ll oula(ll n){ ll res=n;for(ll // i=2;i*i<=n;i++){if(n%i==0){ res=res-res/i;while(n%i==0) n/=i;}}if(n>1) // res=res-res/n;return res;} bool MRT(ll x){if(x==2)return true;fup(i,1,50){ll // now=rand()%(x-2)+2;if(ksm(now,x-1,x)!=1)return false;}return true;} void // shai(int n)fup(i,2,n){if(isprime[i]){v.push_back(i);for(int // j=2*i;j<=10000;j+=i)isprime[j]=0;}}//"埃氏筛筛选素数" const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; const double eps = 1e-7; const int N = 4e5 + 10; int main() { sync; string s; cin >> s; int t1 = 0, t2 = 0; fup(i, 0, 2) { if (s[i] == 'A') t1++; else t2++; } if (t1 && t2) { cout << "Yes" << endl; } else cout << "No" << endl; return 0; }
replace
27
31
27
28
0
p02753
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (int i = 0; i < N; i++) #define all(x) x.begin(), x.end() #define sort(x) sort(all(x)) #define cou(x) cout << x << endl using lint = long long; int main() { string N; cin >> N; cou((N == "AAA" || N == "BBB" ? "No" : "Yes")); rep(i, 1000) { rep(j, 1000) { rep(k, 200) { N = "処理"; } } } }
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (int i = 0; i < N; i++) #define all(x) x.begin(), x.end() #define sort(x) sort(all(x)) #define cou(x) cout << x << endl using lint = long long; int main() { string N; cin >> N; cou((N == "AAA" || N == "BBB" ? "No" : "Yes")); rep(i, 1000) { rep(j, 1000) { rep(k, 100) { N = "処理"; } } } }
replace
13
14
13
14
TLE
p02753
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (int i = 0; i < N; i++) #define all(x) x.begin(), x.end() #define sort(x) sort(all(x)) #define cou(x) cout << x << endl using lint = long long; int main() { string N; cin >> N; cou((N == "AAA" || N == "BBB" ? "No" : "Yes")); rep(i, 1000) { rep(j, 1000) { rep(k, 140) { N = "処理"; } } } }
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (int i = 0; i < N; i++) #define all(x) x.begin(), x.end() #define sort(x) sort(all(x)) #define cou(x) cout << x << endl using lint = long long; int main() { string N; cin >> N; cou((N == "AAA" || N == "BBB" ? "No" : "Yes")); rep(i, 1000) { rep(j, 1000) { rep(k, 135) { N = "処理"; } } } }
replace
13
14
13
14
TLE
p02753
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (int i = 0; i < N; i++) #define all(x) x.begin(), x.end() #define sort(x) sort(all(x)) #define cou(x) cout << x << endl using lint = long long; int main() { string N; cin >> N; cou((N == "AAA" || N == "BBB" ? "No" : "Yes")); rep(i, 1000) { rep(j, 1020) { rep(k, 135) { N = "処理"; } } } }
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (int i = 0; i < N; i++) #define all(x) x.begin(), x.end() #define sort(x) sort(all(x)) #define cou(x) cout << x << endl using lint = long long; int main() { string N; cin >> N; cou((N == "AAA" || N == "BBB" ? "No" : "Yes")); rep(i, 1000) { rep(j, 1005) { rep(k, 135) { N = "処理"; } } } }
replace
12
13
12
13
TLE
p02753
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; if (s.at(1) == s.at(2) && s.at(2) == s.at(3)) { cout << "No" << endl; } else { cout << "Yes" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; if (s.at(1) == s.at(2) && s.at(2) == s.at(0)) { cout << "No" << endl; } else { cout << "Yes" << endl; } }
replace
5
6
5
6
0
p02753
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define pi 3.14159265359 #define int long long #define pii pair<int, int> const int mod = 1e9 + 7; int dx[] = {-1, 0, 1, 0}; int dy[] = {0, -1, 0, 1}; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif string s; cin >> s; if (s[0] == s[1] && s[1] == s[2]) { cout << "No\n"; } else cout << "Yes\n"; }
#include <bits/stdc++.h> using namespace std; #define pi 3.14159265359 #define int long long #define pii pair<int, int> const int mod = 1e9 + 7; int dx[] = {-1, 0, 1, 0}; int dy[] = {0, -1, 0, 1}; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); string s; cin >> s; if (s[0] == s[1] && s[1] == s[2]) { cout << "No\n"; } else cout << "Yes\n"; }
delete
15
20
15
15
0
p02753
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("in.in", "r", stdin); // freopen("out.out", "w", stdout); #endif // ONLINE_JUDGE ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; if (s[0] == s[1] && s[1] == s[2]) cout << "No"; else cout << "Yes"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string s; cin >> s; if (s[0] == s[1] && s[1] == s[2]) cout << "No"; else cout << "Yes"; return 0; }
delete
4
8
4
4
0
p02753
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep1(i, n) for (ll i = 1; i <= (n); ++i) #define repA(i, a, n) for (ll i = a; i <= (n); ++i) #define repD(i, a, n) for (ll i = a; i >= (n); --i) // #define trav(a, x) for(auto& a : x) #define all(x) x.begin(), x.end() #define sz(x) (ll)(x).size() #define bpc(a) __builtin_popcount(a) #define ff first #define ss second #define mk0(a) memset(a, 0, sizeof(a)) #define mk_1(a) memset(a, -1, sizeof(a)) const ll MAX = 1e5 + 5; const ll MAX1 = 1e2 + 5; const ll INF = 1e15 + 2; const ll MOD = 1e9 + 7; #define pb push_back #define faster \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(0); #define pi pair<ll, ll> #define map1 unordered_map inline ll nc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline ll read() { ll ret = 0; bool f = 0; char ch = nc(); while (ch > '9' || ch < '0') f ^= ch == '-', ch = nc(); while (ch <= '9' && ch >= '0') ret = ret * 10 + ch - '0', ch = nc(); return f ? -ret : ret; } ll power(ll base, ll ind, ll mod) { ll res = 1; while (ind) { if (ind & 1) res = (res * base) % mod; base = (base * base) % mod; ind >>= 1; } return res; } ll inv(ll den, ll mod) { return power(den, mod - 2, mod); } int main() { faster; #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif string s; cin >> s; ll c[2]; mk0(c); for (int i = 0; i < sz(s); ++i) { if (s[i] == 'A') c[0]++; else if (s[i] == 'B') c[1]++; } if (c[0] == 0 or c[1] == 0) cout << "No\n"; else cout << "Yes\n"; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; #define rep(i, n) for (ll i = 0; i < (n); ++i) #define rep1(i, n) for (ll i = 1; i <= (n); ++i) #define repA(i, a, n) for (ll i = a; i <= (n); ++i) #define repD(i, a, n) for (ll i = a; i >= (n); --i) // #define trav(a, x) for(auto& a : x) #define all(x) x.begin(), x.end() #define sz(x) (ll)(x).size() #define bpc(a) __builtin_popcount(a) #define ff first #define ss second #define mk0(a) memset(a, 0, sizeof(a)) #define mk_1(a) memset(a, -1, sizeof(a)) const ll MAX = 1e5 + 5; const ll MAX1 = 1e2 + 5; const ll INF = 1e15 + 2; const ll MOD = 1e9 + 7; #define pb push_back #define faster \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(0); #define pi pair<ll, ll> #define map1 unordered_map inline ll nc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline ll read() { ll ret = 0; bool f = 0; char ch = nc(); while (ch > '9' || ch < '0') f ^= ch == '-', ch = nc(); while (ch <= '9' && ch >= '0') ret = ret * 10 + ch - '0', ch = nc(); return f ? -ret : ret; } ll power(ll base, ll ind, ll mod) { ll res = 1; while (ind) { if (ind & 1) res = (res * base) % mod; base = (base * base) % mod; ind >>= 1; } return res; } ll inv(ll den, ll mod) { return power(den, mod - 2, mod); } int main() { faster; /*#ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); #endif*/ string s; cin >> s; ll c[2]; mk0(c); for (int i = 0; i < sz(s); ++i) { if (s[i] == 'A') c[0]++; else if (s[i] == 'B') c[1]++; } if (c[0] == 0 or c[1] == 0) cout << "No\n"; else cout << "Yes\n"; }
replace
65
69
65
69
0
p02753
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef vector<ll> vi; #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define nl cout << '\n' #define pb push_back #define all(s) s.begin(), s.end() #define bs binary_search #define gcd(a, b) __gcd((a), (b)) #define lcm(a, b) (a) * (b) / (__gcd((a), (b))) const int Mod = 1e9 + 7; #define sum(a, b) (((a) % Mod) + ((b) % Mod)) % Mod #define sub(a, b) (((a) % Mod) - ((b) % Mod)) % Mod #define mul(a, b) (((a) % Mod) * ((b) % Mod)) % Mod #define count1(x) __built_popcount(x) #define loop(i, s, e) for (i = s; i < e; i++) #define rloop(i, s, e) for (i = e; i >= s; i--) #define dbg(x) cout << #x << ":" << x << endl; bool isPowerOfTwo(int x) { /* First x in the below expression is for the case when x is 0 */ return x && (!(x & (x - 1))); } ll pow(ll x, ll y, ll mod) { int ans = 1; while (y) { if (y & 1) ans = (ans * x) % mod; y /= 2; x = (x * x) % mod; } return ans; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("debug.txt", "w", stderr); #endif fast; int i, a = 0, b = 0; string s; cin >> s; for (i = 0; i < 3; i++) { if (s[i] == 'A') a = 1; else b = 1; } if (a & b) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long int ull; typedef long long int ll; typedef vector<ll> vi; #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define nl cout << '\n' #define pb push_back #define all(s) s.begin(), s.end() #define bs binary_search #define gcd(a, b) __gcd((a), (b)) #define lcm(a, b) (a) * (b) / (__gcd((a), (b))) const int Mod = 1e9 + 7; #define sum(a, b) (((a) % Mod) + ((b) % Mod)) % Mod #define sub(a, b) (((a) % Mod) - ((b) % Mod)) % Mod #define mul(a, b) (((a) % Mod) * ((b) % Mod)) % Mod #define count1(x) __built_popcount(x) #define loop(i, s, e) for (i = s; i < e; i++) #define rloop(i, s, e) for (i = e; i >= s; i--) #define dbg(x) cout << #x << ":" << x << endl; bool isPowerOfTwo(int x) { /* First x in the below expression is for the case when x is 0 */ return x && (!(x & (x - 1))); } ll pow(ll x, ll y, ll mod) { int ans = 1; while (y) { if (y & 1) ans = (ans * x) % mod; y /= 2; x = (x * x) % mod; } return ans; } int main() { fast; int i, a = 0, b = 0; string s; cin >> s; for (i = 0; i < 3; i++) { if (s[i] == 'A') a = 1; else b = 1; } if (a & b) { cout << "Yes" << endl; } else { cout << "No" << endl; } }
replace
48
53
48
49
0
p02753
C++
Runtime Error
// R<3S #include <bits/stdc++.h> #define FAST \ std::ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define DECIMAL(n) \ std::cout << std::fixed; \ std::cout << std::setprecision(n); #define hell 1000000007 #define PI 3.14159265358979323844 #define mp make_pair #define pb push_back #define fi first #define se second #define ALL(v) v.begin(), v.end() #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define endl "\n" #define maxc(v) max_element(all(v)) #define minc(v) min_element(all(v)) #define GCD(m, n) __gcd(m, n) #define LCM(m, n) m *(n / GCD(m, n)) #define inputarr(a, n) \ for (int i = 0; i < n; ++i) \ cin >> a[i] #define initarr(a, n, x) \ for (int i = 0; i < n; ++i) \ a[i] = x #define rep(i, n) for (int i = 0; i < (n); ++i) #define repA(i, a, n) for (int i = a; i <= (n); ++i) #define repD(i, a, n) for (int i = a; i >= (n); --i) #define trav(a, x) for (auto &a : x) #define sz(a) (int)a.size() #define sl(a) (int)a.length() #define invect(data, n, commands) \ for (int i = 0; i < n; i++) { \ int tmp; \ cin >> tmp; \ data.pb(tmp); \ commands \ } #define inset(data, n, commands) \ for (int i = 0; i < n; i++) { \ int tmp; \ cin >> tmp; \ data.insert(tmp); \ commands \ } #define ll long long #define ld long double #define pii std::pair<int, int> #define pll std::pair<ll, ll> #define vi vector<int> #define vvi vector<vi> #define vii vector<pii> #define mii map<int, int> #define trace1(x) cerr << #x << ": " << x << endl #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl using namespace std; void solve() { string s; cin >> s; int len = sz(s); rep(i, len - 1) { if ((s[i + 1] == 'A' && s[i] == 'B') || (s[i + 1] == 'B' && s[i] == 'A')) { cout << "Yes"; return; } } cout << "No"; } int main() { FAST #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t; t = 1; // cin>>t; while (t--) { solve(); } return 0; }
// R<3S #include <bits/stdc++.h> #define FAST \ std::ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define DECIMAL(n) \ std::cout << std::fixed; \ std::cout << std::setprecision(n); #define hell 1000000007 #define PI 3.14159265358979323844 #define mp make_pair #define pb push_back #define fi first #define se second #define ALL(v) v.begin(), v.end() #define SORT(v) sort(ALL(v)) #define REVERSE(v) reverse(ALL(v)) #define endl "\n" #define maxc(v) max_element(all(v)) #define minc(v) min_element(all(v)) #define GCD(m, n) __gcd(m, n) #define LCM(m, n) m *(n / GCD(m, n)) #define inputarr(a, n) \ for (int i = 0; i < n; ++i) \ cin >> a[i] #define initarr(a, n, x) \ for (int i = 0; i < n; ++i) \ a[i] = x #define rep(i, n) for (int i = 0; i < (n); ++i) #define repA(i, a, n) for (int i = a; i <= (n); ++i) #define repD(i, a, n) for (int i = a; i >= (n); --i) #define trav(a, x) for (auto &a : x) #define sz(a) (int)a.size() #define sl(a) (int)a.length() #define invect(data, n, commands) \ for (int i = 0; i < n; i++) { \ int tmp; \ cin >> tmp; \ data.pb(tmp); \ commands \ } #define inset(data, n, commands) \ for (int i = 0; i < n; i++) { \ int tmp; \ cin >> tmp; \ data.insert(tmp); \ commands \ } #define ll long long #define ld long double #define pii std::pair<int, int> #define pll std::pair<ll, ll> #define vi vector<int> #define vvi vector<vi> #define vii vector<pii> #define mii map<int, int> #define trace1(x) cerr << #x << ": " << x << endl #define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl #define trace3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl using namespace std; void solve() { string s; cin >> s; int len = sz(s); rep(i, len - 1) { if ((s[i + 1] == 'A' && s[i] == 'B') || (s[i + 1] == 'B' && s[i] == 'A')) { cout << "Yes"; return; } } cout << "No"; } int main() { FAST int t; t = 1; // cin>>t; while (t--) { solve(); } return 0; }
replace
91
96
91
93
0
p02753
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define MOD 1000000007 #define inf 3e18 #define ld long double // #define mp make_pair #define vpll vector<pair<ll, ll>> #define sll set<ll> #define vll vector<ll> #define vld vector<ld> #define vvll vector<vector<ll>> #define vvld vector<vector<ld>> #define pll pair<ll, ll> #define vvpll vector<vector<pair<ll, ll>>> #define pqll priority_queue<ll> #define mll map<ll, ll> #define mlc map<ll, char> #define um unordered_map #define umll um<ll, ll> #define umlc um<ll, char> #define umcl um<char, ll> #define all(x) x.begin(), x.end() #define fi first #define se second #define test \ ll Testcases; \ cin >> Testcases; \ while (Testcases--) #define fastIO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define db(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << " " << name << " : " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } void inp_out() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("debug.txt", "w", stderr); #endif } int main() { fastIO inp_out(); string s; cin >> s; ll a = count(all(s), 'A'); ll b = count(all(s), 'B'); if ((a == 0) || (b == 0)) { cout << "No"; } else { cout << "Yes"; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define MOD 1000000007 #define inf 3e18 #define ld long double // #define mp make_pair #define vpll vector<pair<ll, ll>> #define sll set<ll> #define vll vector<ll> #define vld vector<ld> #define vvll vector<vector<ll>> #define vvld vector<vector<ld>> #define pll pair<ll, ll> #define vvpll vector<vector<pair<ll, ll>>> #define pqll priority_queue<ll> #define mll map<ll, ll> #define mlc map<ll, char> #define um unordered_map #define umll um<ll, ll> #define umlc um<ll, char> #define umcl um<char, ll> #define all(x) x.begin(), x.end() #define fi first #define se second #define test \ ll Testcases; \ cin >> Testcases; \ while (Testcases--) #define fastIO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define db(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << " " << name << " : " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } void inp_out() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("debug.txt", "w", stderr); #endif } int main() { fastIO // inp_out(); string s; cin >> s; ll a = count(all(s), 'A'); ll b = count(all(s), 'B'); if ((a == 0) || (b == 0)) { cout << "No"; } else { cout << "Yes"; } return 0; }
replace
54
56
54
57
0
p02753
C++
Runtime Error
/* क्षमाशील हो रिपु-समक्ष तुम हुये विनत जितना ही दुष्ट कौरवों ने तुमको कायर समझा उतना ही। */ #include <bits/stdc++.h> using namespace std; #define int long long int #define ull unsigned int #define ld long double #define pb push_back #define ff first #define ss second #define S(arr) sort(arr.begin(), arr.end()); #define all(p) p.begin(), p.end() #define RS(arr) sort(arr.rbegin(), arr.rend()); #define R(arr) reverse(arr.begin(), arr.end()); #define pii pair<int, int> #define vpi vector<pii> #define vi vector<int> #define vld vector<ld> #define vvi vector<vector<int>> #define vs vector<string> #define si set<int> #define spi set<pii> #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mii map<int, int> #define mci map<char, int> #define mpi map<pii, int> #define T \ int tcf; \ cin >> tcf; \ while (tcf--) #define que_max(t) priority_queue<t> #define que_min(t) priority_queue<t, vector<t>, greater<t>> #define endl "\n" #define dba(a, l, r) \ for (auto x : a) \ cout << x << " "; \ cout << endl; #define db1(x) cout << #x " = " << x << endl; #define db2(x, y) cout << #x " = " << x << " " << #y " = " << y << endl; #define db3(x, y, z) \ cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl; #define db4(x, y, z, w) \ cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << " " \ << #w " = " << w << endl; #define db5(x, y, z, w, v) \ cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << " " \ << #w " = " << w << " " << #v " = " << v << endl; #define db6(x, y, z, w, v, a) db3(a, y, x) db3(w, v, a) #define p2d(v) \ for (auto a : v) { \ for (auto b : a) \ cout << b << " "; \ cout << endl; \ } #define p1d(v) \ for (auto a : v) \ cout << a << " "; \ cout << endl; #define ppi(v) \ for (auto a : v) \ cout << a.ff << " " << a.ss << endl; // #include <ext/pb_ds/assoc_container.hpp> // using namespace __gnu_pbds; // typedef tree<int, null_type, less<int>, rb_tree_tag, // tree_order_statistics_node_update> pbds; // // *( hsh.find_by_order(k) ) kth smallest, from 0 // // hsh.order_of_key(k) num of ele str less than k // // change less to less_equal for multiset pbds void read(int n = 10) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(n) << fixed; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int M = 1e9 + 7; int M1 = 998244353; #define qqq 4000005 #define pi 3.14159265358979323851 int32_t main() { read(); string str; cin >> str; mii freq; for (auto a : str) freq[a]++; if (freq.size() == 1) { cout << "No"; } else cout << "Yes"; }
/* क्षमाशील हो रिपु-समक्ष तुम हुये विनत जितना ही दुष्ट कौरवों ने तुमको कायर समझा उतना ही। */ #include <bits/stdc++.h> using namespace std; #define int long long int #define ull unsigned int #define ld long double #define pb push_back #define ff first #define ss second #define S(arr) sort(arr.begin(), arr.end()); #define all(p) p.begin(), p.end() #define RS(arr) sort(arr.rbegin(), arr.rend()); #define R(arr) reverse(arr.begin(), arr.end()); #define pii pair<int, int> #define vpi vector<pii> #define vi vector<int> #define vld vector<ld> #define vvi vector<vector<int>> #define vs vector<string> #define si set<int> #define spi set<pii> #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mii map<int, int> #define mci map<char, int> #define mpi map<pii, int> #define T \ int tcf; \ cin >> tcf; \ while (tcf--) #define que_max(t) priority_queue<t> #define que_min(t) priority_queue<t, vector<t>, greater<t>> #define endl "\n" #define dba(a, l, r) \ for (auto x : a) \ cout << x << " "; \ cout << endl; #define db1(x) cout << #x " = " << x << endl; #define db2(x, y) cout << #x " = " << x << " " << #y " = " << y << endl; #define db3(x, y, z) \ cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << endl; #define db4(x, y, z, w) \ cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << " " \ << #w " = " << w << endl; #define db5(x, y, z, w, v) \ cout << #x " = " << x << " " << #y " = " << y << " " << #z " = " << z << " " \ << #w " = " << w << " " << #v " = " << v << endl; #define db6(x, y, z, w, v, a) db3(a, y, x) db3(w, v, a) #define p2d(v) \ for (auto a : v) { \ for (auto b : a) \ cout << b << " "; \ cout << endl; \ } #define p1d(v) \ for (auto a : v) \ cout << a << " "; \ cout << endl; #define ppi(v) \ for (auto a : v) \ cout << a.ff << " " << a.ss << endl; // #include <ext/pb_ds/assoc_container.hpp> // using namespace __gnu_pbds; // typedef tree<int, null_type, less<int>, rb_tree_tag, // tree_order_statistics_node_update> pbds; // // *( hsh.find_by_order(k) ) kth smallest, from 0 // // hsh.order_of_key(k) num of ele str less than k // // change less to less_equal for multiset pbds void read(int n = 10) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(n) << fixed; // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif } int M = 1e9 + 7; int M1 = 998244353; #define qqq 4000005 #define pi 3.14159265358979323851 int32_t main() { read(); string str; cin >> str; mii freq; for (auto a : str) freq[a]++; if (freq.size() == 1) { cout << "No"; } else cout << "Yes"; }
replace
81
85
81
85
0
p02753
Python
Runtime Error
s = input() Q = int(input()) flag = True # flagがTrueのとき、偶数回数の反転が行われている cnt = 0 for _ in range(Q): query = list(map(str, input().split())) # tmp.append(query) if len(query) == 1: # 1のqueryのとき cnt += 1 if flag: flag = False else: flag = True else: f, c = query[1], query[2] if f == "1": # 先頭に追加するもの if flag: s = c + s # 偶数回の反転なら素直に先頭に追加する else: s += c # 奇数会の反転なら後ろに追加する else: # 末尾に追加する if flag: s += c else: s = c + s if cnt % 2 == 1 and cnt != 0: s = s[::-1] print(s)
S = input() if "A" in S and "B" in S: print("Yes") else: print("No")
replace
0
29
0
5
EOFError: EOF when reading a line
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02753/Python/s625684460.py", line 2, in <module> Q = int(input()) EOFError: EOF when reading a line
p02753
Python
Runtime Error
S = list(input()) Q = int(input()) for i in range(Q): query = input().split() if int(query[0]) == 1: S.reverse() else: if int(query[1]) == 1: S.insert(0, query[2]) else: S.append(query[2]) print("".join(S))
S = input() if len(set(S)) == 2: print("Yes") else: print("No")
replace
0
12
0
5
EOFError: EOF when reading a line
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02753/Python/s642674593.py", line 2, in <module> Q = int(input()) EOFError: EOF when reading a line
p02753
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string s[3]; cin >> s[3]; if (s[0] == s[1] && s[1] == s[2]) { cout << "No"; } else { cout << "Yes"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s; for (int i = 0; i < 3; i++) { cin >> s[i]; } if ((s[0] == s[1]) && (s[1] == s[2])) { cout << "No"; } else { cout << "Yes"; } return 0; }
replace
3
6
3
8
-6
*** stack smashing detected ***: terminated
p02753
Python
Runtime Error
s = int(input()) if s in "AAA-BBB": print("No") else: print("Yes")
s = input() if s in "AAA-BBB": print("No") else: print("Yes")
replace
0
1
0
1
ValueError: invalid literal for int() with base 10: 'ABA'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02753/Python/s787865958.py", line 1, in <module> s = int(input()) ValueError: invalid literal for int() with base 10: 'ABA'
p02753
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string S = 0; cin >> S; if (S[0] == S[1] && S[1] == S[2]) { cout << "No" << endl; } else { cout << "Yes" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; if (S[0] == S[1] && S[1] == S[2]) { cout << "No" << endl; } else { cout << "Yes" << endl; } }
replace
4
5
4
5
-6
terminate called after throwing an instance of 'std::logic_error' what(): basic_string: construction from null is not valid
p02753
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { string s; char AB[3] = "AB"; cin >> s; int n_a = 0; int n_b = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == AB[0]) { n_a++; } else { n_b++; } } if (n_a == 0 || n_b == 0) { cout << "No" << endl; } else { cout << "Yes" << endl; } return 1; }
#include <iostream> #include <string> using namespace std; int main() { string s; char AB[3] = "AB"; cin >> s; int n_a = 0; int n_b = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == AB[0]) { n_a++; } else { n_b++; } } if (n_a == 0 || n_b == 0) { cout << "No" << endl; } else { cout << "Yes" << endl; } return 0; }
replace
26
27
26
27
1
p02753
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; if (S.at(1) == S.at(2) && S.at(2) == S.at(3)) { cout << "No" << endl; } else { cout << "Yes" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; if (S == "AAA") { cout << "No" << endl; } else if (S == "BBB") { cout << "No" << endl; } else { cout << "Yes" << endl; } }
replace
7
8
7
10
0
p02753
Python
Runtime Error
s = input() if s[0] == s[1] and s[2] == s[3] and s[3] == s[1]: print("No") else: print("Yes")
s = input() if s[0] == s[1] and s[1] == s[2] and s[2] == s[0]: print("No") else: print("Yes")
replace
2
3
2
3
0
p02754
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, A, B, ans = 0; cin >> N >> A >> B; ans += A * (N / (A + B)); ans += min(A, N % (A + B)); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t N, A, B, ans = 0; cin >> N >> A >> B; ans += A * (N / (A + B)); ans += min(A, N % (A + B)); cout << ans << endl; }
replace
4
5
4
5
0
p02754
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long int lli; int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); lli i, n, a, b, c = 0; cin >> n >> a >> b; for (i = 0; n > 0; ++i) { if (i % 2 == 0) { if (n - a > 0) { n -= a; c += a; } else { c += n; n = 0; } } else { if (n - b > 0) { n -= b; } else { n = 0; } } } cout << c; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int lli; int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr); lli i, n, a, b, c = 0; cin >> n >> a >> b; c += (n / (a + b)) * a; n %= (a + b); if (n > a) c += a; else c += n; cout << c; return 0; }
replace
9
26
9
15
TLE
p02754
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; using V = vector<ll>; #define _GLIBCXX_DEBUG #define rep(i, a, b) for (int i = a; i < b; i++) #define ALL(v) v.begin(), v.end() int main() { ll n, a, b; cin >> n >> a >> b; string s = {}; ll ans = 0; while (1) { rep(i, 0, a) { s.push_back('b'); ans++; } rep(i, 0, b) s.push_back('r'); if (s.size() >= n) break; if (s.size() + b > n) { rep(i, 0, n - s.size()) ans++; break; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using V = vector<ll>; #define _GLIBCXX_DEBUG #define rep(i, a, b) for (int i = a; i < b; i++) #define ALL(v) v.begin(), v.end() int main() { ll n, a, b; cin >> n >> a >> b; ll ans = 0, rem; ans += a * (n / (a + b)); rem = n % (a + b); ans += min(rem, a); cout << ans << endl; }
replace
11
26
11
15
TLE
p02754
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, blue, red, num, blue_red, nokori; cin >> N >> blue >> red; blue_red = blue + red; nokori = (N % (blue_red)); num = N / (blue_red)*blue + min(blue, nokori); cout << num << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t N, blue, red, num, blue_red, nokori; cin >> N >> blue >> red; blue_red = blue + red; nokori = (N % (blue_red)); num = N / (blue_red)*blue + min(blue, nokori); cout << num << endl; }
replace
4
5
4
5
0
p02754
C++
Runtime Error
#include <iostream> using namespace std; int main() { int n, a, b, loop = 0, rem = 0; cin >> n >> a >> b; loop = n / (a + b); rem = n % (a + b); if (rem > a) rem = a; cout << loop * a + rem << endl; }
#include <iostream> using namespace std; int main() { unsigned long long n, a, b, loop = 0, rem = 0; cin >> n >> a >> b; loop = n / (a + b); rem = n % (a + b); if (rem > a) rem = a; cout << loop * a + rem << endl; }
replace
3
4
3
4
0
p02754
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, A, B, loop; cin >> N >> A >> B; loop = N / (A + B); cout << (loop * A + min(N % (A + B), A)); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int N, A, B, loop; cin >> N >> A >> B; loop = N / (A + B); cout << (loop * A + min(N % (A + B), A)); return 0; }
replace
3
4
3
4
0
p02754
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, a, b, c, res; int main() { cin >> n >> a >> b; res = res + n / (a + b) * a; c = n % (a + b); if (c > a) { cout << res + a << endl; } else { cout << res + c << endl; } }
#include <bits/stdc++.h> using namespace std; long long n, a, b, c, res; int main() { cin >> n >> a >> b; res = res + n / (a + b) * a; c = n % (a + b); if (c > a) { cout << res + a << endl; } else { cout << res + c << endl; } }
replace
2
4
2
3
0
p02754
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n, a, b; cin >> n >> a >> b; ll ans = 0; while (1) { if (n >= a) { ans += a; } else { ans += n; } if (a + b >= n) { break; } n -= a + b; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n, a, b; cin >> n >> a >> b; ll amari = (n % (a + b)); ll ans = (n / (a + b)) * a; if (amari > a) { ans += a; } else { ans += amari; } cout << ans << endl; }
replace
7
19
7
13
TLE
p02754
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; int main() { int n, a, b; cin >> n >> a >> b; int ans = 0; int A = n / (a + b); ans += A * a; int B = n % (a + b); ans += B; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; int main() { ll N, A, B; cin >> N >> A >> B; ll ans = 0; if (N > A + B) { ans += (N / (A + B)) * A; if (N % (A + B) <= A) ans += N % (A + B); else ans += A; } else { ans += A; } if (N < A) ans = N; cout << ans << endl; }
replace
6
13
6
20
0
p02754
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, A, B; cin >> N >> A >> B; if (N % (A + B) >= A) { cout << (N / (A + B)) * A + A << endl; } else { cout << (N / (A + B)) * A + N % (A + B) << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long N, A, B; cin >> N >> A >> B; if (N % (A + B) >= A) { cout << (N / (A + B)) * A + A << endl; } else { cout << (N / (A + B)) * A + N % (A + B) << endl; } return 0; }
replace
4
5
4
5
0
p02754
C++
Runtime Error
#include <bits/stdc++.h> #include <numeric> #define ll long long #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define pr pair<int, int> using namespace std; const ll mod = 1000000007; const ll INF = (ll)1000000007 * 1000000007; // #define DEBUG #ifdef DEBUG #define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl; #else #define PRINT(A) #endif template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } // int a[10010][10010], b[1000]; // int dp[10010][3]; int S[10][1000]; void chAllVal(int before, int after, int h, int w) { rep(i, h * w) { if (S[i / w][i % w] == before) { S[i / w][i % w] = after; } } } int main() { int N, A, B; cin >> N >> A >> B; cout << N / (A + B) * A + min(A, N % (A + B)) << endl; return 0; }
#include <bits/stdc++.h> #include <numeric> #define ll long long #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define pr pair<int, int> using namespace std; const ll mod = 1000000007; const ll INF = (ll)1000000007 * 1000000007; // #define DEBUG #ifdef DEBUG #define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl; #else #define PRINT(A) #endif template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } // int a[10010][10010], b[1000]; // int dp[10010][3]; int S[10][1000]; void chAllVal(int before, int after, int h, int w) { rep(i, h * w) { if (S[i / w][i % w] == before) { S[i / w][i % w] = after; } } } int main() { ll N, A, B; cin >> N >> A >> B; cout << N / (A + B) * A + min(A, N % (A + B)) << endl; return 0; }
replace
50
51
50
51
0
p02754
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, A, B; cin >> N >> A >> B; cout << N / (A + B) * A + min(N - N / (A + B) * (A + B), A) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t N, A, B; cin >> N >> A >> B; cout << N / (A + B) * A + min(N - N / (A + B) * (A + B), A) << endl; }
replace
5
6
5
6
0
p02754
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; int main() { ll N, A, B; cin >> N >> A >> B; ll cnt = 0; do { if (N < A) { cnt += N; break; } else { N -= A; cnt += A; } N -= B; } while (N >= 0); cout << cnt << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; int main() { ll N, A, B; cin >> N >> A >> B; ll cnt = 0; ll cntr = (ll)(N / (A + B)); ll amari = N - cntr * (A + B); if (amari < A) { cnt = cntr * A + amari; } else { cnt = (cntr + 1) * A; } cout << cnt << endl; }
replace
9
19
9
16
TLE
p02754
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; int n, a, b; int main() { cin >> n >> a >> b; cout << n / (a + b) * a + min(a, n % (a + b)); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; long long n, a, b; int main() { cin >> n >> a >> b; cout << n / (a + b) * a + min(a, n % (a + b)); return 0; }
replace
5
6
5
6
0
p02754
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, c, d, ans, j, p, i; cin >> a >> b >> c; ans = 0; p = 0; i = 1; while (a != 0) { if (i % 2 != 0) { if (a > b) { ans += b; a -= b; } else { ans += a; a -= a; } } else { if (a > c) { a -= c; } else { a -= a; } } i++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b, c, d, ans, j, p, i; cin >> a >> b >> c; i = a / (b + c); j = a % (b + c); ans = b * i + min(j, b); cout << ans << endl; }
replace
5
26
5
8
TLE
p02754
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, A, B; cin >> N >> A >> B; if (N % (A + B) > A) { cout << (N / (A + B)) * A + A << endl; } else if (N % (A + B) <= A) { cout << ((N / A + B)) * A + (N % (A + B)) << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { long long n, a, b; cin >> n >> a >> b; if (n % (a + b) >= a) { cout << (n / (a + b)) * a + a << endl; } else { cout << (n / (a + b)) * a + n % (a + b) << endl; } }
replace
4
10
4
10
0
p02754
C++
Runtime Error
// #include<bits/stdc++.h> #include <algorithm> #include <assert.h> #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <stack> #include <vector> using namespace std; #define de_x(x) cout << #x << "->debug_val: " << x << endl; #define de_ve(x) \ for (auto it : x) \ cout << it << " "; #define rep(i, a, n) for (int i = a; i < n; i++) #define _rep(i, a, n) for (int i = a; i <= n; i++) #define per(i, a, n) for (int i = n - 1; i >= a; i--) #define pb push_back #define mp make_pair #define fi first #define se second #define SZ(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() typedef long long ll; typedef vector<int> VI; typedef pair<int, int> PII; typedef double db; // std::mt19937 mrand(random_device{}()); // int rnd(int x) { return mrand() % x ; } const ll mod = 1e7; ll ksm(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } int _, n, m; /***********************/ void run() {} int main() { // for(scanf("%d",&_);_;_--) run(); int a, b, ans = 0, res; cin >> n >> a >> b; ans = n / (a + b) * a; res = n % (a + b); ans += min(res, a); cout << ans << endl; return 0; }
// #include<bits/stdc++.h> #include <algorithm> #include <assert.h> #include <cstdio> #include <cstring> #include <iostream> #include <queue> #include <stack> #include <vector> using namespace std; #define de_x(x) cout << #x << "->debug_val: " << x << endl; #define de_ve(x) \ for (auto it : x) \ cout << it << " "; #define rep(i, a, n) for (int i = a; i < n; i++) #define _rep(i, a, n) for (int i = a; i <= n; i++) #define per(i, a, n) for (int i = n - 1; i >= a; i--) #define pb push_back #define mp make_pair #define fi first #define se second #define SZ(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() typedef long long ll; typedef vector<int> VI; typedef pair<int, int> PII; typedef double db; // std::mt19937 mrand(random_device{}()); // int rnd(int x) { return mrand() % x ; } const ll mod = 1e7; ll ksm(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } int _, n, m; /***********************/ void run() {} int main() { // for(scanf("%d",&_);_;_--) run(); ll x, y, z; cin >> x >> y >> z; cout << x / (y + z) * y + min(x % (z + y), y) << endl; return 0; }
replace
47
53
47
50
0
p02754
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vii; typedef vector<pll> vll; #define mem0(x) memset(x, 0, sizeof(x)) #define asort(x) sort(x.begin(), x.end()); #define dsort(x, t) sort(x.begin(), a.end(), greater<t>()); #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); #define MINS(m, s) m.insert(mp(s, 1)); #define MFIN(m, s) m.find(s) != m.end() #define mp make_pair #define pb push_back #define INF (1 << 29) const int mod = 1000000007; int main() { ll N, A, B, ans; ans = 0; cin >> N >> A >> B; while (N > 0) { N -= A; ans += A; if (N <= 0) { ans = ans + N; break; } N -= B; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vii; typedef vector<pll> vll; #define mem0(x) memset(x, 0, sizeof(x)) #define asort(x) sort(x.begin(), x.end()); #define dsort(x, t) sort(x.begin(), a.end(), greater<t>()); #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); #define MINS(m, s) m.insert(mp(s, 1)); #define MFIN(m, s) m.find(s) != m.end() #define mp make_pair #define pb push_back #define INF (1 << 29) const int mod = 1000000007; int main() { ll N, A, B, ans; ans = 0; cin >> N >> A >> B; ans = N / (A + B) * A + min(N % (A + B), A); cout << ans << endl; return 0; }
replace
26
35
26
27
TLE
p02754
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <string> using namespace std; #define ll long long int main() { ll n, a, b; cin >> n >> a >> b; ll i = 0, k = 0, ans = 0; while (i < n) { if ((k % 2) == 0) { if (i + a < n) { i += a; ans += a; } else { ans += (n - i); i = n; } } else { if (i + b < n) { i += b; // ans+=a; } else { // ans+=(n-i); i = n; } } k++; } cout << ans; }
#include <algorithm> #include <iostream> #include <string> using namespace std; #define ll long long int main() { ll n, a, b; cin >> n >> a >> b; ll i = 0, k = 0, ans = 0; ll q = n / (a + b); ll r = n % (a + b); ans = q * a; if (r > a) r = a; ans += r; cout << ans; }
replace
9
30
9
15
TLE