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
p03026
Python
Runtime Error
def inpl(): return list(map(int, input().split())) class UnionFind: def __init__(self, N): # par = parent self.par = [i for i in range(N)] self.N = N self.hop = {i: -1 for i in range(N)} self.adj = [[] for i in range(N)] return def root(self, x): if self.par[x] == x: return x else: self.par[x] = self.root(self.par[x]) return self.par[x] def same(self, x, y): return self.root(x) == self.root(y) def union(self, x, y): x = self.root(x) y = self.root(y) if x == y: return False self.par[x] = min(x, y) self.par[y] = min(x, y) return True def find_root(self): for i in range(self.N): if i == self.root(i): return i return def dfs(self, i): for nh in self.adj[i]: if self.hop[nh] != -1: continue else: self.hop[nh] = self.hop[i] + 1 self.dfs(nh) return N = int(input()) uf = UnionFind(N) AB = [[0, 0] for i in range(N - 1)] for i in range(N - 1): a, b = inpl() a -= 1 b -= 1 AB[i][0] = a AB[i][1] = b uf.adj[a].append(b) uf.adj[b].append(a) C = inpl() for a, b in AB: uf.union(a, b) root_num = uf.find_root() uf.hop[root_num] = 0 uf.dfs(root_num) dic2 = sorted(uf.hop.items(), key=lambda x: x[1], reverse=True) ans = [0 for i in range(N)] for i, k in enumerate(dic2): ans[k[0]] = i C.sort() print(sum(C[:-1])) for i in range(N): if i != 0: print(" ", end="") print(C[ans[i]], end="") print("")
import sys sys.setrecursionlimit(110000) def inpl(): return list(map(int, input().split())) class UnionFind: def __init__(self, N): # par = parent self.par = [i for i in range(N)] self.N = N self.hop = {i: -1 for i in range(N)} self.adj = [[] for i in range(N)] return def root(self, x): if self.par[x] == x: return x else: self.par[x] = self.root(self.par[x]) return self.par[x] def same(self, x, y): return self.root(x) == self.root(y) def union(self, x, y): x = self.root(x) y = self.root(y) if x == y: return False self.par[x] = min(x, y) self.par[y] = min(x, y) return True def find_root(self): for i in range(self.N): if i == self.root(i): return i return def dfs(self, i): for nh in self.adj[i]: if self.hop[nh] != -1: continue else: self.hop[nh] = self.hop[i] + 1 self.dfs(nh) return N = int(input()) uf = UnionFind(N) AB = [[0, 0] for i in range(N - 1)] for i in range(N - 1): a, b = inpl() a -= 1 b -= 1 AB[i][0] = a AB[i][1] = b uf.adj[a].append(b) uf.adj[b].append(a) C = inpl() for a, b in AB: uf.union(a, b) root_num = uf.find_root() uf.hop[root_num] = 0 uf.dfs(root_num) dic2 = sorted(uf.hop.items(), key=lambda x: x[1], reverse=True) ans = [0 for i in range(N)] for i, k in enumerate(dic2): ans[k[0]] = i C.sort() print(sum(C[:-1])) for i in range(N): if i != 0: print(" ", end="") print(C[ans[i]], end="") print("")
insert
0
0
0
5
0
p03026
C++
Time Limit Exceeded
/*********************************************************** *This code By @1353055672(Ligen) * *[Warning]You're not excepted to understand this code! * *STOI GDOI APIO CTS NOIP 2019 RP++ * ***********************************************************/ // #pragma GCC optimize(3) // #pragma comment(linker, "/STACK:102400000,102400000") #include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <vector> #define ll long long #define ull unsigned long long #define mn 20020 #define Max(x, y) ((x > y) ? x : y) #define Min(x, y) ((x < y) ? x : y) #define Abs(x) (((x) < (0)) ? (-(x)) : (x)) #define infll (ll)(1e18) #define infint (int)(1 << 30) #define mod (int)(1e9 + 7) #define FOR(a, b, c) for (register ll a = b; a <= c; a++) #define FORD(a, b, c) for (register ll a = b; a >= c; a--) using namespace std; inline ll read() { ll x = 0, f = 1; char c; for (c = getchar(); c < '0' || c > '9'; f = ((c == '-') ? -1 : f), c = getchar()) ; for (; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = getchar()) ; return x * f; } template <typename T> inline void write(T a) { if (a == 0) { putchar('0'); return; } if (a < 0) putchar('-'), a = -a; char c1[120]; int h = 0; while (a) c1[++h] = a % 10 + '0', a /= 10; FORD(i, h, 1) putchar(c1[i]); } inline void write_() { return; } template <typename T, typename... Args> inline void write_(T a, Args... b) { write(a); putchar(' '); write_(b...); } inline void writeln() { putchar('\n'); return; } template <typename T, typename... Args> inline void writeln(T a, Args... b) { write(a); putchar(' '); writeln(b...); } // need c++11 // inline void write(ll a){ // if(a==0){putchar('0');return;}if(a<0)putchar('-'),a=-a;char c1[120];int // h=0; while(a)c1[++h]=a%10+'0',a/=10;FORD(i,h,1)putchar(c1[i]); // } // inline void write_(ll a){write(a);putchar(' ');} // inline void writeln(ll a){write(a);putchar('\n');} inline ll gcd(ll a, ll b) { return a == 0 ? b : gcd(b % a, a); } inline ll lcm(ll a, ll b) { return 1ll * a / gcd(a, b) * b; } inline ll Pow(ll n, ll a) { ll b = 1; while (a) { if (a & 1) b = 1ll * b * n % mod; n = 1ll * n * n % mod; a >>= 1; } return b; } //---------------------Head Files--------------------------// int n, fir[mn], nxt[mn], y[mn], a[mn], x, yy, tot, In[mn], ans, d[mn], now, mx, num, an[mn]; inline void adde(int x, int yy) { nxt[++tot] = fir[x]; fir[x] = tot; y[tot] = yy; ++In[x]; } struct node { int x, c; }; inline bool operator<(const node &a, const node &b) { return a.c < b.c; } priority_queue<node> q[mn]; inline void dfs(int x, int fa) { d[x] = a[now--]; for (int i = fir[x]; i; i = nxt[i]) if (y[i] != fa) q[x].push((node){y[i], In[y[i]]}); int yy; while (!q[x].empty()) { yy = q[x].top().x; q[x].pop(); dfs(yy, x); num += Min(d[x], d[yy]); } } signed main() { n = read(); FOR(i, 2, n) x = read(), yy = read(), adde(x, yy), adde(yy, x); FOR(i, 1, n) a[i] = read(); sort(a + 1, a + 1 + n); FOR(i, 1, n) mx = Max(mx, In[i]); FOR(i, 1, n) if (In[i] == mx) { now = n; num = 0; dfs(i, 0); if (num > ans) { ans = num; FOR(j, 1, n) an[j] = d[j]; } } writeln(ans); FOR(i, 1, n) write_(an[i]); puts(""); return 0; }
/*********************************************************** *This code By @1353055672(Ligen) * *[Warning]You're not excepted to understand this code! * *STOI GDOI APIO CTS NOIP 2019 RP++ * ***********************************************************/ // #pragma GCC optimize(3) // #pragma comment(linker, "/STACK:102400000,102400000") #include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <vector> #define ll long long #define ull unsigned long long #define mn 20020 #define Max(x, y) ((x > y) ? x : y) #define Min(x, y) ((x < y) ? x : y) #define Abs(x) (((x) < (0)) ? (-(x)) : (x)) #define infll (ll)(1e18) #define infint (int)(1 << 30) #define mod (int)(1e9 + 7) #define FOR(a, b, c) for (register ll a = b; a <= c; a++) #define FORD(a, b, c) for (register ll a = b; a >= c; a--) using namespace std; inline ll read() { ll x = 0, f = 1; char c; for (c = getchar(); c < '0' || c > '9'; f = ((c == '-') ? -1 : f), c = getchar()) ; for (; c >= '0' && c <= '9'; x = x * 10 + c - '0', c = getchar()) ; return x * f; } template <typename T> inline void write(T a) { if (a == 0) { putchar('0'); return; } if (a < 0) putchar('-'), a = -a; char c1[120]; int h = 0; while (a) c1[++h] = a % 10 + '0', a /= 10; FORD(i, h, 1) putchar(c1[i]); } inline void write_() { return; } template <typename T, typename... Args> inline void write_(T a, Args... b) { write(a); putchar(' '); write_(b...); } inline void writeln() { putchar('\n'); return; } template <typename T, typename... Args> inline void writeln(T a, Args... b) { write(a); putchar(' '); writeln(b...); } // need c++11 // inline void write(ll a){ // if(a==0){putchar('0');return;}if(a<0)putchar('-'),a=-a;char c1[120];int // h=0; while(a)c1[++h]=a%10+'0',a/=10;FORD(i,h,1)putchar(c1[i]); // } // inline void write_(ll a){write(a);putchar(' ');} // inline void writeln(ll a){write(a);putchar('\n');} inline ll gcd(ll a, ll b) { return a == 0 ? b : gcd(b % a, a); } inline ll lcm(ll a, ll b) { return 1ll * a / gcd(a, b) * b; } inline ll Pow(ll n, ll a) { ll b = 1; while (a) { if (a & 1) b = 1ll * b * n % mod; n = 1ll * n * n % mod; a >>= 1; } return b; } //---------------------Head Files--------------------------// int n, fir[mn], nxt[mn], y[mn], a[mn], x, yy, tot, In[mn], ans, d[mn], now, mx, num, an[mn]; inline void adde(int x, int yy) { nxt[++tot] = fir[x]; fir[x] = tot; y[tot] = yy; ++In[x]; } struct node { int x, c; }; inline bool operator<(const node &a, const node &b) { return a.c < b.c; } priority_queue<node> q[mn]; inline void dfs(int x, int fa) { d[x] = a[now--]; for (int i = fir[x]; i; i = nxt[i]) if (y[i] != fa) q[x].push((node){y[i], In[y[i]]}); int yy; while (!q[x].empty()) { yy = q[x].top().x; q[x].pop(); dfs(yy, x); num += Min(d[x], d[yy]); } } signed main() { n = read(); FOR(i, 2, n) x = read(), yy = read(), adde(x, yy), adde(yy, x); FOR(i, 1, n) a[i] = read(); sort(a + 1, a + 1 + n); FOR(i, 1, n) mx = Max(mx, In[i]); FOR(i, 1, n) if (In[i] == mx) { now = n; num = 0; dfs(i, 0); if (num > ans) { ans = num; FOR(j, 1, n) an[j] = d[j]; } break; } writeln(ans); FOR(i, 1, n) write_(an[i]); puts(""); return 0; }
insert
132
132
132
133
TLE
p03026
C++
Time Limit Exceeded
// Copyright lzt #include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <stdio.h> #include <string> #include <vector> using namespace std; typedef long long ll; typedef std::pair<int, int> pii; typedef long double ld; typedef unsigned long long ull; typedef std::pair<long long, long long> pll; #define fi first #define se second #define pb push_back #define mp make_pair #define rep(i, j, k) for (register int i = (int)(j); i <= (int)(k); i++) #define rrep(i, j, k) for (register int i = (int)(j); i >= (int)(k); i--) #define Debug(...) fprintf(stderr, __VA_ARGS__) inline ll read() { ll x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch <= '9' && ch >= '0') { x = 10 * x + ch - '0'; ch = getchar(); } return x * f; } const int maxn = 100100; int n, cnt; vector<int> G[maxn]; int num[maxn], a[maxn]; ll ans; int an[maxn]; void dfs(int u) { vector<int> vec; rep(i, 0, G[u].size() - 1) if (!a[G[u][i]]) { a[G[u][i]] = num[++cnt]; vec.pb(G[u][i]); } rep(i, 0, vec.size() - 1) { dfs(vec[i]); } } void work() { n = read(); rep(i, 1, n - 1) { int x = read(), y = read(); G[x].pb(y); G[y].pb(x); } rep(i, 1, n) num[i] = read(); sort(num + 1, num + n + 1); reverse(num + 1, num + n + 1); rep(i, 1, n) { memset(a, 0, sizeof(a)); cnt = 1; a[i] = num[1]; dfs(i); ll nw = 0; rep(j, 1, n) rep(k, 0, G[j].size() - 1) { if (j < G[j][k]) nw += min(a[j], a[G[j][k]]); } if (nw > ans) { ans = nw; rep(i, 1, n) an[i] = a[i]; } } printf("%lld\n", ans); rep(i, 1, n) printf("%d ", an[i]); } int main() { #ifdef LZT freopen("in", "r", stdin); #endif work(); #ifdef LZT Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC); #endif }
// Copyright lzt #include <algorithm> #include <cmath> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <map> #include <queue> #include <set> #include <stdio.h> #include <string> #include <vector> using namespace std; typedef long long ll; typedef std::pair<int, int> pii; typedef long double ld; typedef unsigned long long ull; typedef std::pair<long long, long long> pll; #define fi first #define se second #define pb push_back #define mp make_pair #define rep(i, j, k) for (register int i = (int)(j); i <= (int)(k); i++) #define rrep(i, j, k) for (register int i = (int)(j); i >= (int)(k); i--) #define Debug(...) fprintf(stderr, __VA_ARGS__) inline ll read() { ll x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch <= '9' && ch >= '0') { x = 10 * x + ch - '0'; ch = getchar(); } return x * f; } const int maxn = 100100; int n, cnt; vector<int> G[maxn]; int num[maxn], a[maxn]; ll ans; int an[maxn]; void dfs(int u) { vector<int> vec; rep(i, 0, G[u].size() - 1) if (!a[G[u][i]]) { a[G[u][i]] = num[++cnt]; vec.pb(G[u][i]); } rep(i, 0, vec.size() - 1) { dfs(vec[i]); } } void work() { n = read(); rep(i, 1, n - 1) { int x = read(), y = read(); G[x].pb(y); G[y].pb(x); } rep(i, 1, n) num[i] = read(); sort(num + 1, num + n + 1); reverse(num + 1, num + n + 1); rep(i, 1, 1) { memset(a, 0, sizeof(a)); cnt = 1; a[i] = num[1]; dfs(i); ll nw = 0; rep(j, 1, n) rep(k, 0, G[j].size() - 1) { if (j < G[j][k]) nw += min(a[j], a[G[j][k]]); } if (nw > ans) { ans = nw; rep(i, 1, n) an[i] = a[i]; } } printf("%lld\n", ans); rep(i, 1, n) printf("%d ", an[i]); } int main() { #ifdef LZT freopen("in", "r", stdin); #endif work(); #ifdef LZT Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC); #endif }
replace
68
69
68
69
TLE
p03026
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define fo(a, b) for (int a = 0; a < b; a++) #define Sort(a) sort(a.begin(), a.end()) #define rev(a) reverse(a.begin(), a.end()) #define fi first #define se second #define sz size() #define bgn begin() #define en end() #define pb push_back #define pp() pop_back() #define V vector #define P pair #define yuko(a) setprecision(a) #define uni(a) a.erase(unique(a.begin(), a.end()), a.end()) #define Q queue #define pri priority_queue #define Pri priority_queue<int, vector<int>, greater<int>> #define PriP \ priority_queue<P<int, int>, vector<P<int, int>>, greater<P<int, int>>> #define ff first.first #define fs first.second #define sf second.first #define ss second.second #define all(a) (a).begin(), (a).end() #define elif else if int low(V<int> a, int b) { decltype(a)::iterator c = lower_bound(a.begin(), a.end(), b); int d = c - a.bgn; return d; } int upp(V<int> a, int b) { decltype(a)::iterator c = upper_bound(a.begin(), a.end(), b); int d = c - a.bgn; return d; } template <class T> void cou(vector<vector<T>> a) { int b = a.size(); int c = a[0].size(); fo(i, b) { fo(j, c) { cout << a[i][j]; if (j == c - 1) cout << endl; else cout << ' '; } } } int wari(int a, int b) { if (a % b == 0) return a / b; else return a / b + 1; } int keta(int a) { double b = a; b = log10(b); int c = b; return c + 1; } int souwa(int a) { return a * (a + 1) / 2; } int gcm(int a, int b) { if (a % b == 0) return b; return gcm(b, a % b); } bool prime(int a) { if (a < 2) return false; else if (a == 2) return true; else if (a % 2 == 0) return false; for (int i = 3; i <= sqrt(a) + 1; i += 2) { if (a % i == 0) return false; } return true; } struct Union { vector<int> par; Union(int a) { par = vector<int>(a, -1); } int find(int a) { if (par[a] < 0) return a; else return par[a] = find(par[a]); } bool same(int a, int b) { return find(a) == find(b); } int Size(int a) { return -par[find(a)]; } void unite(int a, int b) { a = find(a); b = find(b); if (a == b) return; if (Size(b) > Size(a)) swap<int>(a, b); par[a] += par[b]; par[b] = a; } }; int ketas(int a) { string b = to_string(a); int c = 0; fo(i, keta(a)) { c += b[i] - '0'; } return c; } bool fe(int a, int b) { a %= 10; b %= 10; if (a == 0) a = 10; if (b == 0) b = 10; if (a > b) return true; else return false; } int INF = 1000000007; struct edge { int s, t, d; }; V<int> mojisyu(string a) { V<int> b(26, 0); fo(i, a.sz) { b[a[i] - 'a']++; } return b; } int wa2(int a) { if (a % 2 == 1) return a / 2; return a / 2 - 1; } /*signed main(){ int a,b,c; cin>>a>>b>>c; V<V<edge>> d(a); fo(i,b){ edge e; cin>>e.s>>e.t>>e.d; d[e.s].pb(e); } V<int> e(a,INF); e[c]=0; priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f; f.push({0,c}); int h=INF; while(!f.empty()){ P<int,int> g; g=f.top(); f.pop(); int v = g.second, i = g.first; for(edge l : d[v]){ if(e[l.t] > i + l.d){ e[l.t] = i + l.d; f.push({i+l.d , l.t}); } } } fo(i,a){ if(e[i]==INF) cout<<"INF"<<endl; else cout<<e[i]<<endl; } } ?*/ int nCr(int n, int r) { int a = 1; r = min(r, n - r); for (int i = n; i > n - r; i--) { a *= i; a /= n - i + 1; } return a; } /*void sea(int x,int y){ if(x<0||a<=x||y<0||b<=y||c[x][y]=='#') return; if(d[x][y]) return; d[x][y]++; sea(x+1,y); sea(x-1,y); sea(x,y+1); sea(x,y-1); }*/ int kaijou(int a) { int b = 1; fo(i, a) b *= i + 1; return b; } int nPr(int a, int b) { if (a < b) return 0; if (b == 0) return 1; int c = 1; for (int i = a; i > a - b; i--) { c *= i; c %= INF; } return c; } int modinv(int a, int m) { int b = m, u = 1, v = 0; while (b) { int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } int lcm(int a, int b) { int c = modinv(gcm(a, b), INF); return ((a * c) % INF) * (b % INF) % INF; } int MOD = INF; int fac[1000010], finv[1000010], inv[1000010]; // テーブルを作る前処理 // 先にCOMinit()で前処理をする // ABC145D void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < 1000010; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 int COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } bool naka(int a, int b, V<V<char>> c) { return (a >= 0 && b >= 0 && a < c.sz && b < c[0].sz); } V<P<int, int>> mawari8 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}, {-1, -1}, {1, 1}, {1, -1}, {-1, -1}}; int inf = 1000000000000000007; /* signed main(){ int a,b,c; cin>>a>>b>>c; V<V<edge>> d(a); fo(i,b){ edge e; cin>>e.s>>e.t>>e.d; d[e.s].pb(e); } V<int> e(a,INF); e[c]=0; priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f; f.push({0,c}); int h=INF; while(!f.empty()){ P<int,int> g; g=f.top(); f.pop(); int v = g.second, i = g.first; for(edge l : d[v]){ if(e[l.t] > i + l.d){ e[l.t] = i + l.d; f.push({i+l.d , l.t}); } } } fo(i,a){ if(e[i]==INF) cout<<"INF"<<endl; else cout<<e[i]<<endl; } }*/ V<P<int, int>> mawari4 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}}; // 最短経路の表 a(全部INFで初期化) // 縦横 x,y // 迷路 f // スタートsx,sy // ゴールgx,gy // 文字はgから使おうね /*int bfs_haba(){ Q<P<int,int>> b; a[sx][sy]=0; b.push({sx,sy}); while(!b.empty()){ P<int,int> c=b.front(); b.pop(); if(c.fi==gx&&c.se==gy){ break; } fo(i,4){ int d=c.fi+mawari4[i].fi; int e=c.se+mawari4[i].se; if(0<=d&&0<=e&&d<x&&e<y&&f[d][e]!='#'&&a[d][e]==INF){ b.push({d,e}); a[d][e]=1+a[c.fi][c.se]; } } } return a[gx][gy]; }*/ V<int> onajibubun(string a) { V<int> b(a.sz); for (int i = 1, j = 0; i < a.sz; i++) { if (i + b[i - j] < j + b[j]) b[i] = b[i - j]; else { int c = max<int>(0, j + b[j] - i); while (i + c < a.sz && a[c] == a[i + c]) c++; b[i] = c; j = i; } } b[0] = a.sz; return b; } // 各頂点ごとにどこに辺が出てるかの表がc // 各頂点ごとの色を表すV<int>(頂点数max)のcolorを用意する // aはどこ塗るか、bは何で塗るかなので、(0,1,c)でよぶとおけ V<int> color(205); bool nibu_hantei(int a, int b, V<V<int>> c) { color[a] = b; fo(i, c[a].sz) { if (b == color[c[a][i]]) return false; if (color[c[a][i]] == 0 && !nibu_hantei(c[a][i], -b, c)) return false; } return true; } // aは頂点数 // nibu_hanteiの上にcolorを用意する // 各頂点ごとにどこに辺が出てるかの表がc bool renketujanai_nibu_hantei(int a, V<V<int>> c) { fo(i, a) { if (color[i] == 0) { if (!nibu_hantei(i, 1, c)) return false; } } return true; } signed main() { int a; cin >> a; V<P<int, int>> b(a - 1); fo(i, a - 1) { cin >> b[i].fi >> b[i].se; b[i].fi--; b[i].se--; } V<int> c(a); fo(i, a) cin >> c[i]; Sort(c); rev(c); V<V<int>> d(a); fo(i, a) { d[b[i].fi].pb(b[i].se); d[b[i].se].pb(b[i].fi); } V<P<int, int>> e(a, {INF, 0}); fo(i, a) { e[i].se = i; } e[0].fi = 0; queue<P<int, int>> f; f.push({0, 0}); while (!f.empty()) { P<int, int> g = f.front(); f.pop(); fo(i, d[g.fi].sz) { if (e[d[g.fi][i]].fi == INF) { e[d[g.fi][i]].fi = g.se + 1; f.push({d[g.fi][i], g.se + 1}); } } } Sort(e); int g = 0; fo(i, a - 1) g += c[i + 1]; cout << g << endl; V<int> h(a); fo(i, a) { h[e[i].se] = c[i]; } fo(i, a) { cout << h[i]; if (i == a - 1) cout << endl; else cout << ' '; } }
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double #define fo(a, b) for (int a = 0; a < b; a++) #define Sort(a) sort(a.begin(), a.end()) #define rev(a) reverse(a.begin(), a.end()) #define fi first #define se second #define sz size() #define bgn begin() #define en end() #define pb push_back #define pp() pop_back() #define V vector #define P pair #define yuko(a) setprecision(a) #define uni(a) a.erase(unique(a.begin(), a.end()), a.end()) #define Q queue #define pri priority_queue #define Pri priority_queue<int, vector<int>, greater<int>> #define PriP \ priority_queue<P<int, int>, vector<P<int, int>>, greater<P<int, int>>> #define ff first.first #define fs first.second #define sf second.first #define ss second.second #define all(a) (a).begin(), (a).end() #define elif else if int low(V<int> a, int b) { decltype(a)::iterator c = lower_bound(a.begin(), a.end(), b); int d = c - a.bgn; return d; } int upp(V<int> a, int b) { decltype(a)::iterator c = upper_bound(a.begin(), a.end(), b); int d = c - a.bgn; return d; } template <class T> void cou(vector<vector<T>> a) { int b = a.size(); int c = a[0].size(); fo(i, b) { fo(j, c) { cout << a[i][j]; if (j == c - 1) cout << endl; else cout << ' '; } } } int wari(int a, int b) { if (a % b == 0) return a / b; else return a / b + 1; } int keta(int a) { double b = a; b = log10(b); int c = b; return c + 1; } int souwa(int a) { return a * (a + 1) / 2; } int gcm(int a, int b) { if (a % b == 0) return b; return gcm(b, a % b); } bool prime(int a) { if (a < 2) return false; else if (a == 2) return true; else if (a % 2 == 0) return false; for (int i = 3; i <= sqrt(a) + 1; i += 2) { if (a % i == 0) return false; } return true; } struct Union { vector<int> par; Union(int a) { par = vector<int>(a, -1); } int find(int a) { if (par[a] < 0) return a; else return par[a] = find(par[a]); } bool same(int a, int b) { return find(a) == find(b); } int Size(int a) { return -par[find(a)]; } void unite(int a, int b) { a = find(a); b = find(b); if (a == b) return; if (Size(b) > Size(a)) swap<int>(a, b); par[a] += par[b]; par[b] = a; } }; int ketas(int a) { string b = to_string(a); int c = 0; fo(i, keta(a)) { c += b[i] - '0'; } return c; } bool fe(int a, int b) { a %= 10; b %= 10; if (a == 0) a = 10; if (b == 0) b = 10; if (a > b) return true; else return false; } int INF = 1000000007; struct edge { int s, t, d; }; V<int> mojisyu(string a) { V<int> b(26, 0); fo(i, a.sz) { b[a[i] - 'a']++; } return b; } int wa2(int a) { if (a % 2 == 1) return a / 2; return a / 2 - 1; } /*signed main(){ int a,b,c; cin>>a>>b>>c; V<V<edge>> d(a); fo(i,b){ edge e; cin>>e.s>>e.t>>e.d; d[e.s].pb(e); } V<int> e(a,INF); e[c]=0; priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f; f.push({0,c}); int h=INF; while(!f.empty()){ P<int,int> g; g=f.top(); f.pop(); int v = g.second, i = g.first; for(edge l : d[v]){ if(e[l.t] > i + l.d){ e[l.t] = i + l.d; f.push({i+l.d , l.t}); } } } fo(i,a){ if(e[i]==INF) cout<<"INF"<<endl; else cout<<e[i]<<endl; } } ?*/ int nCr(int n, int r) { int a = 1; r = min(r, n - r); for (int i = n; i > n - r; i--) { a *= i; a /= n - i + 1; } return a; } /*void sea(int x,int y){ if(x<0||a<=x||y<0||b<=y||c[x][y]=='#') return; if(d[x][y]) return; d[x][y]++; sea(x+1,y); sea(x-1,y); sea(x,y+1); sea(x,y-1); }*/ int kaijou(int a) { int b = 1; fo(i, a) b *= i + 1; return b; } int nPr(int a, int b) { if (a < b) return 0; if (b == 0) return 1; int c = 1; for (int i = a; i > a - b; i--) { c *= i; c %= INF; } return c; } int modinv(int a, int m) { int b = m, u = 1, v = 0; while (b) { int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } int lcm(int a, int b) { int c = modinv(gcm(a, b), INF); return ((a * c) % INF) * (b % INF) % INF; } int MOD = INF; int fac[1000010], finv[1000010], inv[1000010]; // テーブルを作る前処理 // 先にCOMinit()で前処理をする // ABC145D void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < 1000010; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 int COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } bool naka(int a, int b, V<V<char>> c) { return (a >= 0 && b >= 0 && a < c.sz && b < c[0].sz); } V<P<int, int>> mawari8 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}, {-1, -1}, {1, 1}, {1, -1}, {-1, -1}}; int inf = 1000000000000000007; /* signed main(){ int a,b,c; cin>>a>>b>>c; V<V<edge>> d(a); fo(i,b){ edge e; cin>>e.s>>e.t>>e.d; d[e.s].pb(e); } V<int> e(a,INF); e[c]=0; priority_queue<P<int,int>,V<P<int,int>>,greater<P<int,int>>> f; f.push({0,c}); int h=INF; while(!f.empty()){ P<int,int> g; g=f.top(); f.pop(); int v = g.second, i = g.first; for(edge l : d[v]){ if(e[l.t] > i + l.d){ e[l.t] = i + l.d; f.push({i+l.d , l.t}); } } } fo(i,a){ if(e[i]==INF) cout<<"INF"<<endl; else cout<<e[i]<<endl; } }*/ V<P<int, int>> mawari4 = {{0, -1}, {0, 1}, {1, 0}, {-1, 0}}; // 最短経路の表 a(全部INFで初期化) // 縦横 x,y // 迷路 f // スタートsx,sy // ゴールgx,gy // 文字はgから使おうね /*int bfs_haba(){ Q<P<int,int>> b; a[sx][sy]=0; b.push({sx,sy}); while(!b.empty()){ P<int,int> c=b.front(); b.pop(); if(c.fi==gx&&c.se==gy){ break; } fo(i,4){ int d=c.fi+mawari4[i].fi; int e=c.se+mawari4[i].se; if(0<=d&&0<=e&&d<x&&e<y&&f[d][e]!='#'&&a[d][e]==INF){ b.push({d,e}); a[d][e]=1+a[c.fi][c.se]; } } } return a[gx][gy]; }*/ V<int> onajibubun(string a) { V<int> b(a.sz); for (int i = 1, j = 0; i < a.sz; i++) { if (i + b[i - j] < j + b[j]) b[i] = b[i - j]; else { int c = max<int>(0, j + b[j] - i); while (i + c < a.sz && a[c] == a[i + c]) c++; b[i] = c; j = i; } } b[0] = a.sz; return b; } // 各頂点ごとにどこに辺が出てるかの表がc // 各頂点ごとの色を表すV<int>(頂点数max)のcolorを用意する // aはどこ塗るか、bは何で塗るかなので、(0,1,c)でよぶとおけ V<int> color(205); bool nibu_hantei(int a, int b, V<V<int>> c) { color[a] = b; fo(i, c[a].sz) { if (b == color[c[a][i]]) return false; if (color[c[a][i]] == 0 && !nibu_hantei(c[a][i], -b, c)) return false; } return true; } // aは頂点数 // nibu_hanteiの上にcolorを用意する // 各頂点ごとにどこに辺が出てるかの表がc bool renketujanai_nibu_hantei(int a, V<V<int>> c) { fo(i, a) { if (color[i] == 0) { if (!nibu_hantei(i, 1, c)) return false; } } return true; } signed main() { int a; cin >> a; V<P<int, int>> b(a - 1); fo(i, a - 1) { cin >> b[i].fi >> b[i].se; b[i].fi--; b[i].se--; } V<int> c(a); fo(i, a) cin >> c[i]; Sort(c); rev(c); V<V<int>> d(a); fo(i, a - 1) { d[b[i].fi].pb(b[i].se); d[b[i].se].pb(b[i].fi); } V<P<int, int>> e(a, {INF, 0}); fo(i, a) { e[i].se = i; } e[0].fi = 0; queue<P<int, int>> f; f.push({0, 0}); while (!f.empty()) { P<int, int> g = f.front(); f.pop(); fo(i, d[g.fi].sz) { if (e[d[g.fi][i]].fi == INF) { e[d[g.fi][i]].fi = g.se + 1; f.push({d[g.fi][i], g.se + 1}); } } } Sort(e); int g = 0; fo(i, a - 1) g += c[i + 1]; cout << g << endl; V<int> h(a); fo(i, a) { h[e[i].se] = c[i]; } fo(i, a) { cout << h[i]; if (i == a - 1) cout << endl; else cout << ' '; } }
replace
374
375
374
375
0
p03026
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; #define int long long typedef vector<int> VI; // typedef pair<int, int> pii; #define fore(i, a) for (auto &i : a) #define REP(i, n) for (int i = 0; i < n; i++) #define eREP(i, n) for (int i = 0; i <= n; i++) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define eFOR(i, a, b) for (int i = (a); i <= (b); ++i) #define SORT(c) sort((c).begin(), (c).end()) #define rSORT(c) sort((c).rbegin(), (c).rend()) #define LB(x, a) lower_bound((x).begin(), (x).end(), (a)) #define UB(x, a) upper_bound((x).begin(), (x).end(), (a)) #define INF 1000000000 #define LLINF 9223372036854775807 #define mod 1000000007 // vector<vector<int> > dp; // vector<vector<vector<int> > > vvvi; // dp=vector<vector<int> >(N, vector<int>(M,0)); // vector<pair<int,int> > v; // v.push_back(make_pair(x,y)); // priority_queue<int,vector<int>, greater<int> > q2; #define ma 100010 vector<VI> to(ma); vector<pair<int, int>> ans, in; VI cost; int N; VI out(ma); VI si(ma); void bfs() { queue<int> Q; int co = 0; Q.push(0); int cnt = 0; while (!Q.empty()) { // cout << "K" << endl; // cout << cnt << endl; if (out[Q.front()] == LLINF) { out[Q.front()] = cost[co]; cnt++; co++; } if (cnt == N) return; int i = 0; while (i < to[Q.front()].size()) { Q.push(to[Q.front()][i]); i++; } Q.pop(); } } signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; REP(i, N) { out[i] = LLINF; } REP(i, N - 1) { int a, b; cin >> a >> b; a--; b--; to[a].push_back(b); to[b].push_back(a); in.push_back(make_pair(a, b)); } REP(i, N) { int a; cin >> a; cost.push_back(a); } rSORT(cost); REP(i, N) { si[i] = to[i].size(); } REP(i, N) { int a = si[i], b = i; ans.push_back(make_pair(a, b)); } rSORT(ans); REP(i, N) { // cout << ans[i].first<<" "<<ans[i].second << endl; } // cout << endl; REP(i, N) { // out[ans[i].second] = cost[i]; } bfs(); int sum = 0; REP(i, N - 1) { sum += min(out[in[i].first], out[in[i].second]); } cout << sum << endl; FOR(i, 0, N - 1) { // cout << to[i][0] << endl; cout << out[i] << " "; } cout << out[N - 1] << endl; return 0; }
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; #define int long long typedef vector<int> VI; // typedef pair<int, int> pii; #define fore(i, a) for (auto &i : a) #define REP(i, n) for (int i = 0; i < n; i++) #define eREP(i, n) for (int i = 0; i <= n; i++) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define eFOR(i, a, b) for (int i = (a); i <= (b); ++i) #define SORT(c) sort((c).begin(), (c).end()) #define rSORT(c) sort((c).rbegin(), (c).rend()) #define LB(x, a) lower_bound((x).begin(), (x).end(), (a)) #define UB(x, a) upper_bound((x).begin(), (x).end(), (a)) #define INF 1000000000 #define LLINF 9223372036854775807 #define mod 1000000007 // vector<vector<int> > dp; // vector<vector<vector<int> > > vvvi; // dp=vector<vector<int> >(N, vector<int>(M,0)); // vector<pair<int,int> > v; // v.push_back(make_pair(x,y)); // priority_queue<int,vector<int>, greater<int> > q2; #define ma 100010 vector<VI> to(ma); vector<pair<int, int>> ans, in; VI cost; int N; VI out(ma); VI si(ma); void bfs() { queue<int> Q; int co = 0; Q.push(0); int cnt = 0; while (!Q.empty()) { // cout << "K" << endl; // cout << cnt << endl; if (out[Q.front()] == LLINF) { out[Q.front()] = cost[co]; cnt++; co++; } if (cnt == N) return; int i = 0; while (i < to[Q.front()].size()) { if (out[to[Q.front()][i]] == LLINF) Q.push(to[Q.front()][i]); i++; } Q.pop(); } } signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; REP(i, N) { out[i] = LLINF; } REP(i, N - 1) { int a, b; cin >> a >> b; a--; b--; to[a].push_back(b); to[b].push_back(a); in.push_back(make_pair(a, b)); } REP(i, N) { int a; cin >> a; cost.push_back(a); } rSORT(cost); REP(i, N) { si[i] = to[i].size(); } REP(i, N) { int a = si[i], b = i; ans.push_back(make_pair(a, b)); } rSORT(ans); REP(i, N) { // cout << ans[i].first<<" "<<ans[i].second << endl; } // cout << endl; REP(i, N) { // out[ans[i].second] = cost[i]; } bfs(); int sum = 0; REP(i, N - 1) { sum += min(out[in[i].first], out[in[i].second]); } cout << sum << endl; FOR(i, 0, N - 1) { // cout << to[i][0] << endl; cout << out[i] << " "; } cout << out[N - 1] << endl; return 0; }
replace
60
61
60
62
TLE
p03026
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { // # of Nodes int N; cin >> N; // Links to connect node a & b vector<vector<int>> ab(N + 1, vector<int>(0)); for (int i = 1; i < N; i++) { int a, b; cin >> a; cin >> b; if (a > b) swap(a, b); ab.at(a).push_back(b); } // vector<int> c(N); int M = 0; for (int i = 0; i < N; i++) { cin >> c.at(i); M += c.at(i); } sort(c.begin(), c.end()); reverse(c.begin(), c.end()); // M -= c.at(0); cout << M << endl; // vector<bool> Ndone(N + 1, false); vector<int> order(0); order.push_back(1); Ndone.at(1) = true; int ix = 0; while (true) { int NN = order.at(ix); int iy = 0; while (iy != ab.at(NN).size()) { int y = ab.at(NN).at(iy); if (!Ndone.at(y)) { order.push_back(y); Ndone.at(y) = true; } iy++; } ix++; if (N == ix) break; } vector<int> d(N + 1, 0); for (int i = 0; i < N; i++) d.at(order.at(i)) = c.at(i); for (int i = 1; i <= N; i++) cout << d.at(i) << ' '; cout << endl; return 0; };
#include <bits/stdc++.h> using namespace std; int main() { // # of Nodes int N; cin >> N; // Links to connect node a & b vector<vector<int>> ab(N + 1, vector<int>(0)); for (int i = 1; i < N; i++) { int a, b; cin >> a; cin >> b; ab.at(a).push_back(b); swap(a, b); ab.at(a).push_back(b); } // vector<int> c(N); int M = 0; for (int i = 0; i < N; i++) { cin >> c.at(i); M += c.at(i); } sort(c.begin(), c.end()); reverse(c.begin(), c.end()); // M -= c.at(0); cout << M << endl; // vector<bool> Ndone(N + 1, false); vector<int> order(0); order.push_back(1); Ndone.at(1) = true; int ix = 0; while (true) { int NN = order.at(ix); int iy = 0; while (iy != ab.at(NN).size()) { int y = ab.at(NN).at(iy); if (!Ndone.at(y)) { order.push_back(y); Ndone.at(y) = true; } iy++; } ix++; if (N == ix) break; } vector<int> d(N + 1, 0); for (int i = 0; i < N; i++) d.at(order.at(i)) = c.at(i); for (int i = 1; i <= N; i++) cout << d.at(i) << ' '; cout << endl; return 0; };
replace
13
15
13
15
0
p03026
C++
Runtime Error
#include <bits/stdc++.h> #define int long long int using namespace std; vector<vector<int>> v; int n; int vis[1005] = {0}; int ans[1005] = {0}; int cnt; void dfs(int i, int a[]) { vis[i] = 1; ans[i] = a[cnt]; cnt--; for (auto j : v[i]) { if (vis[j] == 0) dfs(j, a); } } signed main() { cin >> n; int a[n]; int sum = 0; v.resize(n); int x, y; for (int i = 0; i < n - 1; ++i) { cin >> x >> y; x--; y--; v[x].push_back(y); v[y].push_back(x); } for (int i = 0; i < n; ++i) { cin >> a[i]; sum += a[i]; } sort(a, a + n); sum -= a[n - 1]; cnt = n - 1; dfs(0, a); cout << sum << endl; for (int i = 0; i < n; ++i) { cout << ans[i] << " "; } }
#include <bits/stdc++.h> #define int long long int using namespace std; vector<vector<int>> v; int n; int vis[10005] = {0}; int ans[10005] = {0}; int cnt; void dfs(int i, int a[]) { vis[i] = 1; ans[i] = a[cnt]; cnt--; for (auto j : v[i]) { if (vis[j] == 0) dfs(j, a); } } signed main() { cin >> n; int a[n]; int sum = 0; v.resize(n); int x, y; for (int i = 0; i < n - 1; ++i) { cin >> x >> y; x--; y--; v[x].push_back(y); v[y].push_back(x); } for (int i = 0; i < n; ++i) { cin >> a[i]; sum += a[i]; } sort(a, a + n); sum -= a[n - 1]; cnt = n - 1; dfs(0, a); cout << sum << endl; for (int i = 0; i < n; ++i) { cout << ans[i] << " "; } }
replace
5
7
5
7
0
p03026
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define Would #define you #define please int d = 1; bool D[10001]; int H[1001], topo[10001]; pair<int, int> E[20002]; void dfs(int A) { if (!D[A]) { D[A] = true; topo[A] = d; d++; for (int i = H[A]; i; i = E[i].second) { dfs(E[i].first); } } } const int cm = 1 << 17; char cn[cm], *ci = cn + cm, ct; inline char getcha() { if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; } return *ci++; } inline int getint() { int A = 0; if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0'; else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0'; return A; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N = getint(); for (int i = 2; i < 2 * N; i += 2) { int a = getint(), b = getint(); E[i] = mp(a, H[b]); H[b] = i; E[i + 1] = mp(b, H[a]); H[a] = i + 1; } int C[10000]; int goukei = 0; int saidai = 0; rep(i, N) { C[i] = getint(); goukei += C[i]; saidai = max(saidai, C[i]); } sort(C, C + N); dfs(1); const int dm = 1 << 17; char dn[dm], *di = dn; int X = goukei - saidai; int keta = 0; char c[10]; while (X) { *(c + keta) = '0' + X % 10; X /= 10; keta++; } for (int i = keta - 1; i >= 0; i--) *di++ = (*(c + i)); *di++ = '\n'; rep1(i, N) { X = C[N - topo[i]]; keta = 0; while (X) { *(c + keta) = '0' + X % 10; X /= 10; keta++; } for (int i = keta - 1; i >= 0; i--) *di++ = (*(c + i)); *di++ = ' '; } fwrite_unlocked(dn, di - dn, 1, stdout); Would you please return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i <= (n); i++) #define co(x) cout << (x) << "\n" #define cosp(x) cout << (x) << " " #define ce(x) cerr << (x) << "\n" #define cesp(x) cerr << (x) << " " #define pb push_back #define mp make_pair #define Would #define you #define please int d = 1; bool D[10001]; int H[10001], topo[10001]; pair<int, int> E[20002]; void dfs(int A) { if (!D[A]) { D[A] = true; topo[A] = d; d++; for (int i = H[A]; i; i = E[i].second) { dfs(E[i].first); } } } const int cm = 1 << 17; char cn[cm], *ci = cn + cm, ct; inline char getcha() { if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; } return *ci++; } inline int getint() { int A = 0; if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0'; else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0'; return A; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N = getint(); for (int i = 2; i < 2 * N; i += 2) { int a = getint(), b = getint(); E[i] = mp(a, H[b]); H[b] = i; E[i + 1] = mp(b, H[a]); H[a] = i + 1; } int C[10000]; int goukei = 0; int saidai = 0; rep(i, N) { C[i] = getint(); goukei += C[i]; saidai = max(saidai, C[i]); } sort(C, C + N); dfs(1); const int dm = 1 << 17; char dn[dm], *di = dn; int X = goukei - saidai; int keta = 0; char c[10]; while (X) { *(c + keta) = '0' + X % 10; X /= 10; keta++; } for (int i = keta - 1; i >= 0; i--) *di++ = (*(c + i)); *di++ = '\n'; rep1(i, N) { X = C[N - topo[i]]; keta = 0; while (X) { *(c + keta) = '0' + X % 10; X /= 10; keta++; } for (int i = keta - 1; i >= 0; i--) *di++ = (*(c + i)); *di++ = ' '; } fwrite_unlocked(dn, di - dn, 1, stdout); Would you please return 0; }
replace
17
18
17
18
0
p03026
C++
Memory Limit Exceeded
#include <algorithm> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define ll int64_t #define Rep(i, n) for (ll i = 0; i < n; i++) using namespace std; vector<vector<ll>> graph; vector<ll> depth; void dfs(ll i, ll v) { if (depth[i] != -1) return; depth[i] = v; for (ll e : graph[i]) { dfs(e, v + 1); } } int main() { cin.tie(0); ios::sync_with_stdio(false); ll N; cin >> N; graph.assign(N, vector<ll>(N)); depth.assign(N, -1); Rep(i, N - 1) { ll a, b; cin >> a >> b; a--; b--; graph[a].push_back(b); graph[b].push_back(a); } vector<ll> c(N); ll M = 0; Rep(i, N) { cin >> c[i]; M += c[i]; } sort(c.begin(), c.end()); M -= c.back(); cout << M << "\n"; dfs(0, 0); // Rep (i, N) { // cout << depth[i] << "\n"; // } set<pair<ll, ll>> ans; Rep(i, N) { ans.insert(make_pair(-depth[i], i)); } vector<ll> output(N); ll i = 0; for (auto e : ans) { output[e.second] = c[i]; i++; } for (ll e : output) { cout << e << " "; } cout << endl; }
#include <algorithm> #include <cstdio> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define ll int #define Rep(i, n) for (ll i = 0; i < n; i++) using namespace std; vector<vector<ll>> graph; vector<ll> depth; void dfs(ll i, ll v) { if (depth[i] != -1) return; depth[i] = v; for (ll e : graph[i]) { dfs(e, v + 1); } } int main() { cin.tie(0); ios::sync_with_stdio(false); ll N; cin >> N; graph.assign(N, vector<ll>(N)); depth.assign(N, -1); Rep(i, N - 1) { ll a, b; cin >> a >> b; a--; b--; graph[a].push_back(b); graph[b].push_back(a); } vector<ll> c(N); ll M = 0; Rep(i, N) { cin >> c[i]; M += c[i]; } sort(c.begin(), c.end()); M -= c.back(); cout << M << "\n"; dfs(0, 0); // Rep (i, N) { // cout << depth[i] << "\n"; // } set<pair<ll, ll>> ans; Rep(i, N) { ans.insert(make_pair(-depth[i], i)); } vector<ll> output(N); ll i = 0; for (auto e : ans) { output[e.second] = c[i]; i++; } for (ll e : output) { cout << e << " "; } cout << endl; }
replace
12
13
12
13
MLE
p03026
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define R cin >> #define Z class #define ll long long #define ln cout << '\n' #define in(a) insert(a) #define pb(a) push_back(a) #define pd(a) printf("%.10f\n", a) #define mem(a) memset(a, 0, sizeof(a)) #define all(c) (c).begin(), (c).end() #define iter(c) __typeof((c).begin()) #define rrep(i, n) for (ll i = (ll)(n)-1; i >= 0; i--) #define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++) #define rep(i, n) REP(i, 0, n) #define tr(it, c) for (iter(c) it = (c).begin(); it != (c).end(); it++) template <Z A> void pr(A a) { cout << a; ln; } template <Z A, Z B> void pr(A a, B b) { cout << a << ' '; pr(b); } template <Z A, Z B, Z C> void pr(A a, B b, C c) { cout << a << ' '; pr(b, c); } template <Z A, Z B, Z C, Z D> void pr(A a, B b, C c, D d) { cout << a << ' '; pr(b, c, d); } template <Z A> void PR(A a, ll n) { rep(i, n) { if (i) cout << ' '; cout << a[i]; } ln; } ll check(ll n, ll m, ll x, ll y) { return x >= 0 && x < n && y >= 0 && y < m; } const ll MAX = 1e9 + 7, MAXL = 1LL << 61, dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1}; typedef pair<ll, ll> P; ll ans = 0; void Main() { ll n; R n; vector<ll> v[n]; rep(i, n - 1) { ll x, y; cin >> x >> y; x--, y--; v[x].pb(y); v[y].pb(x); } ll c[n], d[n]; rep(i, n) R c[i]; sort(c, c + n, greater<ll>()); queue<int> que; que.push(0); memset(d, -1, sizeof(d)); ll k = 0, ans = 0; d[0] = c[k++]; while (!que.empty()) { ll x = que.front(); que.pop(); rep(i, v[x].size()) { ll y = v[x][i]; // if(d[y]!=-1) continue; d[y] = c[k++]; ans += d[y]; que.push(y); } } pr(ans); PR(d, n); } int main() { ios::sync_with_stdio(0); cin.tie(0); Main(); return 0; }
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define R cin >> #define Z class #define ll long long #define ln cout << '\n' #define in(a) insert(a) #define pb(a) push_back(a) #define pd(a) printf("%.10f\n", a) #define mem(a) memset(a, 0, sizeof(a)) #define all(c) (c).begin(), (c).end() #define iter(c) __typeof((c).begin()) #define rrep(i, n) for (ll i = (ll)(n)-1; i >= 0; i--) #define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++) #define rep(i, n) REP(i, 0, n) #define tr(it, c) for (iter(c) it = (c).begin(); it != (c).end(); it++) template <Z A> void pr(A a) { cout << a; ln; } template <Z A, Z B> void pr(A a, B b) { cout << a << ' '; pr(b); } template <Z A, Z B, Z C> void pr(A a, B b, C c) { cout << a << ' '; pr(b, c); } template <Z A, Z B, Z C, Z D> void pr(A a, B b, C c, D d) { cout << a << ' '; pr(b, c, d); } template <Z A> void PR(A a, ll n) { rep(i, n) { if (i) cout << ' '; cout << a[i]; } ln; } ll check(ll n, ll m, ll x, ll y) { return x >= 0 && x < n && y >= 0 && y < m; } const ll MAX = 1e9 + 7, MAXL = 1LL << 61, dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1}; typedef pair<ll, ll> P; ll ans = 0; void Main() { ll n; R n; vector<ll> v[n]; rep(i, n - 1) { ll x, y; cin >> x >> y; x--, y--; v[x].pb(y); v[y].pb(x); } ll c[n], d[n]; rep(i, n) R c[i]; sort(c, c + n, greater<ll>()); queue<int> que; que.push(0); memset(d, -1, sizeof(d)); ll k = 0, ans = 0; d[0] = c[k++]; while (!que.empty()) { ll x = que.front(); que.pop(); rep(i, v[x].size()) { ll y = v[x][i]; if (d[y] != -1) continue; d[y] = c[k++]; ans += d[y]; que.push(y); } } pr(ans); PR(d, n); } int main() { ios::sync_with_stdio(0); cin.tie(0); Main(); return 0; }
replace
73
74
73
75
-11
p03027
C++
Runtime Error
#include <bits/stdc++.h> #define FOR(i, k, n) for (int i = (k); i < (n); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) begin(x), end(x) using namespace std; using vecint = vector<int>; using ll = int64_t; constexpr ll MOD = 1000003; // a^-1 mod p ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p); } ll powmod(ll x, ll i) { if (i == 0) return 1; if ((i % 2) == 1) return (x * powmod(x, i - 1)) % MOD; ll h = powmod(x, i / 2); return (h * h) % MOD; } int main() { int q; cin >> q; vector<ll> fact(MOD); vector<ll> factinv(MOD); fact[0] = factinv[0] = 1; REP(i, MOD - 1) { fact[i + 1] = fact[i] * (i + 1); fact[i + 1] %= MOD; factinv[i + 1] = inv(fact[i + 1], MOD); } REP(task, q) { ll x, d, n; cin >> x >> d >> n; if (x == 0) { cout << 0 << endl; } else { ll y = (x * inv(d, MOD)) % MOD; if (y + n - 1 < MOD) { ll res = powmod(d, n); res *= fact[y + n - 1]; res %= MOD; res *= factinv[y - 1]; res %= MOD; cout << res << endl; } else { cout << 0 << endl; } } } return 0; }
#include <bits/stdc++.h> #define FOR(i, k, n) for (int i = (k); i < (n); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) begin(x), end(x) using namespace std; using vecint = vector<int>; using ll = int64_t; constexpr ll MOD = 1000003; // a^-1 mod p ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p); } ll powmod(ll x, ll i) { if (i == 0) return 1; if ((i % 2) == 1) return (x * powmod(x, i - 1)) % MOD; ll h = powmod(x, i / 2); return (h * h) % MOD; } int main() { int q; cin >> q; vector<ll> fact(MOD); vector<ll> factinv(MOD); fact[0] = factinv[0] = 1; REP(i, MOD - 1) { fact[i + 1] = fact[i] * (i + 1); fact[i + 1] %= MOD; factinv[i + 1] = inv(fact[i + 1], MOD); } REP(task, q) { ll x, d, n; cin >> x >> d >> n; if (x == 0) { cout << 0 << endl; } else if (d == 0) { cout << powmod(x, n) << endl; } else { ll y = (x * inv(d, MOD)) % MOD; if (y + n - 1 < MOD) { ll res = powmod(d, n); res *= fact[y + n - 1]; res %= MOD; res *= factinv[y - 1]; res %= MOD; cout << res << endl; } else { cout << 0 << endl; } } } return 0; }
insert
38
38
38
40
0
p03027
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; // #define int ll using PII = pair<ll, ll>; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); } template <typename T> bool IN(T a, T b, T x) { return a <= x && x < b; } template <typename T> T ceil(T a, T b) { return a / b + !!(a % b); } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } template <class S, class T> ostream &operator<<(ostream &out, const pair<S, T> &a) { out << '(' << a.first << ',' << a.second << ')'; return out; } template <class T> ostream &operator<<(ostream &out, const vector<T> &a) { out << '['; for (const T &i : a) out << i << ','; out << ']'; return out; } template <class T> ostream &operator<<(ostream &out, const set<T> &a) { out << '{'; for (const T &i : a) out << i << ','; out << '}'; return out; } template <class T, class S> ostream &operator<<(ostream &out, const map<T, S> &a) { out << '{'; for (auto &i : a) out << i << ','; out << '}'; return out; } int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL const int INF = 1 << 30; const ll LLINF = 1LL << 60; // const ll MOD = 1000000007; template <ll MOD> struct modint { ll x; modint() : x(0) {} modint(ll y) : x(y >= 0 ? y % MOD : y % MOD + MOD) {} static constexpr ll mod() { return MOD; } // e乗 modint pow(ll e) { ll a = 1, p = x; while (e > 0) { if (e % 2 == 0) { p = (p * p) % MOD; e /= 2; } else { a = (a * p) % MOD; e--; } } return modint(a); } modint inv() const { ll a = x, b = MOD, u = 1, y = 1, v = 0, z = 0; while (a) { ll q = b / a; swap(z -= q * u, u); swap(y -= q * v, v); swap(b -= q * a, a); } return z; } // Comparators bool operator<(modint b) { return x < b.x; } bool operator>(modint b) { return x > b.x; } bool operator<=(modint b) { return x <= b.x; } bool operator>=(modint b) { return x >= b.x; } bool operator!=(modint b) { return x != b.x; } bool operator==(modint b) { return x == b.x; } // Basic Operations modint operator+(modint r) const { return modint(*this) += r; } modint operator-(modint r) const { return modint(*this) -= r; } modint operator*(modint r) const { return modint(*this) *= r; } modint operator/(modint r) const { return modint(*this) /= r; } modint &operator+=(modint r) { if ((x += r.x) >= MOD) x -= MOD; return *this; } modint &operator-=(modint r) { if ((x -= r.x) < 0) x += MOD; return *this; } modint &operator*=(modint r) { #if !defined(_WIN32) || defined(_WIN64) x = x * r.x % MOD; return *this; #endif unsigned long long y = x * r.x; unsigned xh = (unsigned)(y >> 32), xl = (unsigned)y, d, m; asm("divl %4; \n\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(xl), "r"(MOD)); x = m; return *this; } modint &operator/=(modint r) { return *this *= r.inv(); } // increment, decrement modint operator++() { x++; return *this; } modint operator++(signed) { modint t = *this; x++; return t; } modint operator--() { x--; return *this; } modint operator--(signed) { modint t = *this; x--; return t; } }; using mint = modint<1000003>; template <class T> mint operator*(T l, mint r) { return mint(l) *= r; } template <class T> mint operator+(T l, mint r) { return mint(l) += r; } template <class T> mint operator-(T l, mint r) { return mint(l) -= r; } template <class T> mint operator/(T l, mint r) { return mint(l) /= r; } template <class T> bool operator==(T l, mint r) { return mint(l) == r; } template <class T> bool operator!=(T l, mint r) { return mint(l) != r; } // Input/Output ostream &operator<<(ostream &os, mint a) { return os << a.x; } istream &operator>>(istream &is, mint &a) { return is >> a.x; } string to_frac(mint v) { static map<ll, PII> mp; if (mp.empty()) { mp[0] = mp[mint::mod()] = {0, 1}; FOR(i, 2, 1001) FOR(j, 1, i) if (__gcd(i, j) == 1) { mp[(mint(i) / j).x] = {i, j}; } } auto itr = mp.lower_bound(v.x); if (itr != mp.begin() && v.x - prev(itr)->first < itr->first - v.x) --itr; string ret = to_string(itr->second.first + itr->second.second * ((int)v.x - itr->first)); if (itr->second.second > 1) { ret += '/'; ret += to_string(itr->second.second); } return ret; } mint prod[1000003]; signed main(void) { cin.tie(0); ios::sync_with_stdio(false); prod[0] = 1; FOR(i, 1, 1000003) prod[i] = prod[i - 1] * i; ll q; cin >> q; while (q--) { ll x, d, n; cin >> x >> d >> n; // cout << (mint(x)/d+n-1).x << endl; if (d == 0) { cout << mint(x).pow(n) << endl; } else if ((mint(x) / d + n - 1).x >= 1000003) { cout << 0 << endl; } else { ll t = (mint(x) / d).x; // cout << d << endl; cout << mint(d).pow(n) * prod[t + n - 1] / prod[t - 1] << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; // #define int ll using PII = pair<ll, ll>; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); } template <typename T> bool IN(T a, T b, T x) { return a <= x && x < b; } template <typename T> T ceil(T a, T b) { return a / b + !!(a % b); } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } template <class S, class T> ostream &operator<<(ostream &out, const pair<S, T> &a) { out << '(' << a.first << ',' << a.second << ')'; return out; } template <class T> ostream &operator<<(ostream &out, const vector<T> &a) { out << '['; for (const T &i : a) out << i << ','; out << ']'; return out; } template <class T> ostream &operator<<(ostream &out, const set<T> &a) { out << '{'; for (const T &i : a) out << i << ','; out << '}'; return out; } template <class T, class S> ostream &operator<<(ostream &out, const map<T, S> &a) { out << '{'; for (auto &i : a) out << i << ','; out << '}'; return out; } int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL const int INF = 1 << 30; const ll LLINF = 1LL << 60; // const ll MOD = 1000000007; template <ll MOD> struct modint { ll x; modint() : x(0) {} modint(ll y) : x(y >= 0 ? y % MOD : y % MOD + MOD) {} static constexpr ll mod() { return MOD; } // e乗 modint pow(ll e) { ll a = 1, p = x; while (e > 0) { if (e % 2 == 0) { p = (p * p) % MOD; e /= 2; } else { a = (a * p) % MOD; e--; } } return modint(a); } modint inv() const { ll a = x, b = MOD, u = 1, y = 1, v = 0, z = 0; while (a) { ll q = b / a; swap(z -= q * u, u); swap(y -= q * v, v); swap(b -= q * a, a); } return z; } // Comparators bool operator<(modint b) { return x < b.x; } bool operator>(modint b) { return x > b.x; } bool operator<=(modint b) { return x <= b.x; } bool operator>=(modint b) { return x >= b.x; } bool operator!=(modint b) { return x != b.x; } bool operator==(modint b) { return x == b.x; } // Basic Operations modint operator+(modint r) const { return modint(*this) += r; } modint operator-(modint r) const { return modint(*this) -= r; } modint operator*(modint r) const { return modint(*this) *= r; } modint operator/(modint r) const { return modint(*this) /= r; } modint &operator+=(modint r) { if ((x += r.x) >= MOD) x -= MOD; return *this; } modint &operator-=(modint r) { if ((x -= r.x) < 0) x += MOD; return *this; } modint &operator*=(modint r) { #if !defined(_WIN32) || defined(_WIN64) x = x * r.x % MOD; return *this; #endif unsigned long long y = x * r.x; unsigned xh = (unsigned)(y >> 32), xl = (unsigned)y, d, m; asm("divl %4; \n\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(xl), "r"(MOD)); x = m; return *this; } modint &operator/=(modint r) { return *this *= r.inv(); } // increment, decrement modint operator++() { x++; return *this; } modint operator++(signed) { modint t = *this; x++; return t; } modint operator--() { x--; return *this; } modint operator--(signed) { modint t = *this; x--; return t; } }; using mint = modint<1000003>; template <class T> mint operator*(T l, mint r) { return mint(l) *= r; } template <class T> mint operator+(T l, mint r) { return mint(l) += r; } template <class T> mint operator-(T l, mint r) { return mint(l) -= r; } template <class T> mint operator/(T l, mint r) { return mint(l) /= r; } template <class T> bool operator==(T l, mint r) { return mint(l) == r; } template <class T> bool operator!=(T l, mint r) { return mint(l) != r; } // Input/Output ostream &operator<<(ostream &os, mint a) { return os << a.x; } istream &operator>>(istream &is, mint &a) { return is >> a.x; } string to_frac(mint v) { static map<ll, PII> mp; if (mp.empty()) { mp[0] = mp[mint::mod()] = {0, 1}; FOR(i, 2, 1001) FOR(j, 1, i) if (__gcd(i, j) == 1) { mp[(mint(i) / j).x] = {i, j}; } } auto itr = mp.lower_bound(v.x); if (itr != mp.begin() && v.x - prev(itr)->first < itr->first - v.x) --itr; string ret = to_string(itr->second.first + itr->second.second * ((int)v.x - itr->first)); if (itr->second.second > 1) { ret += '/'; ret += to_string(itr->second.second); } return ret; } mint prod[1000003]; signed main(void) { cin.tie(0); ios::sync_with_stdio(false); prod[0] = 1; FOR(i, 1, 1000003) prod[i] = prod[i - 1] * i; ll q; cin >> q; while (q--) { ll x, d, n; cin >> x >> d >> n; // cout << (mint(x)/d+n-1).x << endl; if (d == 0) { cout << mint(x).pow(n) << endl; } else if ((mint(x) / d).x + n - 1 >= 1000003) { cout << 0 << endl; } else { ll t = (mint(x) / d).x; // cout << d << endl; cout << mint(d).pow(n) * prod[t + n - 1] / prod[t - 1] << endl; } } return 0; }
replace
193
194
193
194
0
p03027
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> P1; typedef pair<P, P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define fi first #define sc second #define rep(i, x) for (int i = 0; i < x; i++) #define repn(i, x) for (int i = 1; i <= x; i++) #define SORT(x) sort(x.begin(), x.end()) #define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end()) #define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin()) #define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin()) const int MAX = 10000000; const int MOD = 1000003; long long fac[MAX], finv[MAX], inv[MAX]; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } int main() { vector<ll> ans; // 前処理 COMinit(); ll Q; cin >> Q; ll i, j, k, l; rep(i, Q) { ll x, d, n; cin >> x >> d >> n; ll tmp; if (d == 0) { tmp = modpow(x, n, MOD); ans.pb(tmp); } else { if (n >= MAX) { ans.pb(0); } else { x = x * inv[d] % MOD; tmp = fac[x + n - 1] * finv[x - 1] % MOD * modpow(d, n, MOD) % MOD; ans.pb(tmp); } } } rep(i, ans.size()) cout << ans.at(i) << endl; }
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> P1; typedef pair<P, P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define fi first #define sc second #define rep(i, x) for (int i = 0; i < x; i++) #define repn(i, x) for (int i = 1; i <= x; i++) #define SORT(x) sort(x.begin(), x.end()) #define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end()) #define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin()) #define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin()) const int MAX = 10000000; const int MOD = 1000003; long long fac[MAX], finv[MAX], inv[MAX]; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } int main() { vector<ll> ans; // 前処理 COMinit(); ll Q; cin >> Q; ll i, j, k, l; rep(i, Q) { ll x, d, n; cin >> x >> d >> n; ll tmp; if (d == 0) { tmp = modpow(x, n, MOD); ans.pb(tmp); } else { if (n >= MOD) { ans.pb(0); } else { x = x * inv[d] % MOD; tmp = fac[x + n - 1] * finv[x - 1] % MOD * modpow(d, n, MOD) % MOD; ans.pb(tmp); } } } rep(i, ans.size()) cout << ans.at(i) << endl; }
replace
67
68
67
68
-11
p03027
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define start_routine() int begtime = clock(); #define end_routine() \ int endtime = clock(); \ cerr << "\n\n" \ << "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC \ << " ms\n\n"; \ return 0 #define ll long long int #define ull unsigned long long int #define db long double #define ff first #define ss second #define mp make_pair #define pb push_back #define lb lower_bound #define ub upper_bound #define pii pair<int, int> #define pdd pair<db, db> #define pll pair<ll, ll> #define vpl vector<pll> #define vll vector<ll> #define mod 1000000007 #define mod1 998244353 #define inf 1000000000000000007 #define eps 0.000001 #define stp fixed << setprecision(20) #define endl '\n' ll fact[3000005]; inline ll pow(ll x, ll y, ll p) { ll ans = 1; x = x % p; while (y > 0) { if (y & 1) ans = (ans * x) % p; y = y >> 1; x = (x * x) % p; } return ans; } inline ll invmod(ll x, ll p) { return pow(x, p - 2, p); } int main() { fastio; #ifdef APNA_IO start_routine(); freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif fact[0] = 1; for (ll i = 1; i < 3000005; i++) { fact[i] = (i * fact[i - 1]) % 1000003; } ll q; cin >> q; while (q--) { ll x, d, n; cin >> x >> d >> n; ll a = (x * invmod(d, 1000003)) % 1000003; ll l = a, r = (a + n - 1); if (l > r) swap(l, r); { ll x = fact[r]; x = (x * invmod(fact[l - 1], 1000003)) % 1000003; x = (x * pow(d, n, 1000003)) % 1000003; cout << x << endl; } } #ifdef APNA_IO end_routine(); #endif }
#include <bits/stdc++.h> using namespace std; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define start_routine() int begtime = clock(); #define end_routine() \ int endtime = clock(); \ cerr << "\n\n" \ << "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC \ << " ms\n\n"; \ return 0 #define ll long long int #define ull unsigned long long int #define db long double #define ff first #define ss second #define mp make_pair #define pb push_back #define lb lower_bound #define ub upper_bound #define pii pair<int, int> #define pdd pair<db, db> #define pll pair<ll, ll> #define vpl vector<pll> #define vll vector<ll> #define mod 1000000007 #define mod1 998244353 #define inf 1000000000000000007 #define eps 0.000001 #define stp fixed << setprecision(20) #define endl '\n' ll fact[3000005]; inline ll pow(ll x, ll y, ll p) { ll ans = 1; x = x % p; while (y > 0) { if (y & 1) ans = (ans * x) % p; y = y >> 1; x = (x * x) % p; } return ans; } inline ll invmod(ll x, ll p) { return pow(x, p - 2, p); } int main() { fastio; #ifdef APNA_IO start_routine(); freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif fact[0] = 1; for (ll i = 1; i < 3000005; i++) { fact[i] = (i * fact[i - 1]) % 1000003; } ll q; cin >> q; while (q--) { ll x, d, n; cin >> x >> d >> n; ll a = (x * invmod(d, 1000003)) % 1000003; if (x == 0) { cout << 0 << endl; continue; } if (d == 0) { cout << pow(x, n, 1000003) << endl; continue; } ll l = a, r = (a + n - 1) % 1000003; if (l + n - 1 >= 1000003 || l - 1 < 0) cout << 0 << endl; else { ll x = fact[r]; x = (x * invmod(fact[l - 1], 1000003)) % 1000003; x = (x * pow(d, n, 1000003)) % 1000003; cout << x << endl; } } #ifdef APNA_IO end_routine(); #endif }
replace
69
73
69
83
0
p03027
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #define MOD 1000003 using namespace std; typedef long long ll; template <typename Tp> inline void getint(Tp &num) { register int ch, neg = 0; while (!isdigit(ch = getchar())) if (ch == '-') neg = 1; num = ch & 15; while (isdigit(ch = getchar())) num = num * 10 + (ch & 15); if (neg) num = -num; } inline ll fastpow(ll bas, ll ex) { register ll res = 1; bas %= MOD; for (; ex; ex >>= 1, bas = bas * bas % MOD) if (ex & 1) res = res * bas % MOD; return res; } int Q, fac[1000005] = {1, 1}, ifac[1000005] = {1, 1}, inv[1000005] = {1, 1}; int main() { getint(Q); for (register int i = 2; i < MOD; i++) { fac[i] = fac[i - 1] * (ll)i % MOD; inv[i] = (MOD - MOD / i) * (ll)inv[MOD % i] % MOD; ifac[i] = ifac[i - 1] * (ll)inv[i] % MOD; } while (Q--) { int x, d, n; getint(x), getint(d), getint(n); x = x * (ll)inv[d] % MOD; printf("%lld\n", x ? fac[x + n - 1] * (ll)ifac[x - 1] % MOD * fastpow(d, n) % MOD : 0); } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #define MOD 1000003 using namespace std; typedef long long ll; template <typename Tp> inline void getint(Tp &num) { register int ch, neg = 0; while (!isdigit(ch = getchar())) if (ch == '-') neg = 1; num = ch & 15; while (isdigit(ch = getchar())) num = num * 10 + (ch & 15); if (neg) num = -num; } inline ll fastpow(ll bas, ll ex) { register ll res = 1; bas %= MOD; for (; ex; ex >>= 1, bas = bas * bas % MOD) if (ex & 1) res = res * bas % MOD; return res; } int Q, fac[1000005] = {1, 1}, ifac[1000005] = {1, 1}, inv[1000005] = {1, 1}; int main() { getint(Q); for (register int i = 2; i < MOD; i++) { fac[i] = fac[i - 1] * (ll)i % MOD; inv[i] = (MOD - MOD / i) * (ll)inv[MOD % i] % MOD; ifac[i] = ifac[i - 1] * (ll)inv[i] % MOD; } while (Q--) { int x, d, n; getint(x), getint(d), getint(n); if (d == 0) printf("%lld\n", fastpow(x, n)); else { x = x * (ll)inv[d] % MOD; if (x == 0 || x + n - 1 >= MOD) puts("0"); else printf("%lld\n", fac[x + n - 1] * (ll)ifac[x - 1] % MOD * fastpow(d, n) % MOD); } } return 0; }
replace
43
47
43
53
0
p03027
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define all(x) (x).begin(), (x).end() #define YES() printf("YES\n") #define NO() printf("NO\n") #define Yes() printf("Yes\n") #define No() printf("No\n") #define in(x, y, h, w) x >= 0 && x < h &&y >= 0 && y < w #define int long long // typedef long long ll; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<vb> vvb; typedef vector<vi> vvi; typedef pair<int, int> P; template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); } const int INF = 1e+18; const double EPS = 1e-9; const int MOD = 1000003; const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1}; int mod_inv(int X) { int a = X, b = MOD, u = 1, v = 0; while (b) { int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } if (u < 0) u += MOD; return u; } vector<int> fact, factinv; void nCr_init(int N) { N = min(N, (int)MOD); fact.resize(N + 1); factinv.resize(N + 1); fact[0] = 1; for (int i = 1; i <= N; i++) fact[i] = fact[i - 1] * i % MOD; factinv[N] = mod_inv(fact[N]); for (int i = N; i >= 1; i--) factinv[i - 1] = factinv[i] * i % MOD; } int nCr(int ncr_n, int ncr_r) { if (ncr_n >= MOD) return nCr(ncr_n % MOD, ncr_r % MOD) * nCr(ncr_n / MOD, ncr_r / MOD) % MOD; return ncr_r > ncr_n ? 0 : fact[ncr_n] * factinv[ncr_n - ncr_r] % MOD * factinv[ncr_r] % MOD; } int pow2(int a, int b) { if (!b) return 1; int tmp = pow2(a * a % MOD, b / 2); if (b % 2) tmp = (tmp * a) % MOD; return tmp; } signed main() { int q; cin >> q; nCr_init(MOD - 1); for (int i = 0; i < q; i++) { int x, d, n; cin >> x >> d >> n; cout << fact[n] * nCr(MOD - x * mod_inv(d) % MOD, n) % MOD * pow2(MOD - d, n) % MOD << endl; } }
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back #define all(x) (x).begin(), (x).end() #define YES() printf("YES\n") #define NO() printf("NO\n") #define Yes() printf("Yes\n") #define No() printf("No\n") #define in(x, y, h, w) x >= 0 && x < h &&y >= 0 && y < w #define int long long // typedef long long ll; typedef vector<bool> vb; typedef vector<int> vi; typedef vector<vb> vvb; typedef vector<vi> vvi; typedef pair<int, int> P; template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); } template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); } const int INF = 1e+18; const double EPS = 1e-9; const int MOD = 1000003; const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1}; int mod_inv(int X) { int a = X, b = MOD, u = 1, v = 0; while (b) { int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } if (u < 0) u += MOD; return u; } vector<int> fact, factinv; void nCr_init(int N) { N = min(N, (int)MOD); fact.resize(N + 1); factinv.resize(N + 1); fact[0] = 1; for (int i = 1; i <= N; i++) fact[i] = fact[i - 1] * i % MOD; factinv[N] = mod_inv(fact[N]); for (int i = N; i >= 1; i--) factinv[i - 1] = factinv[i] * i % MOD; } int nCr(int ncr_n, int ncr_r) { if (ncr_n >= MOD) return nCr(ncr_n % MOD, ncr_r % MOD) * nCr(ncr_n / MOD, ncr_r / MOD) % MOD; return ncr_r > ncr_n ? 0 : fact[ncr_n] * factinv[ncr_n - ncr_r] % MOD * factinv[ncr_r] % MOD; } int pow2(int a, int b) { if (!b) return 1; int tmp = pow2(a * a % MOD, b / 2); if (b % 2) tmp = (tmp * a) % MOD; return tmp; } signed main() { int q; cin >> q; nCr_init(MOD - 1); for (int i = 0; i < q; i++) { int x, d, n; cin >> x >> d >> n; if (!d) cout << pow2(x, n) << endl; else if (n >= MOD) cout << 0 << endl; else cout << fact[n] * nCr(MOD - x * mod_inv(d) % MOD, n) % MOD * pow2(MOD - d, n) % MOD << endl; } }
replace
80
83
80
88
0
p03027
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i < b; i++) #define rrep(i, a, b) for (int i = a; i >= b; i--) #define fore(i, a) for (auto &i : a) // #define all(x) (x).begin(),(x).end() // #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; 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 (b < a) { a = b; return 1; } return 0; } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ const int MAX = 5100000; const int MOD = 1000003; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // a^n mod を計算する long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // a^{-1} mod を計算する long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } void _main() { COMinit(); int Q; cin >> Q; rep(i, 0, Q) { ll x, d, n; cin >> x >> d >> n; ll ans; if (d == 0) { ans = modpow(x, n, MOD); } else { bool zero = false; for (ll i = 0; i < n; ++i) { if (x + i % MOD == 0) { zero = true; break; } } if (zero) { ans = 0; } else { x = x * modinv(d, MOD) % MOD; ans = modpow(d, n, MOD) * fac[x + n - 1] % MOD * finv[x - 1] % MOD; } } cout << ans << endl; } }
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i < b; i++) #define rrep(i, a, b) for (int i = a; i >= b; i--) #define fore(i, a) for (auto &i : a) // #define all(x) (x).begin(),(x).end() // #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; 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 (b < a) { a = b; return 1; } return 0; } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ const int MAX = 5100000; const int MOD = 1000003; long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } // a^n mod を計算する long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // a^{-1} mod を計算する long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } void _main() { COMinit(); int Q; cin >> Q; rep(i, 0, Q) { ll x, d, n; cin >> x >> d >> n; ll ans; if (d == 0) { ans = modpow(x, n, MOD); } else { if (n >= MOD) { ans = 0; } else { x = x * modinv(d, MOD) % MOD; ans = modpow(d, n, MOD) * fac[x + n - 1] % MOD * finv[x - 1] % MOD; } } cout << ans << endl; } }
replace
86
95
86
87
-11
p03027
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdint> #include <cstdio> #include <ctime> #include <deque> #include <float.h> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <type_traits> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using ll = long long; unsigned euclidean_gcd(unsigned a, unsigned b) { if (a < b) return euclidean_gcd(b, a); unsigned r; while ((r = a % b)) { a = b; b = r; } return b; } ll ll_gcd(ll a, ll b) { if (a < b) return ll_gcd(b, a); ll r; while ((r = a % b)) { a = b; b = r; } return b; } struct UnionFind { vector<ll> par; vector<ll> siz; UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); for (ll i = 0; i < sz_; ++i) par[i] = i; } ll root(ll x) { while (par[x] != x) { x = par[x] = par[par[x]]; } return x; } bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return siz[root(x)]; } }; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } vector<int> tpsort(vector<vector<int>> &G) { int V = G.size(); vector<int> sorted_vertices; queue<int> que; vector<int> indegree(V); for (int i = 0; i < V; i++) { for (int j = 0; j < G[i].size(); j++) { indegree[G[i][j]]++; } } for (int i = 0; i < V; i++) { if (indegree[i] == 0) { que.push(i); } } while (que.empty() == false) { int v = que.front(); que.pop(); for (int i = 0; i < G[v].size(); i++) { int u = G[v][i]; indegree[u] -= 1; if (indegree[u] == 0) que.push(u); } sorted_vertices.push_back(v); } return sorted_vertices; } struct Point { double x; double y; }; struct LineSegment { Point start; Point end; }; double tenkyori(const LineSegment &line, const Point &point) { double x0 = point.x, y0 = point.y; double x1 = line.start.x, y1 = line.start.y; double x2 = line.end.x, y2 = line.end.y; double a = x2 - x1; double b = y2 - y1; double a2 = a * a; double b2 = b * b; double r2 = a2 + b2; double tt = -(a * (x1 - x0) + b * (y1 - y0)); if (tt < 0) return sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)); else if (tt > r2) return sqrt((x2 - x0) * (x2 - x0) + (y2 - y0) * (y2 - y0)); double f1 = a * (y1 - y0) - b * (x1 - x0); return sqrt((f1 * f1) / r2); } template <typename X> struct SegTree { using FX = function<X(X, X)>; // X•X -> X となる関数の型 int n; FX fx; const X ex; vector<X> dat; SegTree(int n_, FX fx_, X ex_) : n(), fx(fx_), ex(ex_), dat(n_ * 4, ex_) { int x = 1; while (n_ > x) { x *= 2; } n = x; } void set(int i, X x) { dat[i + n - 1] = x; } void build() { for (int k = n - 2; k >= 0; k--) dat[k] = fx(dat[2 * k + 1], dat[2 * k + 2]); } void update(int i, X x) { i += n - 1; dat[i] = x; while (i > 0) { i = (i - 1) / 2; // parent dat[i] = fx(dat[i * 2 + 1], dat[i * 2 + 2]); } } X query(int a, int b) { return query_sub(a, b, 0, 0, n); } X query_sub(int a, int b, int k, int l, int r) { if (r <= a || b <= l) { return ex; } else if (a <= l && r <= b) { return dat[k]; } else { X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2); X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r); return fx(vl, vr); } } }; template <typename X, typename M> struct SegTreeLazy { using FX = function<X(X, X)>; using FA = function<X(X, M)>; using FM = function<M(M, M)>; int n; FX fx; FA fa; FM fm; const X ex; const M em; vector<X> dat; vector<M> lazy; SegTreeLazy(int n_, FX fx_, FA fa_, FM fm_, X ex_, M em_) : n(), fx(fx_), fa(fa_), fm(fm_), ex(ex_), em(em_), dat(n_ * 4, ex), lazy(n_ * 4, em) { int x = 1; while (n_ > x) x *= 2; n = x; } void set(int i, X x) { dat[i + n - 1] = x; } void build() { for (int k = n - 2; k >= 0; k--) dat[k] = fx(dat[2 * k + 1], dat[2 * k + 2]); } void eval(int k) { if (lazy[k] == em) return; if (k < n - 1) { lazy[k * 2 + 1] = fm(lazy[k * 2 + 1], lazy[k]); lazy[k * 2 + 2] = fm(lazy[k * 2 + 2], lazy[k]); } dat[k] = fa(dat[k], lazy[k]); lazy[k] = em; } void update(int a, int b, M x, int k, int l, int r) { eval(k); if (a <= l && r <= b) { lazy[k] = fm(lazy[k], x); eval(k); } else if (a < r && l < b) { update(a, b, x, k * 2 + 1, l, (l + r) / 2); update(a, b, x, k * 2 + 2, (l + r) / 2, r); dat[k] = fx(dat[k * 2 + 1], dat[k * 2 + 2]); } } void update(int a, int b, M x) { update(a, b, x, 0, 0, n); } X query_sub(int a, int b, int k, int l, int r) { eval(k); if (r <= a || b <= l) { return ex; } else if (a <= l && r <= b) { return dat[k]; } else { X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2); X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r); return fx(vl, vr); } } X query(int a, int b) { return query_sub(a, b, 0, 0, n); } }; int main() { ll q; cin >> q; vector<ll> bik(2002008); bik[0] = 1; for (int i = 0; i < 2000104; i++) { bik[i + 1] = (i + 1) * bik[i] % 1000003; } for (int i = 0; i < q; i++) { ll a, b, c; cin >> a >> b >> c; ll d = modinv(b, 1000003) * a % 1000003; ll ans = bik[d + c - 1] * modinv(bik[d - 1], 1000003) % 1000003 * modpow(b, c, 1000003) % 1000003; cout << ans << endl; } }
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdint> #include <cstdio> #include <ctime> #include <deque> #include <float.h> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <type_traits> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using ll = long long; unsigned euclidean_gcd(unsigned a, unsigned b) { if (a < b) return euclidean_gcd(b, a); unsigned r; while ((r = a % b)) { a = b; b = r; } return b; } ll ll_gcd(ll a, ll b) { if (a < b) return ll_gcd(b, a); ll r; while ((r = a % b)) { a = b; b = r; } return b; } struct UnionFind { vector<ll> par; vector<ll> siz; UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); for (ll i = 0; i < sz_; ++i) par[i] = i; } ll root(ll x) { while (par[x] != x) { x = par[x] = par[par[x]]; } return x; } bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { return root(x) == root(y); } ll size(ll x) { return siz[root(x)]; } }; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } vector<int> tpsort(vector<vector<int>> &G) { int V = G.size(); vector<int> sorted_vertices; queue<int> que; vector<int> indegree(V); for (int i = 0; i < V; i++) { for (int j = 0; j < G[i].size(); j++) { indegree[G[i][j]]++; } } for (int i = 0; i < V; i++) { if (indegree[i] == 0) { que.push(i); } } while (que.empty() == false) { int v = que.front(); que.pop(); for (int i = 0; i < G[v].size(); i++) { int u = G[v][i]; indegree[u] -= 1; if (indegree[u] == 0) que.push(u); } sorted_vertices.push_back(v); } return sorted_vertices; } struct Point { double x; double y; }; struct LineSegment { Point start; Point end; }; double tenkyori(const LineSegment &line, const Point &point) { double x0 = point.x, y0 = point.y; double x1 = line.start.x, y1 = line.start.y; double x2 = line.end.x, y2 = line.end.y; double a = x2 - x1; double b = y2 - y1; double a2 = a * a; double b2 = b * b; double r2 = a2 + b2; double tt = -(a * (x1 - x0) + b * (y1 - y0)); if (tt < 0) return sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)); else if (tt > r2) return sqrt((x2 - x0) * (x2 - x0) + (y2 - y0) * (y2 - y0)); double f1 = a * (y1 - y0) - b * (x1 - x0); return sqrt((f1 * f1) / r2); } template <typename X> struct SegTree { using FX = function<X(X, X)>; // X•X -> X となる関数の型 int n; FX fx; const X ex; vector<X> dat; SegTree(int n_, FX fx_, X ex_) : n(), fx(fx_), ex(ex_), dat(n_ * 4, ex_) { int x = 1; while (n_ > x) { x *= 2; } n = x; } void set(int i, X x) { dat[i + n - 1] = x; } void build() { for (int k = n - 2; k >= 0; k--) dat[k] = fx(dat[2 * k + 1], dat[2 * k + 2]); } void update(int i, X x) { i += n - 1; dat[i] = x; while (i > 0) { i = (i - 1) / 2; // parent dat[i] = fx(dat[i * 2 + 1], dat[i * 2 + 2]); } } X query(int a, int b) { return query_sub(a, b, 0, 0, n); } X query_sub(int a, int b, int k, int l, int r) { if (r <= a || b <= l) { return ex; } else if (a <= l && r <= b) { return dat[k]; } else { X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2); X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r); return fx(vl, vr); } } }; template <typename X, typename M> struct SegTreeLazy { using FX = function<X(X, X)>; using FA = function<X(X, M)>; using FM = function<M(M, M)>; int n; FX fx; FA fa; FM fm; const X ex; const M em; vector<X> dat; vector<M> lazy; SegTreeLazy(int n_, FX fx_, FA fa_, FM fm_, X ex_, M em_) : n(), fx(fx_), fa(fa_), fm(fm_), ex(ex_), em(em_), dat(n_ * 4, ex), lazy(n_ * 4, em) { int x = 1; while (n_ > x) x *= 2; n = x; } void set(int i, X x) { dat[i + n - 1] = x; } void build() { for (int k = n - 2; k >= 0; k--) dat[k] = fx(dat[2 * k + 1], dat[2 * k + 2]); } void eval(int k) { if (lazy[k] == em) return; if (k < n - 1) { lazy[k * 2 + 1] = fm(lazy[k * 2 + 1], lazy[k]); lazy[k * 2 + 2] = fm(lazy[k * 2 + 2], lazy[k]); } dat[k] = fa(dat[k], lazy[k]); lazy[k] = em; } void update(int a, int b, M x, int k, int l, int r) { eval(k); if (a <= l && r <= b) { lazy[k] = fm(lazy[k], x); eval(k); } else if (a < r && l < b) { update(a, b, x, k * 2 + 1, l, (l + r) / 2); update(a, b, x, k * 2 + 2, (l + r) / 2, r); dat[k] = fx(dat[k * 2 + 1], dat[k * 2 + 2]); } } void update(int a, int b, M x) { update(a, b, x, 0, 0, n); } X query_sub(int a, int b, int k, int l, int r) { eval(k); if (r <= a || b <= l) { return ex; } else if (a <= l && r <= b) { return dat[k]; } else { X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2); X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r); return fx(vl, vr); } } X query(int a, int b) { return query_sub(a, b, 0, 0, n); } }; int main() { ll q; cin >> q; vector<ll> bik(2002008); bik[0] = 1; for (int i = 0; i < 2000104; i++) { bik[i + 1] = (i + 1) * bik[i] % 1000003; } for (int i = 0; i < q; i++) { ll a, b, c; cin >> a >> b >> c; if (b == 0) { cout << modpow(a, c, 1000003) << endl; continue; } if (c >= 1000003) { cout << 0 << endl; continue; } ll d = modinv(b, 1000003) * a % 1000003; ll ans = bik[d + c - 1] * modinv(bik[d - 1], 1000003) % 1000003 * modpow(b, c, 1000003) % 1000003; cout << ans << endl; } }
insert
280
280
280
288
0
p03027
C++
Runtime Error
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; struct __INIT { __INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } __init; #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define MOD 1000003 #define INF (1 << 30) #define LINF (1LL << 60) #define endl "\n" #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define reprev(i, n) for (int(i) = (n - 1); (i) >= 0; (i)--) #define Flag(x) (1 << (x)) #define Flagcount(x) __builtin_popcount(x) #define pint pair<int, int> #define pdouble pair<double, double> typedef unsigned long long int ull; typedef long long lint; long long fac[2200000], finv[2200000], inv[2200000]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < 2200000; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long long facdiv(lint n, lint k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return (fac[n] * finv[k]) % MOD; } long long powmod(lint a, lint b) { return b ? powmod(a * a % MOD, b / 2) * (b % 2 ? a : 1) % MOD : 1; } int main(void) { COMinit(); int Q; cin >> Q; rep(i, Q) { lint x, d, n; cin >> x >> d >> n; if (d == 1) cout << facdiv(x + n - 1, x - 1) << endl; else if (d == 0) cout << powmod(x, n) << endl; else { x = (x * powmod(d, MOD - 2)) % MOD; lint a = powmod(d, n); cout << (facdiv(x + n - 1, x - 1) * a) % MOD << endl; } } }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; struct __INIT { __INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } __init; #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define MOD 1000003 #define INF (1 << 30) #define LINF (1LL << 60) #define endl "\n" #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define reprev(i, n) for (int(i) = (n - 1); (i) >= 0; (i)--) #define Flag(x) (1 << (x)) #define Flagcount(x) __builtin_popcount(x) #define pint pair<int, int> #define pdouble pair<double, double> typedef unsigned long long int ull; typedef long long lint; long long fac[2200000], finv[2200000], inv[2200000]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < 2200000; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } long long facdiv(lint n, lint k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return (fac[n] * finv[k]) % MOD; } long long powmod(lint a, lint b) { return b ? powmod(a * a % MOD, b / 2) * (b % 2 ? a : 1) % MOD : 1; } int main(void) { COMinit(); int Q; cin >> Q; rep(i, Q) { lint x, d, n; cin >> x >> d >> n; if (d == 1) cout << facdiv(x + n - 1, x - 1) << endl; else if (d == 0) cout << powmod(x, n) << endl; else { x = (x * powmod(d, MOD - 2)) % MOD; lint a = powmod(d, n) % MOD; if (n > 1000003) cout << "0" << endl; else cout << (facdiv(x + n - 1, x - 1) * a) % MOD << endl; } } }
replace
60
62
60
65
0
p03027
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef vector<int> VI; typedef pair<int, int> ii; typedef long long LL; #define pb push_back const int INF = 2147483647; const int MOD = 1000003; int pot[MOD + 5], z, x, d, n, licz, mian, r; // rozwiązuje równanie ax=1(%MOD), gdy MOD pierwsze int inverse(int a, int n = MOD - 2) { int r = 1; while (n) { if (n % 2) r = (r * 1LL * a) % MOD; a = (a * 1LL * a) % MOD; n >>= 1; } return r; } // (a^b)%c int poteguj(int a, int b, int c = MOD) { int r = 1, m = a; while (b) { if (b % 2) r = (r * 1LL * m) % c; m = (m * 1LL * m) % c; b /= 2; } return r; } int main() { pot[0] = 1; for (int i = 1; i < MOD; i++) pot[i] = (pot[i - 1] * 1LL * i) % MOD; scanf("%d", &z); while (z--) { scanf("%d %d %d", &x, &d, &n); if (x == 0 || d == 0) { printf("%d\n", poteguj(x, n)); continue; } else if (d == 1) { if (x + n - 1 >= MOD) printf("0\n"); else { r = (pot[x + n - 1] * 1LL * inverse(pot[x - 1])) % MOD; printf("%d\n", r); } continue; } else { licz = (x * inverse(d)) % MOD + n - 1; mian = (x * inverse(d)) % MOD - 1; if (licz >= MOD) printf("0\n"); else { r = (pot[licz] * 1LL * inverse(pot[mian])) % MOD; r = (r * 1LL * poteguj(d, n)) % MOD; printf("%d\n", r); } } } }
#include <bits/stdc++.h> using namespace std; typedef vector<int> VI; typedef pair<int, int> ii; typedef long long LL; #define pb push_back const int INF = 2147483647; const int MOD = 1000003; int pot[MOD + 5], z, x, d, n, licz, mian, r; // rozwiązuje równanie ax=1(%MOD), gdy MOD pierwsze int inverse(int a, int n = MOD - 2) { int r = 1; while (n) { if (n % 2) r = (r * 1LL * a) % MOD; a = (a * 1LL * a) % MOD; n >>= 1; } return r; } // (a^b)%c int poteguj(int a, int b, int c = MOD) { int r = 1, m = a; while (b) { if (b % 2) r = (r * 1LL * m) % c; m = (m * 1LL * m) % c; b /= 2; } return r; } int main() { pot[0] = 1; for (int i = 1; i < MOD; i++) pot[i] = (pot[i - 1] * 1LL * i) % MOD; scanf("%d", &z); while (z--) { scanf("%d %d %d", &x, &d, &n); if (x == 0 || d == 0) { printf("%d\n", poteguj(x, n)); continue; } else if (d == 1) { if (x + n - 1 >= MOD) printf("0\n"); else { r = (pot[x + n - 1] * 1LL * inverse(pot[x - 1])) % MOD; printf("%d\n", r); } continue; } else { licz = (x * 1LL * inverse(d)) % MOD + n - 1; mian = (x * 1LL * inverse(d)) % MOD - 1; if (licz >= MOD) printf("0\n"); else { r = (pot[licz] * 1LL * inverse(pot[mian])) % MOD; r = (r * 1LL * poteguj(d, n)) % MOD; printf("%d\n", r); } } } }
replace
54
56
54
56
0
p03027
C++
Runtime Error
// --------------------------------------------------<TEMPLATE>-------------------------------------------------- // --------------------<optimizations>-------------------- #pragma GCC optimize("O3") //(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\ #pragma comment(linker, "/stack:200000000") //(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\ #pragma GCC optimize("unroll-loops") // -------------------</optimizations>-------------------- // ---------------<Headers and namespaces>---------------- #include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <ratio> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> using namespace __gnu_pbds; using namespace __gnu_cxx; // ---------------</Headers and namespaces>--------------- // -----------------<Defines and typedefs>---------------- typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; // order_of_key (val): returns the no. of values less than val // find_by_order (k): returns the iterator to kth largest element.(0-based) typedef long long ll; typedef long double LD; #define int ll #define double LD #define pb push_back #define mp make_pair #define REP(i, n) for (int i = 0; i < n; i++) #define FOR(i, a, b) for (int i = a; i < b; i++) #define REPD(i, n) for (int i = n - 1; i >= 0; i--) #define FORD(i, a, b) for (int i = a; i >= b; i--) #define remax(a, b) a = max(a, b) #define remin(a, b) a = min(a, b) #define all(v) v.begin(), v.end() typedef map<int, int> mii; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef vector<pii> vpii; #define F first #define S second #define PQ(type) priority_queue<type> #define PQD(type) priority_queue<type, vector<type>, greater<type>> #define ITR ::iterator it #define WL(t) while (t--) #define SZ(x) ((int)(x).size()) #define runtime() ((double)clock() / CLOCKS_PER_SEC) #define TR(container, it) \ for (typeof(container.begin()) it = container.begin(); \ it != container.end(); it++) #define sqr(x) ((x) * (x)) // -----<SCANF>----- #define sfi(x) scanf("%d", &x); #define sfi2(x, y) scanf("%d%d", &x, &y); #define sfi3(x, y, z) scanf("%d%d%d", &x, &y, &z); #define sfl(x) scanf("%lld", &x); #define sfl2(x, y) scanf("%lld%lld", &x, &y); #define sfl3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z); #define sfs(x) scanf("%s", x); #define sfs2(x, y) scanf("%s%s", x, y); #define sfs3(x, y, z) scanf("%s%s%s", x, y, z); // ----</SCANF>----- // ----<PRINTF>----- #define pfi(x) printf("%d\n", x); #define pfi2(x, y) printf("%d %d\n", x, y); #define pfi3(x, y, z) printf("%d %d %d\n", x, y, z); #define pfl(x) printf("%lld\n", x); #define pfl2(x, y) printf("%lld %lld\n", x, y); #define pfl3(x, y, z) printf("%lld %lld %lld\n", x, y, z); #define pfs(x) printf("%s\n", x); #define pfs2(x, y) printf("%s %s\n", x, y); #define pfs3(x, y, z) printf("%s %s %s\n", x, y, z); // ----</PRINTF>---- #define FLSH fflush(stdout) #define fileIO(name) \ freopen(name ".in", "r", stdin); \ freopen(name ".out", "w", stdout); #define PRECISION(x) cout << fixed << setprecision(x); #define FAST_IO \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); // ----------------</Defines and typedefs>---------------- // -------------------<Debugging stuff>------------------- #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << std::endl; } 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...); } #else #define trace(...) #endif // ------------------</Debugging stuff>------------------- // ------------------------<Consts>----------------------- const int MAXN = 1000005; const int SQRTN = 1003; const int LOGN = 22; const double PI = acos(-1); const int INF = 1000000000; const int MOD = 1000003; const int FMOD = 998244353; const double eps = 1e-9; // -----------------------</Consts>----------------------- // -------------------------<RNG>------------------------- mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); #define SHUF(v) shuffle(all(v), RNG); // Use mt19937_64 for 64 bit random numbers. // ------------------------</RNG>------------------------- // -----------------<Modular Arithmetic>------------------ template <typename T> T gcd(T a, T b) { return (b ? __gcd(a, b) : a); } template <typename T> T lcm(T a, T b) { return (a * (b / gcd(a, b))); } int add(int a, int b, int c) { int res = a + b; return (res >= c ? res - c : res); } int mod_neg(int a, int b, int c) { int res; if (abs(a - b) < c) res = a - b; else res = (a - b) % c; return (res < 0 ? res + c : res); } int mul(int a, int b, int c) { ll res = (ll)a * b; return (res >= c ? res % c : res); } ll mulmod(ll a, ll b, ll m) { ll q = (ll)(((LD)a * (LD)b) / (LD)m); ll r = a * b - q * m; if (r > m) r %= m; if (r < 0) r += m; return r; } template <typename T> T expo(T e, T n) { T x = 1, p = e; while (n) { if (n & 1) x = x * p; p = p * p; n >>= 1; } return x; } template <typename T> T power(T e, T n, T m) { T x = 1, p = e; while (n) { if (n & 1) x = mul(x, p, m); p = mul(p, p, m); n >>= 1; } return x; } template <typename T> T extended_euclid(T a, T b, T &x, T &y) { T xx = 0, yy = 1; y = 0; x = 1; while (b) { T q = a / b, t = b; b = a % b; a = t; t = xx; xx = x - q * xx; x = t; t = yy; yy = y - q * yy; y = t; } return a; } template <typename T> T mod_inverse(T a, T n) { T x, y, z = 0; T d = extended_euclid(a, n, x, y); return (d > 1 ? -1 : mod_neg(x, z, n)); } // -----------------</Modular Arithmetic>----------------- // --------------------------------------------------</TEMPLATE>-------------------------------------------------- int fact[MAXN + 5]; void solvethetestcase(); signed main() { fact[0] = 1; FOR(i, 1, MAXN) fact[i] = (i * fact[i - 1]) % MOD; // (UNCOMMENT FOR CIN/COUT) \ FAST_IO PRECISION(10) int t = 1; // (UNCOMMENT FOR MULTIPLE TEST CASES) sfl(t) FOR(testcase, 1, t + 1) { // (UNCOMMENT FOR CODEJAM) \ printf("Case #%lld: ",testcase); solvethetestcase(); } } int n, a, d; void solvethetestcase() { sfl3(a, d, n) int temp = a; temp *= mod_inverse(d, MOD); temp %= MOD; temp += n; if (temp > MOD or temp == n) pfi(0) else { int ans = fact[temp - 1]; ans *= mod_inverse(fact[temp - n - 1], MOD); ans %= MOD; ans *= power(d, n, MOD); ans %= MOD; pfl(ans) } }
// --------------------------------------------------<TEMPLATE>-------------------------------------------------- // --------------------<optimizations>-------------------- #pragma GCC optimize("O3") //(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\ #pragma comment(linker, "/stack:200000000") //(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\ #pragma GCC optimize("unroll-loops") // -------------------</optimizations>-------------------- // ---------------<Headers and namespaces>---------------- #include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <ratio> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> using namespace __gnu_pbds; using namespace __gnu_cxx; // ---------------</Headers and namespaces>--------------- // -----------------<Defines and typedefs>---------------- typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; // order_of_key (val): returns the no. of values less than val // find_by_order (k): returns the iterator to kth largest element.(0-based) typedef long long ll; typedef long double LD; #define int ll #define double LD #define pb push_back #define mp make_pair #define REP(i, n) for (int i = 0; i < n; i++) #define FOR(i, a, b) for (int i = a; i < b; i++) #define REPD(i, n) for (int i = n - 1; i >= 0; i--) #define FORD(i, a, b) for (int i = a; i >= b; i--) #define remax(a, b) a = max(a, b) #define remin(a, b) a = min(a, b) #define all(v) v.begin(), v.end() typedef map<int, int> mii; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int, int> pii; typedef vector<pii> vpii; #define F first #define S second #define PQ(type) priority_queue<type> #define PQD(type) priority_queue<type, vector<type>, greater<type>> #define ITR ::iterator it #define WL(t) while (t--) #define SZ(x) ((int)(x).size()) #define runtime() ((double)clock() / CLOCKS_PER_SEC) #define TR(container, it) \ for (typeof(container.begin()) it = container.begin(); \ it != container.end(); it++) #define sqr(x) ((x) * (x)) // -----<SCANF>----- #define sfi(x) scanf("%d", &x); #define sfi2(x, y) scanf("%d%d", &x, &y); #define sfi3(x, y, z) scanf("%d%d%d", &x, &y, &z); #define sfl(x) scanf("%lld", &x); #define sfl2(x, y) scanf("%lld%lld", &x, &y); #define sfl3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z); #define sfs(x) scanf("%s", x); #define sfs2(x, y) scanf("%s%s", x, y); #define sfs3(x, y, z) scanf("%s%s%s", x, y, z); // ----</SCANF>----- // ----<PRINTF>----- #define pfi(x) printf("%d\n", x); #define pfi2(x, y) printf("%d %d\n", x, y); #define pfi3(x, y, z) printf("%d %d %d\n", x, y, z); #define pfl(x) printf("%lld\n", x); #define pfl2(x, y) printf("%lld %lld\n", x, y); #define pfl3(x, y, z) printf("%lld %lld %lld\n", x, y, z); #define pfs(x) printf("%s\n", x); #define pfs2(x, y) printf("%s %s\n", x, y); #define pfs3(x, y, z) printf("%s %s %s\n", x, y, z); // ----</PRINTF>---- #define FLSH fflush(stdout) #define fileIO(name) \ freopen(name ".in", "r", stdin); \ freopen(name ".out", "w", stdout); #define PRECISION(x) cout << fixed << setprecision(x); #define FAST_IO \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); // ----------------</Defines and typedefs>---------------- // -------------------<Debugging stuff>------------------- #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << std::endl; } 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...); } #else #define trace(...) #endif // ------------------</Debugging stuff>------------------- // ------------------------<Consts>----------------------- const int MAXN = 1000005; const int SQRTN = 1003; const int LOGN = 22; const double PI = acos(-1); const int INF = 1000000000; const int MOD = 1000003; const int FMOD = 998244353; const double eps = 1e-9; // -----------------------</Consts>----------------------- // -------------------------<RNG>------------------------- mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); #define SHUF(v) shuffle(all(v), RNG); // Use mt19937_64 for 64 bit random numbers. // ------------------------</RNG>------------------------- // -----------------<Modular Arithmetic>------------------ template <typename T> T gcd(T a, T b) { return (b ? __gcd(a, b) : a); } template <typename T> T lcm(T a, T b) { return (a * (b / gcd(a, b))); } int add(int a, int b, int c) { int res = a + b; return (res >= c ? res - c : res); } int mod_neg(int a, int b, int c) { int res; if (abs(a - b) < c) res = a - b; else res = (a - b) % c; return (res < 0 ? res + c : res); } int mul(int a, int b, int c) { ll res = (ll)a * b; return (res >= c ? res % c : res); } ll mulmod(ll a, ll b, ll m) { ll q = (ll)(((LD)a * (LD)b) / (LD)m); ll r = a * b - q * m; if (r > m) r %= m; if (r < 0) r += m; return r; } template <typename T> T expo(T e, T n) { T x = 1, p = e; while (n) { if (n & 1) x = x * p; p = p * p; n >>= 1; } return x; } template <typename T> T power(T e, T n, T m) { T x = 1, p = e; while (n) { if (n & 1) x = mul(x, p, m); p = mul(p, p, m); n >>= 1; } return x; } template <typename T> T extended_euclid(T a, T b, T &x, T &y) { T xx = 0, yy = 1; y = 0; x = 1; while (b) { T q = a / b, t = b; b = a % b; a = t; t = xx; xx = x - q * xx; x = t; t = yy; yy = y - q * yy; y = t; } return a; } template <typename T> T mod_inverse(T a, T n) { T x, y, z = 0; T d = extended_euclid(a, n, x, y); return (d > 1 ? -1 : mod_neg(x, z, n)); } // -----------------</Modular Arithmetic>----------------- // --------------------------------------------------</TEMPLATE>-------------------------------------------------- int fact[MAXN + 5]; void solvethetestcase(); signed main() { fact[0] = 1; FOR(i, 1, MAXN) fact[i] = (i * fact[i - 1]) % MOD; // (UNCOMMENT FOR CIN/COUT) \ FAST_IO PRECISION(10) int t = 1; // (UNCOMMENT FOR MULTIPLE TEST CASES) sfl(t) FOR(testcase, 1, t + 1) { // (UNCOMMENT FOR CODEJAM) \ printf("Case #%lld: ",testcase); solvethetestcase(); } } int n, a, d; void solvethetestcase() { sfl3(a, d, n) if (d == 0) { pfl(power(a, n, MOD)) return; } int temp = a; temp *= mod_inverse(d, MOD); temp %= MOD; temp += n; if (temp > MOD or temp == n) pfi(0) else { int ans = fact[temp - 1]; ans *= mod_inverse(fact[temp - n - 1], MOD); ans %= MOD; ans *= power(d, n, MOD); ans %= MOD; pfl(ans) } }
replace
266
267
266
268
0
p03027
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #ifdef ONLINE_JUDGE #define LLD "%I64d" #else #define LLD "%lld" #endif #define fu(a, b, c) for (int a = b; a <= (int)c; ++a) #define fd(a, b, c) for (int a = b; a >= (int)c; --a) #define cu(a, b, c) for (int a = b; a < (int)c; ++a) #define cd(a, b, c) for (int a = (b)-1; a >= (int)c; --a) #define gcd(a, b) __gcd(a, b) #define pii pair<int, int> #define pll pair<long long, long long> #define all(a) a.begin(), a.end() #define F first #define S second #define pb push_back #define pf push_front #define MOD 1000003 #define MAXN 52 #define MAXH 20 #define MAXM 52 #define INF 100000000 #define ll long long #define ull unsigned long long #define RNG rng mt19937(time(NULL)) #define udist(a, b) uniform_int_distribution<uint32_t> distribution(a, b) #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define gmax(a, b) a = max(a, b) #define gmin(a, b) a = min(a, b) #define whatis(x) cerr << #x << " is " << x << endl; #define fast_io() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define PI 3.1415926535897932384626433 using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int N = 2000010; ll t[N << 1]; int sze; void init(int n) { sze = n; cu(i, 0, n) t[i + n] = i + 1; cd(i, n, 1) { t[i] = t[i << 1] * t[i << 1 | 1] % MOD; } } ll query(int l, int r) { ll res = 1; for (l += sze, r += sze; l < r; l >>= 1, r >>= 1) { if (l & 1) res = res * t[l++] % MOD; if (r & 1) res = res * t[--r] % MOD; } return res; } ll modpow(ll x, ll p) { if (p == 0) return 1; ll y = 1; while (p > 1) { if (p & 1) y = y * x % MOD; x = x * x % MOD; p >>= 1; } return x * y % MOD; } int main() { fast_io(); init(MOD * 2); int q; cin >> q; cu(i, 0, q) { ll x, d, n; cin >> x >> d >> n; ll ans = modpow(d, n); ll start = x * modpow(d, MOD - 2) % MOD; ans *= query(start - 1, start + n - 1); ans %= MOD; cout << ans << '\n'; } }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #ifdef ONLINE_JUDGE #define LLD "%I64d" #else #define LLD "%lld" #endif #define fu(a, b, c) for (int a = b; a <= (int)c; ++a) #define fd(a, b, c) for (int a = b; a >= (int)c; --a) #define cu(a, b, c) for (int a = b; a < (int)c; ++a) #define cd(a, b, c) for (int a = (b)-1; a >= (int)c; --a) #define gcd(a, b) __gcd(a, b) #define pii pair<int, int> #define pll pair<long long, long long> #define all(a) a.begin(), a.end() #define F first #define S second #define pb push_back #define pf push_front #define MOD 1000003 #define MAXN 52 #define MAXH 20 #define MAXM 52 #define INF 100000000 #define ll long long #define ull unsigned long long #define RNG rng mt19937(time(NULL)) #define udist(a, b) uniform_int_distribution<uint32_t> distribution(a, b) #define max3(a, b, c) max(a, max(b, c)) #define min3(a, b, c) min(a, min(b, c)) #define gmax(a, b) a = max(a, b) #define gmin(a, b) a = min(a, b) #define whatis(x) cerr << #x << " is " << x << endl; #define fast_io() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define PI 3.1415926535897932384626433 using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int N = 2000010; ll t[N << 1]; int sze; void init(int n) { sze = n; cu(i, 0, n) t[i + n] = i + 1; cd(i, n, 1) { t[i] = t[i << 1] * t[i << 1 | 1] % MOD; } } ll query(int l, int r) { ll res = 1; for (l += sze, r += sze; l < r; l >>= 1, r >>= 1) { if (l & 1) res = res * t[l++] % MOD; if (r & 1) res = res * t[--r] % MOD; } return res; } ll modpow(ll x, ll p) { if (p == 0) return 1; ll y = 1; while (p > 1) { if (p & 1) y = y * x % MOD; x = x * x % MOD; p >>= 1; } return x * y % MOD; } int main() { fast_io(); init(MOD * 2); int q; cin >> q; cu(i, 0, q) { ll x, d, n; cin >> x >> d >> n; if (d == 0) { cout << modpow(x, n) << '\n'; } else if (n >= MOD) { cout << 0 << '\n'; } else { ll ans = modpow(d, n); ll start = x * modpow(d, MOD - 2) % MOD; ans *= query(start - 1, start + n - 1); ans %= MOD; cout << ans << '\n'; } } }
replace
86
91
86
97
0
p03027
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <ctime> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef pair<int, int> P; typedef long long ll; const int mod = 1000003; /* class UnionFind{//UnionFind木 private: vector<int> Parent; public: UnionFind(int N){ vector<int> Parent(N,-1); } int root(int A){ if(Parent[A]<0) return A; return Parent[A]=root(Parent[A]); } int size(int A){ return -Parent[root(A)]; } bool connect(int A,int B){ A=root(A); B=root(B); if(A==B) return false; if(size(A)<size(B)) swap(A,B); Parent[A]-=Parent[B]; Parent[B]=A; } }; */ ll mpow(ll x, ll n) { // x^n(mod division) // ←普通にpow(x,n)では溢れてしまうため,随時mod計算 ll ans = 1; while (n != 0) { if (n & 1) ans = ans * x % mod; x = x * x % mod; n = n >> 1; } return ans; } ll inv_mod(ll a) { return mpow(a, mod - 2); } class Fuctorical { private: vector<ll> fac; public: Fuctorical(ll N) { fac.push_back(1); for (int i = 0; i < N; i++) fac.push_back(fac[i] * (i + 1) % mod); } ll fact(ll a) { return fac[a]; } ll ifact(ll a) { return inv_mod(fac[a]); } ll cmb(ll a, ll b) { if (a == 0 && b == 0) return 1; if (a < b || a < 0) return 0; ll tmp = ifact(a - b) * ifact(b) % mod; return tmp * fac[a] % mod; } }; int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }; // xとyの最大公約数 int main() { Fuctorical get(mod); int Q; cin >> Q; for (int i = 0; i < Q; i++) { ll x, d, n; cin >> x >> d >> n; if (d == 0) { cout << mpow(x, n) << endl; continue; } ll first = x * inv_mod(d) % mod; ll a = get.fact(first + n - 1) * get.ifact(first - 1) % mod; cout << a * mpow(d, n) % mod << endl; } }
#include <algorithm> #include <cmath> #include <cstdio> #include <ctime> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef pair<int, int> P; typedef long long ll; const int mod = 1000003; /* class UnionFind{//UnionFind木 private: vector<int> Parent; public: UnionFind(int N){ vector<int> Parent(N,-1); } int root(int A){ if(Parent[A]<0) return A; return Parent[A]=root(Parent[A]); } int size(int A){ return -Parent[root(A)]; } bool connect(int A,int B){ A=root(A); B=root(B); if(A==B) return false; if(size(A)<size(B)) swap(A,B); Parent[A]-=Parent[B]; Parent[B]=A; } }; */ ll mpow(ll x, ll n) { // x^n(mod division) // ←普通にpow(x,n)では溢れてしまうため,随時mod計算 ll ans = 1; while (n != 0) { if (n & 1) ans = ans * x % mod; x = x * x % mod; n = n >> 1; } return ans; } ll inv_mod(ll a) { return mpow(a, mod - 2); } class Fuctorical { private: vector<ll> fac; public: Fuctorical(ll N) { fac.push_back(1); for (int i = 0; i < N; i++) fac.push_back(fac[i] * (i + 1) % mod); } ll fact(ll a) { return fac[a]; } ll ifact(ll a) { return inv_mod(fac[a]); } ll cmb(ll a, ll b) { if (a == 0 && b == 0) return 1; if (a < b || a < 0) return 0; ll tmp = ifact(a - b) * ifact(b) % mod; return tmp * fac[a] % mod; } }; int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }; // xとyの最大公約数 int main() { Fuctorical get(mod); int Q; cin >> Q; for (int i = 0; i < Q; i++) { ll x, d, n; cin >> x >> d >> n; if (d == 0) { cout << mpow(x, n) << endl; continue; } ll first = x * inv_mod(d) % mod; if (first <= mod && mod <= first + n - 1) { cout << 0 << endl; continue; } ll a = get.fact(first + n - 1) * get.ifact(first - 1) % mod; cout << a * mpow(d, n) % mod << endl; } }
insert
97
97
97
101
0
p03027
C++
Runtime Error
#include <bits/stdc++.h> // using namespace std; #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define rep(i, j, n) for (ll i = (ll)(j); i < (ll)(n); i++) #define REP(i, j, n) for (ll i = (ll)(j); i <= (ll)(n); i++) #define per(i, j, n) for (ll i = (ll)(j); (ll)(n) <= i; i--) #define ll long long #define ALL(a) (a).begin(), (a).end() #define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (ll)(key))) #define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (ll)(key))) #define pb emplace_back #define mp std::make_pair // #define endl "\n" // using std::endl; using std::cin; using std::cout; using std::lower_bound; using std::string; using std::upper_bound; using std::vector; using vi = vector<ll>; using vii = vector<vi>; using pii = std::pair<ll, ll>; // constexpr ll MOD = 1e9 + 7; // constexpr ll MOD=998244353; // constexpr ll MOD=10000000; // constexpr ll MOD=1e4; constexpr ll MAX = 3e6; constexpr ll inf = (1ll << 60); template <class T> class prique : public std::priority_queue<T, std::vector<T>, std::greater<T>> { }; template <typename T> struct Segment_tree { ll N; T mem; vector<T> node; Segment_tree(vector<T> &X, T m) : mem(m) { ll sz = X.size(); N = 1; while (N < sz) N *= 2; node.resize(2 * N - 1, mem); rep(i, 0, sz) node[N - 1 + i] = X[i]; per(i, N - 2, 0) { node[i] = Compare(node[i * 2 + 1], node[i * 2 + 2]); } } T Compare(T &A, T &B) { return std::max(A, B); } void update(ll X, T val) { X += N - 1; node[X] = val; while (X > 0) { X = (X - 1) / 2; node[X] = Compare(node[X * 2 + 1], node[X * 2 + 2]); } } T Query(ll a, ll b, ll now, ll l, ll r) { //[a,b),[l,r) if (r < 0) r = N; if (r <= a || b <= l) return mem; if (a <= l && r <= b) return node[now]; auto vl = Query(a, b, now * 2 + 1, l, (l + r) / 2), vr = Query(a, b, now * 2 + 2, (l + r) / 2, r); return Compare(vl, vr); } }; template <typename T> struct lazy_Segment_tree { int N; vector<T> node, lazy; T INF; lazy_Segment_tree(vector<T> X, T Y) : INF(Y) { N = 1; while (X.size() > N) N *= 2; node.resize(2 * N - 1, Y); lazy.resize(2 * N - 1); rep(i, 0, X.size()) node[i + N - 1] = X[i]; per(i, N - 2, 0) node[i] = compare(node[i * 2 + 1], node[i * 2 + 2]); } T compare(T X, T Y) { return std::max(X, Y); } T plus(T X, int l, int r) { return X; } void eval(int now, int l, int r) { if (lazy[now] == 0) return; node[now] += lazy[now]; if (r - l > 1) { lazy[now * 2 + 1] += plus(lazy[now], l, r); lazy[now * 2 + 2] += plus(lazy[now], l, r); } lazy[now] = 0; } void update(int a, int b, T add, int now = 0, int l = 0, int r = -1) { if (r < 0) r = N; eval(now, l, r); if (b <= l || r <= a) return; if (a <= l && r <= b) { lazy[now] += add; eval(now, l, r); } else { update(a, b, add, now * 2 + 1, l, (r + l) / 2); update(a, b, add, now * 2 + 2, (r + l) / 2, r); node[now] = compare(node[now * 2 + 1], node[now * 2 + 2]); } } T Query(int a, int b, int now = 0, int l = 0, int r = -1) { if (r < 0) r = N; eval(now, l, r); if (b <= l || r <= a) return INF; if (a <= l && r <= b) return node[now]; return compare(Query(a, b, now * 2 + 1, l, (r + l) / 2), Query(a, b, now * 2 + 2, (r + l) / 2, r)); } }; struct Tree { int N; vii dp; vi dist; Tree(vii edge) { N = edge.size(); dp.resize(N); dist.resize(N, -1); for (int i = 0; i < N; i++) dp[i].resize(30); dist[0] = dp[0][0] = 0; std::queue<int> que; que.push(0); while (!que.empty()) { int now = que.front(); que.pop(); for (int i = 0; i < edge[now].size(); i++) { int next = edge[now][i]; if (dist[next] == -1) { dist[next] = dist[now] + 1; que.push(next); dp[next][0] = now; } } } for (int i = 1; i < 30; i++) { for (int j = 0; j < N; j++) dp[j][i] = dp[dp[j][i - 1]][i - 1]; } } int LCA(int X, int Y) { if (dist[X] < dist[Y]) std::swap(X, Y); { int Z = dist[X] - dist[Y]; for (int i = 0; i < 30; i++) { if (Z & (1 << i)) { X = dp[X][i]; } } } if (X == Y) return X; for (int i = 29; i >= 0; i--) { if (dp[X][i] != dp[Y][i]) { X = dp[X][i]; Y = dp[Y][i]; } } return dp[X][0]; } }; struct Binary_indexed_tree { int N; vi bit; Binary_indexed_tree(int n) : N(n) { bit.resize(N + 1, 0); } void add(int x, ll a) { for (x; x <= N; x += (x & -x)) bit[x] += a; } ll sum(int x) { ll ret = 0; for (x; x > 0; x -= (x & -x)) ret += bit[x]; return ret; } ll lower_bound(ll X) { if (sum(N) < X) return -1; ll ret = 0, memo = 1, sum = 0; while (memo * 2 <= N) memo *= 2; while (memo > 0) { if (memo + ret <= N && sum + bit[memo + ret] < X) { sum += bit[memo + ret]; ret += memo; } memo /= 2; } return ret + 1; } }; struct Union_Find { ll N; vi par; vi siz; Union_Find(int n) : N(n) { par.resize(N); siz.resize(N, 1); rep(i, 0, N) par[i] = i; } ll root(ll X) { if (par[X] == X) return X; return par[X] = root(par[X]); } bool same(ll X, ll Y) { return root(X) == root(Y); } void unite(ll X, ll Y) { X = root(X); Y = root(Y); if (X == Y) return; par[X] = Y; siz[Y] += siz[X]; siz[X] = 0; } ll size(ll X) { return siz[root(X)]; } }; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } vi fac, finv, inv; void COMinit() { fac.resize(MAX); finv.resize(MAX); inv.resize(MAX); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll COM(ll n, ll r) { if (n < r || n < 0 || r < 0) return 0; return fac[n] * finv[r] % MOD * finv[n - r] % MOD; } void comp(vi &A) { std::map<ll, ll> memo; rep(i, 0, A.size()) memo[A[i]] = 0; ll cnt = 1; for (auto &p : memo) p.second = cnt++; rep(i, 0, A.size()) A[i] = memo[A[i]]; } void dec(std::map<ll, ll> &mem, ll X) { mem[X]--; if (mem[X] == 0) mem.erase(X); } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); ll Q; cin >> Q; const ll mod = 1e6 + 3; vi fac(mod); fac[0] = 1; rep(i, 1, mod) { fac[i] = fac[i - 1] * i % mod; } while (Q--) { ll X, D, N; cin >> X >> D >> N; ll ans = 1; if (D == 0) ans = modpow(X, N, mod); else if (N >= mod) ans = 0; else { X *= modpow(D, mod - 2, mod); X %= mod; ll Y = X + N - 1; if (X > Y) ans = 0; else { ans = fac[Y] * modpow(fac[X], mod - 2, mod) % mod * X % mod * modpow(D, N, mod) % mod; } } cout << ans << endl; } }
#include <bits/stdc++.h> // using namespace std; #pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define rep(i, j, n) for (ll i = (ll)(j); i < (ll)(n); i++) #define REP(i, j, n) for (ll i = (ll)(j); i <= (ll)(n); i++) #define per(i, j, n) for (ll i = (ll)(j); (ll)(n) <= i; i--) #define ll long long #define ALL(a) (a).begin(), (a).end() #define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (ll)(key))) #define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (ll)(key))) #define pb emplace_back #define mp std::make_pair // #define endl "\n" // using std::endl; using std::cin; using std::cout; using std::lower_bound; using std::string; using std::upper_bound; using std::vector; using vi = vector<ll>; using vii = vector<vi>; using pii = std::pair<ll, ll>; // constexpr ll MOD = 1e9 + 7; // constexpr ll MOD=998244353; // constexpr ll MOD=10000000; // constexpr ll MOD=1e4; constexpr ll MAX = 3e6; constexpr ll inf = (1ll << 60); template <class T> class prique : public std::priority_queue<T, std::vector<T>, std::greater<T>> { }; template <typename T> struct Segment_tree { ll N; T mem; vector<T> node; Segment_tree(vector<T> &X, T m) : mem(m) { ll sz = X.size(); N = 1; while (N < sz) N *= 2; node.resize(2 * N - 1, mem); rep(i, 0, sz) node[N - 1 + i] = X[i]; per(i, N - 2, 0) { node[i] = Compare(node[i * 2 + 1], node[i * 2 + 2]); } } T Compare(T &A, T &B) { return std::max(A, B); } void update(ll X, T val) { X += N - 1; node[X] = val; while (X > 0) { X = (X - 1) / 2; node[X] = Compare(node[X * 2 + 1], node[X * 2 + 2]); } } T Query(ll a, ll b, ll now, ll l, ll r) { //[a,b),[l,r) if (r < 0) r = N; if (r <= a || b <= l) return mem; if (a <= l && r <= b) return node[now]; auto vl = Query(a, b, now * 2 + 1, l, (l + r) / 2), vr = Query(a, b, now * 2 + 2, (l + r) / 2, r); return Compare(vl, vr); } }; template <typename T> struct lazy_Segment_tree { int N; vector<T> node, lazy; T INF; lazy_Segment_tree(vector<T> X, T Y) : INF(Y) { N = 1; while (X.size() > N) N *= 2; node.resize(2 * N - 1, Y); lazy.resize(2 * N - 1); rep(i, 0, X.size()) node[i + N - 1] = X[i]; per(i, N - 2, 0) node[i] = compare(node[i * 2 + 1], node[i * 2 + 2]); } T compare(T X, T Y) { return std::max(X, Y); } T plus(T X, int l, int r) { return X; } void eval(int now, int l, int r) { if (lazy[now] == 0) return; node[now] += lazy[now]; if (r - l > 1) { lazy[now * 2 + 1] += plus(lazy[now], l, r); lazy[now * 2 + 2] += plus(lazy[now], l, r); } lazy[now] = 0; } void update(int a, int b, T add, int now = 0, int l = 0, int r = -1) { if (r < 0) r = N; eval(now, l, r); if (b <= l || r <= a) return; if (a <= l && r <= b) { lazy[now] += add; eval(now, l, r); } else { update(a, b, add, now * 2 + 1, l, (r + l) / 2); update(a, b, add, now * 2 + 2, (r + l) / 2, r); node[now] = compare(node[now * 2 + 1], node[now * 2 + 2]); } } T Query(int a, int b, int now = 0, int l = 0, int r = -1) { if (r < 0) r = N; eval(now, l, r); if (b <= l || r <= a) return INF; if (a <= l && r <= b) return node[now]; return compare(Query(a, b, now * 2 + 1, l, (r + l) / 2), Query(a, b, now * 2 + 2, (r + l) / 2, r)); } }; struct Tree { int N; vii dp; vi dist; Tree(vii edge) { N = edge.size(); dp.resize(N); dist.resize(N, -1); for (int i = 0; i < N; i++) dp[i].resize(30); dist[0] = dp[0][0] = 0; std::queue<int> que; que.push(0); while (!que.empty()) { int now = que.front(); que.pop(); for (int i = 0; i < edge[now].size(); i++) { int next = edge[now][i]; if (dist[next] == -1) { dist[next] = dist[now] + 1; que.push(next); dp[next][0] = now; } } } for (int i = 1; i < 30; i++) { for (int j = 0; j < N; j++) dp[j][i] = dp[dp[j][i - 1]][i - 1]; } } int LCA(int X, int Y) { if (dist[X] < dist[Y]) std::swap(X, Y); { int Z = dist[X] - dist[Y]; for (int i = 0; i < 30; i++) { if (Z & (1 << i)) { X = dp[X][i]; } } } if (X == Y) return X; for (int i = 29; i >= 0; i--) { if (dp[X][i] != dp[Y][i]) { X = dp[X][i]; Y = dp[Y][i]; } } return dp[X][0]; } }; struct Binary_indexed_tree { int N; vi bit; Binary_indexed_tree(int n) : N(n) { bit.resize(N + 1, 0); } void add(int x, ll a) { for (x; x <= N; x += (x & -x)) bit[x] += a; } ll sum(int x) { ll ret = 0; for (x; x > 0; x -= (x & -x)) ret += bit[x]; return ret; } ll lower_bound(ll X) { if (sum(N) < X) return -1; ll ret = 0, memo = 1, sum = 0; while (memo * 2 <= N) memo *= 2; while (memo > 0) { if (memo + ret <= N && sum + bit[memo + ret] < X) { sum += bit[memo + ret]; ret += memo; } memo /= 2; } return ret + 1; } }; struct Union_Find { ll N; vi par; vi siz; Union_Find(int n) : N(n) { par.resize(N); siz.resize(N, 1); rep(i, 0, N) par[i] = i; } ll root(ll X) { if (par[X] == X) return X; return par[X] = root(par[X]); } bool same(ll X, ll Y) { return root(X) == root(Y); } void unite(ll X, ll Y) { X = root(X); Y = root(Y); if (X == Y) return; par[X] = Y; siz[Y] += siz[X]; siz[X] = 0; } ll size(ll X) { return siz[root(X)]; } }; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } vi fac, finv, inv; void COMinit() { fac.resize(MAX); finv.resize(MAX); inv.resize(MAX); fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } ll COM(ll n, ll r) { if (n < r || n < 0 || r < 0) return 0; return fac[n] * finv[r] % MOD * finv[n - r] % MOD; } void comp(vi &A) { std::map<ll, ll> memo; rep(i, 0, A.size()) memo[A[i]] = 0; ll cnt = 1; for (auto &p : memo) p.second = cnt++; rep(i, 0, A.size()) A[i] = memo[A[i]]; } void dec(std::map<ll, ll> &mem, ll X) { mem[X]--; if (mem[X] == 0) mem.erase(X); } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); ll Q; cin >> Q; const ll mod = 1e6 + 3; vi fac(mod); fac[0] = 1; rep(i, 1, mod) { fac[i] = fac[i - 1] * i % mod; } while (Q--) { ll X, D, N; cin >> X >> D >> N; ll ans = 1; if (D == 0) ans = modpow(X, N, mod); else if (N >= mod) ans = 0; else { X *= modpow(D, mod - 2, mod); X %= mod; ll Y = X + N - 1; Y %= mod; if (X > Y) ans = 0; else { ans = fac[Y] * modpow(fac[X], mod - 2, mod) % mod * X % mod * modpow(D, N, mod) % mod; } } cout << ans << endl; } }
insert
294
294
294
295
0
p03027
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long using namespace std; vector<ll> fct, invfct; ll mod_pow(ll n, ll p, ll mod) { // 繰り返し二乗法で (n^p) % mod を求める if (p == 0) return 1; ll res = mod_pow(n * n % mod, p / 2, mod); if (p % 2 == 1) res = res * n % mod; return res; } ll calc(ll x, ll n, ll mod) { if (x == 0 || x + n - 1 >= mod) { // (2-a) の場合 return 0; } else { // (2-b) の場合 return fct[x + n - 1] * invfct[x - 1] % mod; } } int main() { int Q; cin >> Q; ll mod = 1000003; // mod-1 までの階乗を求める。 fct = vector<ll>(mod, 1); for (int i = 1; i < 2 * mod; i++) { fct[i] = fct[i - 1] * i % mod; } // mod-1 までの階乗の逆数を求める。 invfct = vector<ll>(mod, 1); invfct[mod - 1] = mod_pow(mod - 1, mod - 2, mod); for (int i = mod - 2; i >= 1; i--) { invfct[i] = invfct[i + 1] * (i + 1) % mod; } while (Q--) { ll x, d, n; cin >> x >> d >> n; if (d == 0) { // (1) の場合。 x^n を計算する。 cout << mod_pow(x, n, mod) << endl; } else if (d == 1) { // (2) の場合。 cout << calc(x, n, mod) << endl; } else { // (3) の場合。 // x を x/d の mod で置き換えて(2)の計算をし、最後に d^n を掛ける。 x = x * mod_pow(d, mod - 2, mod) % mod; cout << mod_pow(d, n, mod) * calc(x, n, mod) % mod << endl; } } }
#include <bits/stdc++.h> #define ll long long using namespace std; vector<ll> fct, invfct; ll mod_pow(ll n, ll p, ll mod) { // 繰り返し二乗法で (n^p) % mod を求める if (p == 0) return 1; ll res = mod_pow(n * n % mod, p / 2, mod); if (p % 2 == 1) res = res * n % mod; return res; } ll calc(ll x, ll n, ll mod) { if (x == 0 || x + n - 1 >= mod) { // (2-a) の場合 return 0; } else { // (2-b) の場合 return fct[x + n - 1] * invfct[x - 1] % mod; } } int main() { int Q; cin >> Q; ll mod = 1000003; // mod-1 までの階乗を求める。 fct = vector<ll>(mod, 1); for (int i = 1; i < mod; i++) { fct[i] = fct[i - 1] * i % mod; } // mod-1 までの階乗の逆数を求める。 invfct = vector<ll>(mod, 1); invfct[mod - 1] = mod_pow(mod - 1, mod - 2, mod); for (int i = mod - 2; i >= 1; i--) { invfct[i] = invfct[i + 1] * (i + 1) % mod; } while (Q--) { ll x, d, n; cin >> x >> d >> n; if (d == 0) { // (1) の場合。 x^n を計算する。 cout << mod_pow(x, n, mod) << endl; } else if (d == 1) { // (2) の場合。 cout << calc(x, n, mod) << endl; } else { // (3) の場合。 // x を x/d の mod で置き換えて(2)の計算をし、最後に d^n を掛ける。 x = x * mod_pow(d, mod - 2, mod) % mod; cout << mod_pow(d, n, mod) * calc(x, n, mod) % mod << endl; } } }
replace
33
34
33
34
-11
p03027
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; #define REP(i, n) for (ll i = 0; i < n; i++) #define REP1(i, n) for (ll i = 1; i < n; i++) #define REPR(i, n) for (ll i = n - 1; i >= 0; i--) #define FOR(i, m, n) for (ll i = m; i < n; i++) #define VSORT(v) sort(v.begin(), v.end()) #define VRSORT(v) sort(v.rbegin(), v.rend()) #define ll long long #define ALL(a) (a).begin(), (a).end() #define pb(a) push_back(a) #define MOD 1000003 vector<ll> stk; // l~rまでリダクションしたいときの // a/b mod c ll moddiv(ll a, ll b) { ll x0 = MOD, x1 = b, x2, n0 = 0LL, n1 = 1LL, n2, t = a % b, m, ans; if (t == 0) return a / b; for (int i = 0; i < 900; i++) { m = x0 / x1; x2 = x0 - x1 * m; n2 = (n0 - m * n1) % MOD; if (x2 == 1) { ans = (n2 + MOD) % MOD; break; } x0 = x1; x1 = x2; n0 = n1; n1 = n2; } return (a + ((t * ans) % MOD) * b - t) / b; } // 剰余の割ざん // aのn乗 mod c ll expmod(ll a, ll n) { ll ans = 1LL, aa = a, beki = n; for (int i = 0; i < 64; i++) { if (beki % 2 == 1) ans = ans * aa % MOD; aa = aa * aa % MOD; beki /= 2; if (beki == 0) break; } return ans; } ////////////////////////////////////////////////////////////////////////O(N ///logN)リダクション bool Chkbit(int num, int n) { return ((num >> n) % 2 == 1); } int Log2u(int num) { // 自分含むより高い次にくる2^NとなるNを返す int rsznum = num - 1; int beki = 0; for (int i = 0; i < 32; i++) { if (rsznum == 0) { beki = i; break; } rsznum /= 2; } return beki; } ll Makestk_f0(ll a1, ll a2) { return a1 * a2 % MOD; // ●●●●●●●●●●●●●●●●●●●●●●● } void Makestk(ll num) { int beki = Log2u(num) + 1; int rsznum = 1 << beki; stk.resize(rsznum); // 初期値設定●●●●●●●●●●●●●●●●●●●●●●● for (int i = 0; i < num; i++) { stk[i] = (ll)i; } // 初期値0埋め●●●●●●●●●●●●●●●●●●●●●●● for (int i = num; i < rsznum / 2; i++) { stk[i] = 1LL; } // 2こ1にまとめていく。1レイヤーごと半分になっていく // 初期レイヤー含めずあとbeki個必要 int ofst = rsznum / 2; int ofstp = 0; // 1個まえのofst for (int j = beki - 2; j >= 0; j--) { int bk1 = 1 << j; for (int i = 0; i < bk1; i++) { stk[ofst + i] = Makestk_f0(stk[ofstp + i * 2], stk[ofstp + i * 2 + 1]); } ofstp = ofst; ofst += bk1; } } // stk前半データに対し0~n-1までのリダクション施行した結果を返す ll Reduc0(int n) { int nn = n; ll ans = 1LL; // ●●●●●●●●●●●●●●●●●●●●●●● int sz = stk.size() / 2; int ofst = 0; int beki = Log2u(sz); for (; nn > 0; nn >>= 1) { if (nn % 2 == 1) { ans = Makestk_f0(ans, stk[ofst + nn - 1]); } ofst += 1 << beki; beki--; } return ans; } // stk前半データに対しl~r-1までのリダクション施行した結果を返す ll Reduc1(int l, int r) { int nn = r; int mm = l; ll ans = 1LL; // ●●●●●●●●●●●●●●●●●●●●●●● int sz = stk.size() / 2; int ofst = 0; int beki = Log2u(sz); int i = 0; for (int i = 0; (nn + mm) > 0; i++) { if (nn % 2 == 1) { if (nn - 1 >= mm) { ans = Makestk_f0(ans, stk[ofst + nn - 1]); nn--; } } if (mm % 2 == 1) { if (mm < nn) { ans = Makestk_f0(ans, stk[ofst + mm]); mm++; } } nn >>= 1; mm >>= 1; ofst += 1 << (beki - i); } return ans; } ////////////////////////////////////////////////////////////////////////O(N ///logN)リダクション int main() { Makestk(MOD); ll q, x, d, n, y; ll ans = 1LL; cin >> q; REP(i, q) { cin >> x >> d >> n; y = moddiv(x, d); // y~y+n-1までリダクション掛け算 ll loop = (y + n - 1) / MOD; if (loop != 0) { cout << 0 << endl; continue; } ll red = Reduc1(y, y + n); ans = red * expmod(d, n) % MOD; cout << ans << endl; } return 0; }
#include "bits/stdc++.h" using namespace std; #define REP(i, n) for (ll i = 0; i < n; i++) #define REP1(i, n) for (ll i = 1; i < n; i++) #define REPR(i, n) for (ll i = n - 1; i >= 0; i--) #define FOR(i, m, n) for (ll i = m; i < n; i++) #define VSORT(v) sort(v.begin(), v.end()) #define VRSORT(v) sort(v.rbegin(), v.rend()) #define ll long long #define ALL(a) (a).begin(), (a).end() #define pb(a) push_back(a) #define MOD 1000003 vector<ll> stk; // l~rまでリダクションしたいときの // a/b mod c ll moddiv(ll a, ll b) { ll x0 = MOD, x1 = b, x2, n0 = 0LL, n1 = 1LL, n2, t = a % b, m, ans; if (t == 0) return a / b; for (int i = 0; i < 900; i++) { m = x0 / x1; x2 = x0 - x1 * m; n2 = (n0 - m * n1) % MOD; if (x2 == 1) { ans = (n2 + MOD) % MOD; break; } x0 = x1; x1 = x2; n0 = n1; n1 = n2; } return (a + ((t * ans) % MOD) * b - t) / b; } // 剰余の割ざん // aのn乗 mod c ll expmod(ll a, ll n) { ll ans = 1LL, aa = a, beki = n; for (int i = 0; i < 64; i++) { if (beki % 2 == 1) ans = ans * aa % MOD; aa = aa * aa % MOD; beki /= 2; if (beki == 0) break; } return ans; } ////////////////////////////////////////////////////////////////////////O(N ///logN)リダクション bool Chkbit(int num, int n) { return ((num >> n) % 2 == 1); } int Log2u(int num) { // 自分含むより高い次にくる2^NとなるNを返す int rsznum = num - 1; int beki = 0; for (int i = 0; i < 32; i++) { if (rsznum == 0) { beki = i; break; } rsznum /= 2; } return beki; } ll Makestk_f0(ll a1, ll a2) { return a1 * a2 % MOD; // ●●●●●●●●●●●●●●●●●●●●●●● } void Makestk(ll num) { int beki = Log2u(num) + 1; int rsznum = 1 << beki; stk.resize(rsznum); // 初期値設定●●●●●●●●●●●●●●●●●●●●●●● for (int i = 0; i < num; i++) { stk[i] = (ll)i; } // 初期値0埋め●●●●●●●●●●●●●●●●●●●●●●● for (int i = num; i < rsznum / 2; i++) { stk[i] = 1LL; } // 2こ1にまとめていく。1レイヤーごと半分になっていく // 初期レイヤー含めずあとbeki個必要 int ofst = rsznum / 2; int ofstp = 0; // 1個まえのofst for (int j = beki - 2; j >= 0; j--) { int bk1 = 1 << j; for (int i = 0; i < bk1; i++) { stk[ofst + i] = Makestk_f0(stk[ofstp + i * 2], stk[ofstp + i * 2 + 1]); } ofstp = ofst; ofst += bk1; } } // stk前半データに対し0~n-1までのリダクション施行した結果を返す ll Reduc0(int n) { int nn = n; ll ans = 1LL; // ●●●●●●●●●●●●●●●●●●●●●●● int sz = stk.size() / 2; int ofst = 0; int beki = Log2u(sz); for (; nn > 0; nn >>= 1) { if (nn % 2 == 1) { ans = Makestk_f0(ans, stk[ofst + nn - 1]); } ofst += 1 << beki; beki--; } return ans; } // stk前半データに対しl~r-1までのリダクション施行した結果を返す ll Reduc1(int l, int r) { int nn = r; int mm = l; ll ans = 1LL; // ●●●●●●●●●●●●●●●●●●●●●●● int sz = stk.size() / 2; int ofst = 0; int beki = Log2u(sz); int i = 0; for (int i = 0; (nn + mm) > 0; i++) { if (nn % 2 == 1) { if (nn - 1 >= mm) { ans = Makestk_f0(ans, stk[ofst + nn - 1]); nn--; } } if (mm % 2 == 1) { if (mm < nn) { ans = Makestk_f0(ans, stk[ofst + mm]); mm++; } } nn >>= 1; mm >>= 1; ofst += 1 << (beki - i); } return ans; } ////////////////////////////////////////////////////////////////////////O(N ///logN)リダクション int main() { Makestk(MOD); ll q, x, d, n, y; ll ans = 1LL; cin >> q; REP(i, q) { cin >> x >> d >> n; if (d == 0) { cout << (expmod(x, n) % MOD) << endl; continue; } y = moddiv(x, d); // y~y+n-1までリダクション掛け算 ll loop = (y + n - 1) / MOD; if (loop != 0) { cout << 0 << endl; continue; } ll red = Reduc1(y, y + n); ans = red * expmod(d, n) % MOD; cout << ans << endl; } return 0; }
insert
162
162
162
166
0
p03027
C++
Runtime Error
#include <algorithm> #include <iostream> #include <math.h> #include <vector> using namespace std; typedef long long ll; ll inf = 1000003; ll pw(ll x, ll y) { if (y == 0) return 1; else if (y == 1) return x % inf; else if (y % 2 == 0) return pw(x, y / 2) * pw(x, y / 2) % inf; else return pw(x, y / 2) * pw(x, y / 2) % inf * x % inf; } ll dv(ll x, ll y) { return x * pw(y, inf - 2) % inf; } int main(void) { int q; ll pile[3000010]; cin >> q; for (int i = 1; i < 2 * inf; i++) { if (i == 1) pile[i] = 1; else pile[i] = pile[i - 1] * i % inf; } for (int i = 0; i < q; i++) { ll x, d, n; cin >> x >> d >> n; if (d == 0) cout << pw(x, n) << endl; else { if (dv(x, d + n - 1) >= inf) cout << 0 << endl; else cout << pw(d, n) * pile[dv(x, d) + n - 1] % inf * dv(1, pile[dv(x, d) - 1]) % inf << endl; } } }
#include <algorithm> #include <iostream> #include <math.h> #include <vector> using namespace std; typedef long long ll; ll inf = 1000003; ll pw(ll x, ll y) { if (y == 0) return 1; else if (y == 1) return x % inf; else if (y % 2 == 0) return pw(x, y / 2) * pw(x, y / 2) % inf; else return pw(x, y / 2) * pw(x, y / 2) % inf * x % inf; } ll dv(ll x, ll y) { return x * pw(y, inf - 2) % inf; } int main(void) { int q; ll pile[3000010]; cin >> q; for (int i = 1; i < 2 * inf; i++) { if (i == 1) pile[i] = 1; else pile[i] = pile[i - 1] * i % inf; } for (int i = 0; i < q; i++) { ll x, d, n; cin >> x >> d >> n; if (d == 0) cout << pw(x, n) << endl; else { if (dv(x, d) + n - 1 >= inf) cout << 0 << endl; else cout << pw(d, n) * pile[dv(x, d) + n - 1] % inf * dv(1, pile[dv(x, d) - 1]) % inf << endl; } } }
replace
41
42
41
42
-11
p03027
C++
Runtime Error
#include <bits/stdc++.h> #define mod 1000003 #define fr first #define se second #define ll long long #define PI 3.1415926535 #define pb push_back #define mpr make_pair #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define senky_bansal ios_base::sync_with_stdio(false); #define IIIT_ALLAHABAD \ cin.tie(NULL); \ cout.tie(NULL); using namespace std; ll fac[1000003]; ll ifac[1000003]; ll power(ll a, ll b) { ll res = 1; while (b) { a %= mod; if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b = b / 2; } return res % mod; } signed main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif senky_bansal IIIT_ALLAHABAD fac[0] = 1; fac[1] = 1; for (int i = 2; i < 1000003; i++) fac[i] = (i * fac[i - 1]) % mod; ifac[1000002] = power(fac[1000002], mod - 2); for (int i = 1000001; i >= 0; i--) { ifac[i] = ((i + 1) * ifac[i + 1]) % mod; } ll q; cin >> q; while (q--) { ll x, d, n; cin >> x >> d >> n; if (d == 0) { cout << power(x, n) << endl; } else { // cout<<ifac[d]<<endl; // cout<<power(d,mod-2)<<endl; ll p = (x * power(d, mod - 2)) % mod; ll r = power(d, n); if (p + n - 1 >= mod) { cout << "0" << endl; } else { cout << ((fac[p + n - 1] * power(fac[p - 1], mod - 2)) % mod * r) % mod << endl; } } } }
#include <bits/stdc++.h> #define mod 1000003 #define fr first #define se second #define ll long long #define PI 3.1415926535 #define pb push_back #define mpr make_pair #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() #define senky_bansal ios_base::sync_with_stdio(false); #define IIIT_ALLAHABAD \ cin.tie(NULL); \ cout.tie(NULL); using namespace std; ll fac[1000003]; ll ifac[1000003]; ll power(ll a, ll b) { ll res = 1; while (b) { a %= mod; if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b = b / 2; } return res % mod; } signed main() { senky_bansal IIIT_ALLAHABAD fac[0] = 1; fac[1] = 1; for (int i = 2; i < 1000003; i++) fac[i] = (i * fac[i - 1]) % mod; ifac[1000002] = power(fac[1000002], mod - 2); for (int i = 1000001; i >= 0; i--) { ifac[i] = ((i + 1) * ifac[i + 1]) % mod; } ll q; cin >> q; while (q--) { ll x, d, n; cin >> x >> d >> n; if (d == 0) { cout << power(x, n) << endl; } else { // cout<<ifac[d]<<endl; // cout<<power(d,mod-2)<<endl; ll p = (x * power(d, mod - 2)) % mod; ll r = power(d, n); if (p + n - 1 >= mod) { cout << "0" << endl; } else { cout << ((fac[p + n - 1] * power(fac[p - 1], mod - 2)) % mod * r) % mod << endl; } } } }
delete
29
33
29
29
TLE
p03027
Python
Time Limit Exceeded
# https://atcoder.jp/contests/m-solutions2019/submissions/5741430 from operator import mul MOD = 10**6 + 3 def inv(n): return pow(n, MOD - 2, MOD) def mod_mul(x, y): return mul(x, y) % MOD fact = [1] for n in range(1, MOD): fact.append(mod_mul(fact[-1], n)) # d>1 の数列を d=1 となる数列に変換する # MODの倍数を含む数列の積は0になるので, # MODの倍数を含まない区間の積が計算できればよい # そのような区間の右端はMOD-1であり,fact[MOD-1]が計算できればよい Q = int(input()) for _ in range(Q): x, d, n = map(int, input().split()) if x == 0: print(0) continue if d == 0: print(pow(x, n, MOD)) continue xd = mod_mul(x, inv(d)) if MOD - xd < n: print(0) continue dn = pow(d, n, MOD) print(mod_mul(mod_mul(fact[xd + n - 1], inv(fact[xd - 1])), dn))
# https://atcoder.jp/contests/m-solutions2019/submissions/5741430 from operator import mul import sys input = sys.stdin.readline MOD = 10**6 + 3 def inv(n): return pow(n, MOD - 2, MOD) def mod_mul(x, y): return mul(x, y) % MOD fact = [1] for n in range(1, MOD): fact.append(mod_mul(fact[-1], n)) # d>1 の数列を d=1 となる数列に変換する # MODの倍数を含む数列の積は0になるので, # MODの倍数を含まない区間の積が計算できればよい # そのような区間の右端はMOD-1であり,fact[MOD-1]が計算できればよい Q = int(input()) for _ in range(Q): x, d, n = map(int, input().split()) if x == 0: print(0) continue if d == 0: print(pow(x, n, MOD)) continue xd = mod_mul(x, inv(d)) if MOD - xd < n: print(0) continue dn = pow(d, n, MOD) print(mod_mul(mod_mul(fact[xd + n - 1], inv(fact[xd - 1])), dn))
insert
2
2
2
5
TLE
p03027
C++
Runtime Error
/* -*- coding: utf-8 -*- * * e.cc: E - Product of Arithmetic Progression */ #include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; /* constant */ const int MOD = 1000003; const int MAX_K = MOD * 2; /* typedef */ typedef long long ll; /* global variables */ int fracs[MAX_K + 1], invfs[MAX_K + 1]; /* subroutines */ ll powmod(ll a, int n) { // a^n % MOD ll pm = 1; while (n > 0) { if (n & 1) pm = (pm * a) % MOD; a = (a * a) % MOD; n >>= 1; } return pm; } /* main */ int main() { fracs[0] = invfs[0] = 1; for (int i = 1; i <= MAX_K; i++) { fracs[i] = (ll)fracs[i - 1] * i % MOD; invfs[i] = powmod(fracs[i], MOD - 2); } int q; scanf("%d", &q); while (q--) { int x, d, n; scanf("%d%d%d", &x, &d, &n); int sum = 0; if (d == 0) sum = powmod(x, n); else { int y = (ll)x * powmod(d, MOD - 2) % MOD; sum = fracs[y + n - 1]; if (y > 0) sum = (ll)sum * invfs[y - 1] % MOD; sum = (ll)sum * powmod(d, n) % MOD; } printf("%d\n", sum); } return 0; }
/* -*- coding: utf-8 -*- * * e.cc: E - Product of Arithmetic Progression */ #include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; /* constant */ const int MOD = 1000003; const int MAX_K = MOD * 2; /* typedef */ typedef long long ll; /* global variables */ int fracs[MAX_K + 1], invfs[MAX_K + 1]; /* subroutines */ ll powmod(ll a, int n) { // a^n % MOD ll pm = 1; while (n > 0) { if (n & 1) pm = (pm * a) % MOD; a = (a * a) % MOD; n >>= 1; } return pm; } /* main */ int main() { fracs[0] = invfs[0] = 1; for (int i = 1; i <= MAX_K; i++) { fracs[i] = (ll)fracs[i - 1] * i % MOD; invfs[i] = powmod(fracs[i], MOD - 2); } int q; scanf("%d", &q); while (q--) { int x, d, n; scanf("%d%d%d", &x, &d, &n); int sum = 0; if (d == 0) sum = powmod(x, n); else if (n < MOD) { int y = (ll)x * powmod(d, MOD - 2) % MOD; sum = fracs[y + n - 1]; if (y > 0) sum = (ll)sum * invfs[y - 1] % MOD; sum = (ll)sum * powmod(d, n) % MOD; } printf("%d\n", sum); } return 0; }
replace
71
72
71
72
0
p03027
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) //~ #define MOD 1000000007 #define MOD 1000003 #define INF 0x3f3f3f3f #define INFL 0x3f3f3f3f3f3f3f3f using namespace std; typedef long long ll; typedef pair<int, int> P; ll ppow(ll a, ll b) { a %= MOD; ll res = 1; while (b) { if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; b >>= 1; } return res; } class Fact { vector<ll> fact; vector<ll> inv; public: Fact() {} Fact(int n) { n = n * 2 + 10; fact = inv = vector<ll>(n); fact[0] = inv[0] = 1; for (int i = 1; i < n; i++) { fact[i] = (fact[i - 1] * i) % MOD; inv[i] = ppow(fact[i], MOD - 2); } } ll get(int n) { return fact[n]; } ll nPr(int n, int r) { return fact[n] * inv[n - r] % MOD; } ll nCr(int n, int r) { return nPr(n, r) * inv[r] % MOD; } ll nrP(int n, int r) { return nPr(n + r, n); } ll nrC(int n, int r) { return nCr(n + r, n); } }; // 負の数にも対応した mod // 例えば -17 を 5 で割った余りは本当は 3 (-17 ≡ 3 (mod. 5)) // しかし単に -17 % 5 では -2 になってしまう inline long long mod(long long a, long long m) { return (a % m + m) % m; } // 拡張 Euclid の互除法 // ap + bq = gcd(a, b) となる (p, q) を求め、d = gcd(a, b) をリターンします long long extGcd(long long a, long long b, long long &p, long long &q) { if (b == 0) { p = 1; q = 0; return a; } long long d = extGcd(b, a % b, q, p); q -= a / b * p; return d; } // 中国剰余定理 // リターン値を (r, m) とすると解は x ≡ r (mod. m) // 解なしの場合は (0, -1) をリターン pair<long long, long long> ChineseRem(long long b1, long long m1, long long b2, long long m2) { long long p, q; long long d = extGcd(m1, m2, p, q); // p is inv of m1/d (mod. m2/d) if ((b2 - b1) % d != 0) return make_pair(0, -1); long long m = m1 * (m2 / d); // lcm of (m1, m2) long long tmp = (b2 - b1) / d * p % (m2 / d); long long r = mod(b1 + m1 * tmp, m); return make_pair(r, m); } int main() { Fact fac(1000000); int q; cin >> q; rep(i, q) { ll x, d, n; scanf("%lld%lld%lld", &x, &d, &n); if (x == 0) { puts("0"); continue; } if (d == 0) { printf("%lld\n", ppow(x, n)); continue; } auto p = ChineseRem(x % d, d, 0, MOD); ll a = (x + p.first - 1) / p.first * p.first; if ((a - x) / d < n) { puts("0"); continue; } ll ans = ppow(d, n) * fac.get((x * ppow(d, MOD - 2) + n + MOD - 1) % MOD) % MOD * ppow(fac.get((x * ppow(d, MOD - 2) + MOD - 1) % MOD), MOD - 2) % MOD; printf("%lld\n", ans); } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) //~ #define MOD 1000000007 #define MOD 1000003 #define INF 0x3f3f3f3f #define INFL 0x3f3f3f3f3f3f3f3f using namespace std; typedef long long ll; typedef pair<int, int> P; ll ppow(ll a, ll b) { a %= MOD; ll res = 1; while (b) { if (b & 1) res = (res * a) % MOD; a = (a * a) % MOD; b >>= 1; } return res; } class Fact { vector<ll> fact; vector<ll> inv; public: Fact() {} Fact(int n) { n = n * 2 + 10; fact = inv = vector<ll>(n); fact[0] = inv[0] = 1; for (int i = 1; i < n; i++) { fact[i] = (fact[i - 1] * i) % MOD; inv[i] = ppow(fact[i], MOD - 2); } } ll get(int n) { return fact[n]; } ll nPr(int n, int r) { return fact[n] * inv[n - r] % MOD; } ll nCr(int n, int r) { return nPr(n, r) * inv[r] % MOD; } ll nrP(int n, int r) { return nPr(n + r, n); } ll nrC(int n, int r) { return nCr(n + r, n); } }; // 負の数にも対応した mod // 例えば -17 を 5 で割った余りは本当は 3 (-17 ≡ 3 (mod. 5)) // しかし単に -17 % 5 では -2 になってしまう inline long long mod(long long a, long long m) { return (a % m + m) % m; } // 拡張 Euclid の互除法 // ap + bq = gcd(a, b) となる (p, q) を求め、d = gcd(a, b) をリターンします long long extGcd(long long a, long long b, long long &p, long long &q) { if (b == 0) { p = 1; q = 0; return a; } long long d = extGcd(b, a % b, q, p); q -= a / b * p; return d; } // 中国剰余定理 // リターン値を (r, m) とすると解は x ≡ r (mod. m) // 解なしの場合は (0, -1) をリターン pair<long long, long long> ChineseRem(long long b1, long long m1, long long b2, long long m2) { long long p, q; long long d = extGcd(m1, m2, p, q); // p is inv of m1/d (mod. m2/d) if ((b2 - b1) % d != 0) return make_pair(0, -1); long long m = m1 * (m2 / d); // lcm of (m1, m2) long long tmp = (b2 - b1) / d * p % (m2 / d); long long r = mod(b1 + m1 * tmp, m); return make_pair(r, m); } int main() { Fact fac(1000000); int q; cin >> q; rep(i, q) { ll x, d, n; scanf("%lld%lld%lld", &x, &d, &n); if (x == 0) { puts("0"); continue; } if (d == 0) { printf("%lld\n", ppow(x, n)); continue; } auto p = ChineseRem(x % d, d, 0, MOD); ll a = (x - p.first + p.second - 1) / p.second * p.second + p.first; if ((a - x) / d < n) { puts("0"); continue; } ll ans = ppow(d, n) * fac.get((x * ppow(d, MOD - 2) + n + MOD - 1) % MOD) % MOD * ppow(fac.get((x * ppow(d, MOD - 2) + MOD - 1) % MOD), MOD - 2) % MOD; printf("%lld\n", ans); } }
replace
92
93
92
93
0
p03027
C++
Runtime Error
#include <algorithm> #include <iostream> #include <math.h> #include <queue> #include <stdlib.h> #include <string.h> #include <string> #include <vector> using namespace std; int mod = 1000003; ///////////// modの計算 long long mod_adjust(long long a) { // 余りをとる(0~mod-1に調整する) if (a > mod) { return a % mod; } if (a < 0) { a *= -1; a %= mod; return mod - a; } return a; } int mod_adjust(int a) { // 余りをとる(0~mod-1に調整する) return (int)mod_adjust((long long)a); } int mod_add(int a, int b) { // 足し算 a = mod_adjust(a), b = mod_adjust(b); long long k = a % mod; k += b % mod; k %= mod; return (int)k; } int mod_sub(int a, int b) { // 引き算 long long k = mod_adjust((long long)a); k += mod_adjust((long long)b); k %= mod; return (int)k; } int mod_multi(int a, int b) { // 掛け算 long long k = mod_adjust((long long)a); k *= mod_adjust((long long)b); k %= mod; return (int)k; } int mod_inv(int a) { // 逆元 a = mod_adjust(a); if (a == 1) { return 1; } long long p = mod, q = a, m = 0, n = 1, r, c; while (q > 1) { r = p % q; c = p / q; c = mod_adjust(m - n * c); p = q, m = n, q = r, n = c; } return n; } int mod_div(int a, int b) { // 割り算 return mod_multi(a, mod_inv(b)); } int mod_pow(int x, int n) { // 累乗(logNオーダーなので速い) if (n < 0) { return mod_pow(mod_div(1, x), -n); } if (n == 0) { return 1; } if (n == 1) { return x; } if (n % 2 == 0) { int k = mod_pow(x, n / 2); return mod_multi(k, k); } else { int k = mod_pow(x, n / 2); return mod_multi(mod_multi(k, k), x); } } int *factorial = NULL; // 階乗 int *factorial_inv = NULL; // 階乗の逆元 // 階乗を事前に計算しておく関数。 // Nはmod_combination(n, r)で呼び出されうる最大の数。 void calc_factorial( int N) { ////////////////////////// 初めに必ず呼び出すこと!!! factorial = new int[N + 1]; factorial_inv = new int[N + 1]; factorial[0] = 1; factorial_inv[0] = 1; for (int i = 1; i <= N; i++) { if (i >= mod) { factorial[i] = 0; factorial_inv[i] = 0; } else { factorial[i] = mod_multi(factorial[i - 1], i); factorial_inv[i] = mod_inv(factorial[i]); } } } int mod_combination(int n, int r) { // nCr を計算する if (n < 0 || r < 0 || r > n) { return 0; } return mod_multi(factorial[n], mod_multi(factorial_inv[n - r], factorial_inv[r])); } int main() { calc_factorial(mod); int Q; cin >> Q; for (int q = 0; q < Q; q++) { int x, d, n; cin >> x >> d >> n; x = x % mod, d = d % mod; if (d == 0) { cout << mod_pow(x, n) << endl; continue; } x = mod_div(x, d); int a = x - 1, b = x + n - 1; if (b >= mod) { cout << 0 << endl; } int prod = mod_div(factorial[b], factorial[a]); prod = mod_multi(prod, mod_pow(d, n)); cout << prod << endl; } return 0; }
#include <algorithm> #include <iostream> #include <math.h> #include <queue> #include <stdlib.h> #include <string.h> #include <string> #include <vector> using namespace std; int mod = 1000003; ///////////// modの計算 long long mod_adjust(long long a) { // 余りをとる(0~mod-1に調整する) if (a > mod) { return a % mod; } if (a < 0) { a *= -1; a %= mod; return mod - a; } return a; } int mod_adjust(int a) { // 余りをとる(0~mod-1に調整する) return (int)mod_adjust((long long)a); } int mod_add(int a, int b) { // 足し算 a = mod_adjust(a), b = mod_adjust(b); long long k = a % mod; k += b % mod; k %= mod; return (int)k; } int mod_sub(int a, int b) { // 引き算 long long k = mod_adjust((long long)a); k += mod_adjust((long long)b); k %= mod; return (int)k; } int mod_multi(int a, int b) { // 掛け算 long long k = mod_adjust((long long)a); k *= mod_adjust((long long)b); k %= mod; return (int)k; } int mod_inv(int a) { // 逆元 a = mod_adjust(a); if (a == 1) { return 1; } long long p = mod, q = a, m = 0, n = 1, r, c; while (q > 1) { r = p % q; c = p / q; c = mod_adjust(m - n * c); p = q, m = n, q = r, n = c; } return n; } int mod_div(int a, int b) { // 割り算 return mod_multi(a, mod_inv(b)); } int mod_pow(int x, int n) { // 累乗(logNオーダーなので速い) if (n < 0) { return mod_pow(mod_div(1, x), -n); } if (n == 0) { return 1; } if (n == 1) { return x; } if (n % 2 == 0) { int k = mod_pow(x, n / 2); return mod_multi(k, k); } else { int k = mod_pow(x, n / 2); return mod_multi(mod_multi(k, k), x); } } int *factorial = NULL; // 階乗 int *factorial_inv = NULL; // 階乗の逆元 // 階乗を事前に計算しておく関数。 // Nはmod_combination(n, r)で呼び出されうる最大の数。 void calc_factorial( int N) { ////////////////////////// 初めに必ず呼び出すこと!!! factorial = new int[N + 1]; factorial_inv = new int[N + 1]; factorial[0] = 1; factorial_inv[0] = 1; for (int i = 1; i <= N; i++) { if (i >= mod) { factorial[i] = 0; factorial_inv[i] = 0; } else { factorial[i] = mod_multi(factorial[i - 1], i); factorial_inv[i] = mod_inv(factorial[i]); } } } int mod_combination(int n, int r) { // nCr を計算する if (n < 0 || r < 0 || r > n) { return 0; } return mod_multi(factorial[n], mod_multi(factorial_inv[n - r], factorial_inv[r])); } int main() { calc_factorial(mod); int Q; cin >> Q; for (int q = 0; q < Q; q++) { int x, d, n; cin >> x >> d >> n; x = x % mod, d = d % mod; if (d == 0) { cout << mod_pow(x, n) << endl; continue; } x = mod_div(x, d); int a = x - 1, b = x + n - 1; if (b >= mod) { cout << 0 << endl; continue; } int prod = mod_div(factorial[b], factorial[a]); prod = mod_multi(prod, mod_pow(d, n)); cout << prod << endl; } return 0; }
insert
133
133
133
134
0
p03027
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define int long long #define double long double #define mod 1000003 #define P pair<long long, long long> #define all(a) a.begin(), a.end() #define INF 10000000000000000 template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; // power_mod inline int Pow_mod(int x, int pow) { if (pow == 0) return 1; int a = Pow_mod(x, pow / 2); a = a * a % mod; if (pow % 2 == 1) a *= x; return a % mod; } int fact[1000010]; signed main(void) { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); fact[0] = 1; rep(i, 1000005) fact[i + 1] = fact[i] * (i + 1) % mod; int q; cin >> q; rep(i, q) { int x, d, n; cin >> x >> d >> n; if (d == 0) { cout << Pow_mod(x, n) << endl; continue; } int newx = x * Pow_mod(d, mod - 2) % mod; if (mod < newx + n or newx == 0) cout << 0 << endl; cout << fact[newx + n - 1] * Pow_mod(fact[newx - 1], mod - 2) % mod * Pow_mod(d, n) % mod << endl; ; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define int long long #define double long double #define mod 1000003 #define P pair<long long, long long> #define all(a) a.begin(), a.end() #define INF 10000000000000000 template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; // power_mod inline int Pow_mod(int x, int pow) { if (pow == 0) return 1; int a = Pow_mod(x, pow / 2); a = a * a % mod; if (pow % 2 == 1) a *= x; return a % mod; } int fact[1000010]; signed main(void) { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); fact[0] = 1; rep(i, 1000005) fact[i + 1] = fact[i] * (i + 1) % mod; int q; cin >> q; rep(i, q) { int x, d, n; cin >> x >> d >> n; if (d == 0) { cout << Pow_mod(x, n) << endl; continue; } int newx = x * Pow_mod(d, mod - 2) % mod; if (mod < newx + n or newx == 0) cout << 0 << endl; else cout << fact[newx + n - 1] * Pow_mod(fact[newx - 1], mod - 2) % mod * Pow_mod(d, n) % mod << endl; } }
replace
57
61
57
61
0
p03027
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b)) #define REP(i, n) for (int i = 0; i < n; i++) #define FOR(i, n1, n2) for (int i = n1; i < n2; i++) #define speed_up \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); typedef long long int ll; typedef pair<ll, ll> Pi; const int INF = (ll)(1LL << 31) - 1; const ll INFl = (ll)9223372036854775807; const int MAX = 10000; const ll MOD = (ll)1e9 + 7; const ll MODI = (ll)1e6 + 3; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1}; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } ll mod_pow(ll x, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } int q; int x[100100], d[100100], n[100100]; ll xnd[1000100LL], xd[1000100LL]; int main() { cin >> q; REP(i, q) { cin >> x[i] >> d[i] >> n[i]; } xnd[0] = 1; for (ll i = 1; i <= 1000050; i++) { xnd[i] = (xnd[i - 1] * i) % MODI; } xd[1000002] = mod_pow(xnd[1000002], MODI - 2, MODI); for (ll i = 1000002; i > 0; i--) { xd[i - 1] = (xd[i] * i % MODI); } // cout<<"2"<<endl; for (int i = 0; i < q; i++) { if (d[i] == 0) { cout << mod_pow(x[i], n[i], MODI) << endl; /*}else if(((x[i]*mod_pow(d[i],MODI-2,MODI)-1))/MODI!=(((x[i]*mod_pow(d[i],MODI-2,MODI))+n[i-1]))/MODI){ cout<<0<<endl;*/ } else { auto ii = x[i] * mod_pow(d[i], MODI - 2, MODI) % MODI; if (ii + n[i] - 1 >= MODI || ii == 0) cout << 0 << endl; // cout<<xd[ii-1]<<endl; cout << (xnd[ii + n[i] - 1] * xd[ii - 1] % MODI) * mod_pow(d[i], n[i], MODI) % MODI << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b)) #define REP(i, n) for (int i = 0; i < n; i++) #define FOR(i, n1, n2) for (int i = n1; i < n2; i++) #define speed_up \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); typedef long long int ll; typedef pair<ll, ll> Pi; const int INF = (ll)(1LL << 31) - 1; const ll INFl = (ll)9223372036854775807; const int MAX = 10000; const ll MOD = (ll)1e9 + 7; const ll MODI = (ll)1e6 + 3; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1}; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } ll mod_pow(ll x, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } int q; int x[100100], d[100100], n[100100]; ll xnd[1000100LL], xd[1000100LL]; int main() { cin >> q; REP(i, q) { cin >> x[i] >> d[i] >> n[i]; } xnd[0] = 1; for (ll i = 1; i <= 1000050; i++) { xnd[i] = (xnd[i - 1] * i) % MODI; } xd[1000002] = mod_pow(xnd[1000002], MODI - 2, MODI); for (ll i = 1000002; i > 0; i--) { xd[i - 1] = (xd[i] * i % MODI); } // cout<<"2"<<endl; for (int i = 0; i < q; i++) { if (d[i] == 0) { cout << mod_pow(x[i], n[i], MODI) << endl; /*}else if(((x[i]*mod_pow(d[i],MODI-2,MODI)-1))/MODI!=(((x[i]*mod_pow(d[i],MODI-2,MODI))+n[i-1]))/MODI){ cout<<0<<endl;*/ } else { auto ii = x[i] * mod_pow(d[i], MODI - 2, MODI) % MODI; if (ii + n[i] - 1 >= MODI || ii == 0) cout << 0 << endl; // cout<<xd[ii-1]<<endl; else cout << (xnd[ii + n[i] - 1] * xd[ii - 1] % MODI) * mod_pow(d[i], n[i], MODI) % MODI << endl; } } return 0; }
replace
67
70
67
71
0
p03027
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define ll long long using ull = unsigned long long; using namespace std; const int INF = 1ll << 50; const int MOD = 1000003; #define dump(x) \ if (dbg) { \ cerr << #x << " = " << (x) << endl; \ } #define overload4(_1, _2, _3, _4, name, ...) name #define FOR1(n) for (ll i = 0; i < (n); ++i) #define FOR2(i, n) for (ll i = 0; i < (n); ++i) #define FOR3(i, a, b) for (ll i = (a); i < (b); ++i) #define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c)) #define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__) #define FORR(i, a, b) for (int i = (a); i <= (b); ++i) #define bit(n, k) ((n >> k) & 1) /*nのk bit目*/ template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } else return 0; } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } else return 0; } void Yes(bool flag = true) { if (flag) cout << "Yes" << endl; else cout << "No" << endl; } void No(bool flag = true) { Yes(!flag); } void YES(bool flag = true) { if (flag) cout << "YES" << endl; else cout << "NO" << endl; } void NO(bool flag = true) { YES(!flag); } #define pb push_back #define mp make_pair #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(v) (v).begin(), (v).end() #define SZ(x) ((int)(x).size()) #define vi vector<int> // #define P pair<int, int> // #define V vector<int> // #define S set<int> #define itn int bool dbg = false; template <uint MD> struct ModInt { using M = ModInt; const static M G; uint v; ModInt(ll _v = 0) { set_v(_v % MD + MD); } M &set_v(uint _v) { v = (_v < MD) ? _v : _v - MD; return *this; } explicit operator bool() const { return v != 0; } M operator-() const { return M() - *this; } M operator+(const M &r) const { return M().set_v(v + r.v); } M operator-(const M &r) const { return M().set_v(v + MD - r.v); } M operator*(const M &r) const { return M().set_v(ull(v) * r.v % MD); } M operator/(const M &r) const { return *this * r.inv(); } M &operator+=(const M &r) { return *this = *this + r; } M &operator-=(const M &r) { return *this = *this - r; } M &operator*=(const M &r) { return *this = *this * r; } M &operator/=(const M &r) { return *this = *this / r; } bool operator==(const M &r) const { return v == r.v; } M pow(ll n) const { M x = *this, r = 1; while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } M inv() const { return pow(MD - 2); } friend ostream &operator<<(ostream &os, const M &r) { return os << r.v; } friend istream &operator>>(istream &is, M &r) { return is >> r.v; } }; using Mint = ModInt<MOD>; int Q; Mint kai[2010101]; void solve() { kai[0] = 1; FOR(i, 1, 2010001) { kai[i] = kai[i - 1] * i; } while (Q--) { Mint x, d; int n; cin >> x >> d >> n; if (d == Mint{0} || x == Mint{0}) { cout << x.pow(n) << endl; } x /= d; if (x.v + n - 1 >= 1000003) { cout << 0 << endl; } else { cout << kai[x.v + n - 1] / kai[x.v - 1] * d.pow(n) << endl; } } } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin >> Q; solve(); return 0; }
#include <bits/stdc++.h> #define int long long #define ll long long using ull = unsigned long long; using namespace std; const int INF = 1ll << 50; const int MOD = 1000003; #define dump(x) \ if (dbg) { \ cerr << #x << " = " << (x) << endl; \ } #define overload4(_1, _2, _3, _4, name, ...) name #define FOR1(n) for (ll i = 0; i < (n); ++i) #define FOR2(i, n) for (ll i = 0; i < (n); ++i) #define FOR3(i, a, b) for (ll i = (a); i < (b); ++i) #define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c)) #define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__) #define FORR(i, a, b) for (int i = (a); i <= (b); ++i) #define bit(n, k) ((n >> k) & 1) /*nのk bit目*/ template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } else return 0; } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } else return 0; } void Yes(bool flag = true) { if (flag) cout << "Yes" << endl; else cout << "No" << endl; } void No(bool flag = true) { Yes(!flag); } void YES(bool flag = true) { if (flag) cout << "YES" << endl; else cout << "NO" << endl; } void NO(bool flag = true) { YES(!flag); } #define pb push_back #define mp make_pair #define eb emplace_back #define lb lower_bound #define ub upper_bound #define all(v) (v).begin(), (v).end() #define SZ(x) ((int)(x).size()) #define vi vector<int> // #define P pair<int, int> // #define V vector<int> // #define S set<int> #define itn int bool dbg = false; template <uint MD> struct ModInt { using M = ModInt; const static M G; uint v; ModInt(ll _v = 0) { set_v(_v % MD + MD); } M &set_v(uint _v) { v = (_v < MD) ? _v : _v - MD; return *this; } explicit operator bool() const { return v != 0; } M operator-() const { return M() - *this; } M operator+(const M &r) const { return M().set_v(v + r.v); } M operator-(const M &r) const { return M().set_v(v + MD - r.v); } M operator*(const M &r) const { return M().set_v(ull(v) * r.v % MD); } M operator/(const M &r) const { return *this * r.inv(); } M &operator+=(const M &r) { return *this = *this + r; } M &operator-=(const M &r) { return *this = *this - r; } M &operator*=(const M &r) { return *this = *this * r; } M &operator/=(const M &r) { return *this = *this / r; } bool operator==(const M &r) const { return v == r.v; } M pow(ll n) const { M x = *this, r = 1; while (n) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; } M inv() const { return pow(MD - 2); } friend ostream &operator<<(ostream &os, const M &r) { return os << r.v; } friend istream &operator>>(istream &is, M &r) { return is >> r.v; } }; using Mint = ModInt<MOD>; int Q; Mint kai[2010101]; void solve() { kai[0] = 1; FOR(i, 1, 2010001) { kai[i] = kai[i - 1] * i; } while (Q--) { Mint x, d; int n; cin >> x >> d >> n; if (d == Mint{0} || x == Mint{0}) { cout << x.pow(n) << endl; continue; } x /= d; if (x.v + n - 1 >= 1000003) { cout << 0 << endl; } else { cout << kai[x.v + n - 1] / kai[x.v - 1] * d.pow(n) << endl; } } } signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); cin >> Q; solve(); return 0; }
insert
107
107
107
108
0
p03027
C++
Runtime Error
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; using ll = long long; typedef pair<ll, ll> P; #define fi first #define se second #define all(v) (v).begin(), (v).end() const ll inf = (1e18); const ll mod = 1000003; // ios_base::sync_with_stdio(false); // cin.tie(NULL); ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } struct __INIT { __INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } __init; 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; } map<P, ll> mp; const ll MAX = 2000010; // 設定して long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; // *1 finv[i] = finv[i - 1] * inv[i] % mod; } } // 階乗 long long factor(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return (fac[n] * finv[k]) % mod; } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } // aの逆元求めるならn=mod-2 long long modpow(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main() { init(); int q; cin >> q; while (q--) { ll x, d, n; cin >> x >> d >> n; if (x == 0) cout << 0 << endl; else if (d == 0) { cout << modpow(x, n) << endl; } else if (d == 1) { if (n > mod) cout << 0 << endl; else cout << factor(x + n - 1, x - 1) << endl; } else { x *= modpow(d, mod - 2); x %= mod; cout << (factor(x + n - 1, x - 1) * modpow(d, n)) % mod << endl; } } }
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; using ll = long long; typedef pair<ll, ll> P; #define fi first #define se second #define all(v) (v).begin(), (v).end() const ll inf = (1e18); const ll mod = 1000003; // ios_base::sync_with_stdio(false); // cin.tie(NULL); ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } struct __INIT { __INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } __init; 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; } map<P, ll> mp; const ll MAX = 2000010; // 設定して long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; // *1 finv[i] = finv[i - 1] * inv[i] % mod; } } // 階乗 long long factor(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return (fac[n] * finv[k]) % mod; } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } // aの逆元求めるならn=mod-2 long long modpow(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main() { init(); int q; cin >> q; while (q--) { ll x, d, n; cin >> x >> d >> n; if (x == 0) cout << 0 << endl; else if (d == 0) { cout << modpow(x, n) << endl; } else if (n > mod) cout << 0 << endl; else if (d == 1) { cout << factor(x + n - 1, x - 1) << endl; } else { x *= modpow(d, mod - 2); x %= mod; cout << (factor(x + n - 1, x - 1) * modpow(d, n)) % mod << endl; } } }
replace
88
93
88
92
0
p03027
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pii; typedef pair<double, double> pdd; #define MEM(a, b) memset(a, (b), sizeof(a)) #define SZ(i) ll(i.size()) #define FOR(i, j, k, in) for (ll i = j; i < k; i += in) #define RFOR(i, j, k, in) for (ll i = j; i >= k; i -= in) #define REP(i, j) FOR(i, 0, j, 1) #define REP1(i, j) FOR(i, 1, j + 1, 1) #define RREP(i, j) RFOR(i, j, 0, 1) #define ALL(_a) _a.begin(), _a.end() #define mp make_pair #define pb push_back #define eb emplace_back #define X first #define Y second #ifdef tmd #define debug(...) \ do { \ fprintf(stderr, "%s - %d (%s) = ", __PRETTY_FUNCTION__, __LINE__, \ #__VA_ARGS__); \ _do(__VA_ARGS__); \ } while (0) template <typename T> void _do(T &&_x) { cerr << _x << endl; } template <typename T, typename... S> void _do(T &&_x, S &&..._t) { cerr << _x << " ,"; _do(_t...); } template <typename _a, typename _b> ostream &operator<<(ostream &_s, const pair<_a, _b> &_p) { return _s << "(" << _p.X << "," << _p.Y << ")"; } template <typename It> ostream &_OUTC(ostream &_s, It _ita, It _itb) { _s << "{"; for (It _it = _ita; _it != _itb; _it++) { _s << (_it == _ita ? "" : ",") << *_it; } _s << "}"; return _s; } template <typename _a> ostream &operator<<(ostream &_s, vector<_a> &_c) { return _OUTC(_s, ALL(_c)); } template <typename _a> ostream &operator<<(ostream &_s, set<_a> &_c) { return _OUTC(_s, ALL(_c)); } template <typename _a> ostream &operator<<(ostream &_s, deque<_a> &_c) { return _OUTC(_s, ALL(_c)); } template <typename _a, typename _b> ostream &operator<<(ostream &_s, map<_a, _b> &_c) { return _OUTC(_s, ALL(_c)); } template <typename _t> void pary(_t _a, _t _b) { _OUTC(cerr, _a, _b); cerr << endl; } #define IOS() #else #define debug(...) #define pary(...) #define endl '\n' #define IOS() \ ios_base::sync_with_stdio(0); \ cin.tie(0) #endif const ll MOD = 1000003; const ll INF = 0x3f3f3f3f3f3f3f3f; const ll MAXN = 1000006; ll q, x, d, n; ll mpow(ll base, ll ep) { if (ep == 0) { return 1; } ll hf = mpow(base, ep >> 1); hf = hf * hf % MOD; return ep & 1 ? hf * base % MOD : hf; } ll fc[MAXN], ifc[MAXN]; void build() { fc[0] = ifc[0] = 1; REP1(i, MAXN - 1) { fc[i] = fc[i - 1] * i % MOD; ifc[i] = mpow(fc[i], MOD - 2); } } /********** Good Luck :) **********/ int main() { IOS(); build(); cin >> q; while (q--) { cin >> x >> d >> n; ll f = x * mpow(d, MOD - 2) % MOD; if ((MOD - x) % d == 0 && (MOD - x) / d <= n - 1) { cout << 0 << endl; } else { cout << mpow(d, n) * fc[(f + n - 1) % MOD] % MOD * ifc[(f - 1 + MOD) % MOD] % MOD << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pii; typedef pair<double, double> pdd; #define MEM(a, b) memset(a, (b), sizeof(a)) #define SZ(i) ll(i.size()) #define FOR(i, j, k, in) for (ll i = j; i < k; i += in) #define RFOR(i, j, k, in) for (ll i = j; i >= k; i -= in) #define REP(i, j) FOR(i, 0, j, 1) #define REP1(i, j) FOR(i, 1, j + 1, 1) #define RREP(i, j) RFOR(i, j, 0, 1) #define ALL(_a) _a.begin(), _a.end() #define mp make_pair #define pb push_back #define eb emplace_back #define X first #define Y second #ifdef tmd #define debug(...) \ do { \ fprintf(stderr, "%s - %d (%s) = ", __PRETTY_FUNCTION__, __LINE__, \ #__VA_ARGS__); \ _do(__VA_ARGS__); \ } while (0) template <typename T> void _do(T &&_x) { cerr << _x << endl; } template <typename T, typename... S> void _do(T &&_x, S &&..._t) { cerr << _x << " ,"; _do(_t...); } template <typename _a, typename _b> ostream &operator<<(ostream &_s, const pair<_a, _b> &_p) { return _s << "(" << _p.X << "," << _p.Y << ")"; } template <typename It> ostream &_OUTC(ostream &_s, It _ita, It _itb) { _s << "{"; for (It _it = _ita; _it != _itb; _it++) { _s << (_it == _ita ? "" : ",") << *_it; } _s << "}"; return _s; } template <typename _a> ostream &operator<<(ostream &_s, vector<_a> &_c) { return _OUTC(_s, ALL(_c)); } template <typename _a> ostream &operator<<(ostream &_s, set<_a> &_c) { return _OUTC(_s, ALL(_c)); } template <typename _a> ostream &operator<<(ostream &_s, deque<_a> &_c) { return _OUTC(_s, ALL(_c)); } template <typename _a, typename _b> ostream &operator<<(ostream &_s, map<_a, _b> &_c) { return _OUTC(_s, ALL(_c)); } template <typename _t> void pary(_t _a, _t _b) { _OUTC(cerr, _a, _b); cerr << endl; } #define IOS() #else #define debug(...) #define pary(...) #define endl '\n' #define IOS() \ ios_base::sync_with_stdio(0); \ cin.tie(0) #endif const ll MOD = 1000003; const ll INF = 0x3f3f3f3f3f3f3f3f; const ll MAXN = 1000006; ll q, x, d, n; ll mpow(ll base, ll ep) { if (ep == 0) { return 1; } ll hf = mpow(base, ep >> 1); hf = hf * hf % MOD; return ep & 1 ? hf * base % MOD : hf; } ll fc[MAXN], ifc[MAXN]; void build() { fc[0] = ifc[0] = 1; REP1(i, MAXN - 1) { fc[i] = fc[i - 1] * i % MOD; ifc[i] = mpow(fc[i], MOD - 2); } } /********** Good Luck :) **********/ int main() { IOS(); build(); cin >> q; while (q--) { cin >> x >> d >> n; ll f = x * mpow(d, MOD - 2) % MOD; ll m = (1 + (MOD - x) * mpow(d, MOD - 2)) % MOD; if (d == 0) { cout << mpow(x, n) << endl; continue; } debug(m); if (n >= m) { cout << 0 << endl; } else { cout << mpow(d, n) * fc[(f + n - 1) % MOD] % MOD * ifc[(f - 1 + MOD) % MOD] % MOD << endl; } } return 0; }
replace
99
100
99
106
0
p03027
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define REP(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORR(i, a, b) for (int i = (b)-1; i >= (a); --i) #define DEBUG(x) cout << #x << ": " << (x) << '\n' #define DEBUG_VEC(v) \ cout << #v << ":"; \ REP(i, v.size()) cout << ' ' << v[i]; \ cout << '\n' #define ALL(a) (a).begin(), (a).end() template <typename T> inline void CHMAX(T &a, const T b) { if (a < b) a = b; } template <typename T> inline void CHMIN(T &a, const T b) { if (a > b) a = b; } constexpr ll MOD = 1000003ll; // constexpr ll MOD=998244353ll; #define FIX(a) ((a) % MOD + MOD) % MOD const double EPS = 1e-11; #define EQ0(x) (abs((x)) < EPS) #define EQ(a, b) (abs((a) - (b)) < EPS) template <typename T> struct Modint { using Type = typename decay<decltype(T::value)>::type; Type val; constexpr Modint() noexcept : val() {} template <typename U> constexpr Modint(const U &x) noexcept { val = normalize(x); } template <typename U> static Type normalize(const U &x) noexcept { Type v; if (-mod() <= x && x < mod()) v = static_cast<Type>(x); else v = static_cast<Type>(x % mod()); if (v < 0) v += mod(); return v; } constexpr Type &value() noexcept { return val; } constexpr const Type &value() const noexcept { return val; } template <typename U> constexpr explicit operator U() const noexcept { return static_cast<U>(val); } constexpr static Type mod() noexcept { return T::value; } constexpr Modint &operator+=(const Modint &rhs) noexcept { if ((val += rhs.val) >= mod()) val -= mod(); return *this; } template <typename U> constexpr Modint &operator+=(const U &rhs) noexcept { return *this += Modint(rhs); } constexpr Modint &operator-=(const Modint &rhs) noexcept { if ((val -= rhs.val) < 0) val += mod(); return *this; } template <typename U> constexpr Modint &operator-=(const U &rhs) noexcept { return *this -= Modint(rhs); } constexpr Modint &operator++() noexcept { return *this += 1; } constexpr Modint &operator--() noexcept { return *this -= 1; } constexpr Modint operator++(int) noexcept { Modint result(*this); *this += 1; return result; } constexpr Modint operator--(int) noexcept { Modint result(*this); *this -= 1; return result; } constexpr Modint operator-() const noexcept { return Modint(-val); } constexpr Modint &operator*=(const Modint rhs) noexcept { val = val * rhs.val % mod(); return *this; } constexpr Modint &operator/=(const Modint &rhs) noexcept { Type x = rhs.val, m = mod(), u = 0, v = 1; while (x != 0) { Type t = m / x; m -= t * x; swap(x, m); u -= t * v; swap(u, v); } assert(m == 1); return *this *= Modint(u); } }; template <typename T> constexpr bool operator==(const Modint<T> &lhs, const Modint<T> &rhs) noexcept { return lhs.val == rhs.val; } template <typename T, typename U> constexpr bool operator==(const Modint<T> &lhs, U rhs) noexcept { return lhs == Modint<T>(rhs); } template <typename T, typename U> constexpr bool operator==(U lhs, const Modint<T> &rhs) noexcept { return Modint<T>(lhs) == rhs; } template <typename T> constexpr bool operator!=(const Modint<T> &lhs, const Modint<T> &rhs) noexcept { return !(lhs == rhs); } template <typename T, typename U> constexpr bool operator!=(const Modint<T> &lhs, U rhs) noexcept { return !(lhs == rhs); } template <typename T, typename U> constexpr bool operator!=(U lhs, const Modint<T> &rhs) noexcept { return !(lhs == rhs); } template <typename T> constexpr bool operator<(const Modint<T> &lhs, const Modint<T> &rhs) noexcept { return lhs.val < rhs.val; } template <typename T, typename U> constexpr bool operator<(const Modint<T> &lhs, U rhs) noexcept { return lhs < Modint<T>(rhs); } template <typename T, typename U> constexpr bool operator<(U lhs, const Modint<T> &rhs) noexcept { return Modint<T>(lhs) < rhs; } template <typename T> constexpr bool operator>(const Modint<T> &lhs, const Modint<T> &rhs) noexcept { return lhs.val > rhs.val; } template <typename T, typename U> constexpr bool operator>(const Modint<T> &lhs, U rhs) noexcept { return lhs > Modint<T>(rhs); } template <typename T, typename U> constexpr bool operator>(U lhs, const Modint<T> &rhs) noexcept { return Modint<T>(lhs) > rhs; } template <typename T> constexpr Modint<T> operator+(const Modint<T> &lhs, const Modint<T> &rhs) noexcept { return Modint<T>(lhs) += rhs; } template <typename T, typename U> constexpr Modint<T> operator+(const Modint<T> &lhs, U rhs) noexcept { return Modint<T>(lhs) += rhs; } template <typename T, typename U> constexpr Modint<T> operator+(U lhs, const Modint<T> &rhs) noexcept { return Modint<T>(lhs) += rhs; } template <typename T> constexpr Modint<T> operator-(const Modint<T> &lhs, const Modint<T> &rhs) noexcept { return Modint<T>(lhs) -= rhs; } template <typename T, typename U> constexpr Modint<T> operator-(const Modint<T> &lhs, U rhs) noexcept { return Modint<T>(lhs) -= rhs; } template <typename T, typename U> constexpr Modint<T> operator-(U lhs, const Modint<T> &rhs) noexcept { return Modint<T>(lhs) -= rhs; } template <typename T> constexpr Modint<T> operator*(const Modint<T> &lhs, const Modint<T> &rhs) noexcept { return Modint<T>(lhs) *= rhs; } template <typename T, typename U> constexpr Modint<T> operator*(const Modint<T> &lhs, U rhs) noexcept { return Modint<T>(lhs) *= rhs; } template <typename T, typename U> constexpr Modint<T> operator*(U lhs, const Modint<T> &rhs) noexcept { return Modint<T>(lhs) *= rhs; } template <typename T> constexpr Modint<T> operator/(const Modint<T> &lhs, const Modint<T> &rhs) noexcept { return Modint<T>(lhs) /= rhs; } template <typename T, typename U> constexpr Modint<T> operator/(const Modint<T> &lhs, U rhs) noexcept { return Modint<T>(lhs) /= rhs; } template <typename T, typename U> constexpr Modint<T> operator/(U lhs, const Modint<T> &rhs) noexcept { return Modint<T>(lhs) /= rhs; } template <typename T, typename U> Modint<T> constexpr power(const Modint<T> &a, const U &b) noexcept { Modint<T> x = a, res = 1; U p = b; while (p > 0) { if (p & 1) res *= x; x *= x; p >>= 1; } return res; } template <class T> struct Combination { using Type = typename decay<decltype(T::value)>::type; // vector<Modint<T>> fact_, finv_; // constexpr Combination(int n) noexcept : fact_(n+1, 1), finv_(n+1, 1) { // Type MOD=fact_[0].mod(); // FOR(i, 2, n+1){ // fact_[i]=fact_[i-1]*i; // } // finv_[n]=power(fact_[n], MOD-2); // FORR(i, 3, n+1){ // finv_[i-1]=finv_[i]*i; // } // } // iの逆元も求める場合 vector<Modint<T>> fact_, inv_, finv_; constexpr Combination(int n) noexcept : fact_(n + 1, 1), inv_(n + 1, 1), finv_(n + 1, 1) { Type MOD = fact_[0].mod(); FOR(i, 2, n + 1) { fact_[i] = fact_[i - 1] * i; inv_[i] = -inv_[MOD % i] * (MOD / i); finv_[i] = finv_[i - 1] * inv_[i]; } } constexpr Modint<T> inv(int n) const noexcept { if (n < 0) return 0; return inv_[n]; } constexpr Modint<T> com(int n, int k) const noexcept { if (n < k || n < 0 || k < 0) return Modint<T>(0); return fact_[n] * finv_[k] * finv_[n - k]; } constexpr Modint<T> fact(int n) const noexcept { if (n < 0) return Modint<T>(0); return fact_[n]; } constexpr Modint<T> finv(int n) const noexcept { if (n < 0) return Modint<T>(0); return finv_[n]; } }; template <typename T> constexpr ostream &operator<<(ostream &stream, const Modint<T> &number) noexcept { return stream << number.val; } template <typename T> constexpr istream &operator>>(istream &stream, Modint<T> &number) noexcept { return stream >> number.val; } using Mint = Modint<integral_constant<decay<decltype(MOD)>::type, MOD>>; using Comb = Combination<integral_constant<decay<decltype(MOD)>::type, MOD>>; int main() { ios::sync_with_stdio(false); cin.tie(0); // cout<<setprecision(10)<<fixed; int Q, d, n; Mint x; Comb comb(MOD - 1); cin >> Q; REP(i, Q) { cin >> x; cin >> d >> n; if (x == 0) { cout << 0 << '\n'; continue; } if (d == 0) { cout << power(x, n) << '\n'; continue; } Mint tmp = x * comb.inv(d); if (tmp + n > MOD - 1) { cout << 0 << '\n'; continue; } if (tmp > 1) { cout << comb.fact(tmp.val + n - 1) * comb.finv(tmp.val - 1) * power(Mint(d), n) << '\n'; } else { cout << comb.fact(tmp.val + n - 1) * power(Mint(d), n) << '\n'; } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define REP(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORR(i, a, b) for (int i = (b)-1; i >= (a); --i) #define DEBUG(x) cout << #x << ": " << (x) << '\n' #define DEBUG_VEC(v) \ cout << #v << ":"; \ REP(i, v.size()) cout << ' ' << v[i]; \ cout << '\n' #define ALL(a) (a).begin(), (a).end() template <typename T> inline void CHMAX(T &a, const T b) { if (a < b) a = b; } template <typename T> inline void CHMIN(T &a, const T b) { if (a > b) a = b; } constexpr ll MOD = 1000003ll; // constexpr ll MOD=998244353ll; #define FIX(a) ((a) % MOD + MOD) % MOD const double EPS = 1e-11; #define EQ0(x) (abs((x)) < EPS) #define EQ(a, b) (abs((a) - (b)) < EPS) template <typename T> struct Modint { using Type = typename decay<decltype(T::value)>::type; Type val; constexpr Modint() noexcept : val() {} template <typename U> constexpr Modint(const U &x) noexcept { val = normalize(x); } template <typename U> static Type normalize(const U &x) noexcept { Type v; if (-mod() <= x && x < mod()) v = static_cast<Type>(x); else v = static_cast<Type>(x % mod()); if (v < 0) v += mod(); return v; } constexpr Type &value() noexcept { return val; } constexpr const Type &value() const noexcept { return val; } template <typename U> constexpr explicit operator U() const noexcept { return static_cast<U>(val); } constexpr static Type mod() noexcept { return T::value; } constexpr Modint &operator+=(const Modint &rhs) noexcept { if ((val += rhs.val) >= mod()) val -= mod(); return *this; } template <typename U> constexpr Modint &operator+=(const U &rhs) noexcept { return *this += Modint(rhs); } constexpr Modint &operator-=(const Modint &rhs) noexcept { if ((val -= rhs.val) < 0) val += mod(); return *this; } template <typename U> constexpr Modint &operator-=(const U &rhs) noexcept { return *this -= Modint(rhs); } constexpr Modint &operator++() noexcept { return *this += 1; } constexpr Modint &operator--() noexcept { return *this -= 1; } constexpr Modint operator++(int) noexcept { Modint result(*this); *this += 1; return result; } constexpr Modint operator--(int) noexcept { Modint result(*this); *this -= 1; return result; } constexpr Modint operator-() const noexcept { return Modint(-val); } constexpr Modint &operator*=(const Modint rhs) noexcept { val = val * rhs.val % mod(); return *this; } constexpr Modint &operator/=(const Modint &rhs) noexcept { Type x = rhs.val, m = mod(), u = 0, v = 1; while (x != 0) { Type t = m / x; m -= t * x; swap(x, m); u -= t * v; swap(u, v); } assert(m == 1); return *this *= Modint(u); } }; template <typename T> constexpr bool operator==(const Modint<T> &lhs, const Modint<T> &rhs) noexcept { return lhs.val == rhs.val; } template <typename T, typename U> constexpr bool operator==(const Modint<T> &lhs, U rhs) noexcept { return lhs == Modint<T>(rhs); } template <typename T, typename U> constexpr bool operator==(U lhs, const Modint<T> &rhs) noexcept { return Modint<T>(lhs) == rhs; } template <typename T> constexpr bool operator!=(const Modint<T> &lhs, const Modint<T> &rhs) noexcept { return !(lhs == rhs); } template <typename T, typename U> constexpr bool operator!=(const Modint<T> &lhs, U rhs) noexcept { return !(lhs == rhs); } template <typename T, typename U> constexpr bool operator!=(U lhs, const Modint<T> &rhs) noexcept { return !(lhs == rhs); } template <typename T> constexpr bool operator<(const Modint<T> &lhs, const Modint<T> &rhs) noexcept { return lhs.val < rhs.val; } template <typename T, typename U> constexpr bool operator<(const Modint<T> &lhs, U rhs) noexcept { return lhs < Modint<T>(rhs); } template <typename T, typename U> constexpr bool operator<(U lhs, const Modint<T> &rhs) noexcept { return Modint<T>(lhs) < rhs; } template <typename T> constexpr bool operator>(const Modint<T> &lhs, const Modint<T> &rhs) noexcept { return lhs.val > rhs.val; } template <typename T, typename U> constexpr bool operator>(const Modint<T> &lhs, U rhs) noexcept { return lhs > Modint<T>(rhs); } template <typename T, typename U> constexpr bool operator>(U lhs, const Modint<T> &rhs) noexcept { return Modint<T>(lhs) > rhs; } template <typename T> constexpr Modint<T> operator+(const Modint<T> &lhs, const Modint<T> &rhs) noexcept { return Modint<T>(lhs) += rhs; } template <typename T, typename U> constexpr Modint<T> operator+(const Modint<T> &lhs, U rhs) noexcept { return Modint<T>(lhs) += rhs; } template <typename T, typename U> constexpr Modint<T> operator+(U lhs, const Modint<T> &rhs) noexcept { return Modint<T>(lhs) += rhs; } template <typename T> constexpr Modint<T> operator-(const Modint<T> &lhs, const Modint<T> &rhs) noexcept { return Modint<T>(lhs) -= rhs; } template <typename T, typename U> constexpr Modint<T> operator-(const Modint<T> &lhs, U rhs) noexcept { return Modint<T>(lhs) -= rhs; } template <typename T, typename U> constexpr Modint<T> operator-(U lhs, const Modint<T> &rhs) noexcept { return Modint<T>(lhs) -= rhs; } template <typename T> constexpr Modint<T> operator*(const Modint<T> &lhs, const Modint<T> &rhs) noexcept { return Modint<T>(lhs) *= rhs; } template <typename T, typename U> constexpr Modint<T> operator*(const Modint<T> &lhs, U rhs) noexcept { return Modint<T>(lhs) *= rhs; } template <typename T, typename U> constexpr Modint<T> operator*(U lhs, const Modint<T> &rhs) noexcept { return Modint<T>(lhs) *= rhs; } template <typename T> constexpr Modint<T> operator/(const Modint<T> &lhs, const Modint<T> &rhs) noexcept { return Modint<T>(lhs) /= rhs; } template <typename T, typename U> constexpr Modint<T> operator/(const Modint<T> &lhs, U rhs) noexcept { return Modint<T>(lhs) /= rhs; } template <typename T, typename U> constexpr Modint<T> operator/(U lhs, const Modint<T> &rhs) noexcept { return Modint<T>(lhs) /= rhs; } template <typename T, typename U> Modint<T> constexpr power(const Modint<T> &a, const U &b) noexcept { Modint<T> x = a, res = 1; U p = b; while (p > 0) { if (p & 1) res *= x; x *= x; p >>= 1; } return res; } template <class T> struct Combination { using Type = typename decay<decltype(T::value)>::type; // vector<Modint<T>> fact_, finv_; // constexpr Combination(int n) noexcept : fact_(n+1, 1), finv_(n+1, 1) { // Type MOD=fact_[0].mod(); // FOR(i, 2, n+1){ // fact_[i]=fact_[i-1]*i; // } // finv_[n]=power(fact_[n], MOD-2); // FORR(i, 3, n+1){ // finv_[i-1]=finv_[i]*i; // } // } // iの逆元も求める場合 vector<Modint<T>> fact_, inv_, finv_; constexpr Combination(int n) noexcept : fact_(n + 1, 1), inv_(n + 1, 1), finv_(n + 1, 1) { Type MOD = fact_[0].mod(); FOR(i, 2, n + 1) { fact_[i] = fact_[i - 1] * i; inv_[i] = -inv_[MOD % i] * (MOD / i); finv_[i] = finv_[i - 1] * inv_[i]; } } constexpr Modint<T> inv(int n) const noexcept { if (n < 0) return 0; return inv_[n]; } constexpr Modint<T> com(int n, int k) const noexcept { if (n < k || n < 0 || k < 0) return Modint<T>(0); return fact_[n] * finv_[k] * finv_[n - k]; } constexpr Modint<T> fact(int n) const noexcept { if (n < 0) return Modint<T>(0); return fact_[n]; } constexpr Modint<T> finv(int n) const noexcept { if (n < 0) return Modint<T>(0); return finv_[n]; } }; template <typename T> constexpr ostream &operator<<(ostream &stream, const Modint<T> &number) noexcept { return stream << number.val; } template <typename T> constexpr istream &operator>>(istream &stream, Modint<T> &number) noexcept { return stream >> number.val; } using Mint = Modint<integral_constant<decay<decltype(MOD)>::type, MOD>>; using Comb = Combination<integral_constant<decay<decltype(MOD)>::type, MOD>>; int main() { ios::sync_with_stdio(false); cin.tie(0); // cout<<setprecision(10)<<fixed; int Q, d, n; Mint x; Comb comb(MOD - 1); cin >> Q; REP(i, Q) { cin >> x; cin >> d >> n; if (x == 0) { cout << 0 << '\n'; continue; } if (d == 0) { cout << power(x, n) << '\n'; continue; } Mint tmp = x * comb.inv(d); if (tmp.val + n > MOD) { cout << 0 << '\n'; continue; } if (tmp > 1) { cout << comb.fact(tmp.val + n - 1) * comb.finv(tmp.val - 1) * power(Mint(d), n) << '\n'; } else { cout << comb.fact(tmp.val + n - 1) * power(Mint(d), n) << '\n'; } } return 0; }
replace
316
317
316
317
0
p03027
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define REP(i, n) for (int i = 0; i < n; i++) #define all(x) (x).begin(), (x).end() #define mp make_pair #define pb push_back #define eb emplace_back typedef long long ll; using namespace std; const int mod = 1000003; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; int main(void) { cin.tie(0); ios::sync_with_stdio(false); // cout << fixed << setprecision(20); // 前計算をする // 1,000,003まで階乗modを前計算する vector<mint> facl(3 * mod); for (ll i = 0; i < 3 * mod; i++) { if (i == 0) facl[i] = (mint)1; else facl[i] = facl[i - 1] * (mint)i; } // 計算する int t; cin >> t; REP(_, t) { // 入力を受け取る ll x, d, n; cin >> x >> d >> n; if (x == 0) { cout << 0 << '\n'; continue; } if (d == 0) { mint X = (mint)x; X = X.pow(n); cout << X.x << '\n'; continue; } else { mint q = (mint)x / (mint)d; //[q,q+(n-1)]に1'000'003の倍数があるか? if ((n - 1) != (q.x + n - 1 % mod) - (q.x % mod)) { cout << 0 << '\n'; } else { mint D = d; D = D.pow(n); if (q.x == 0) { cout << 0 << '\n'; continue; } D *= facl[q.x + (n - 1)] * facl[q.x - 1].inv(); cout << D.x << '\n'; } } } return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define REP(i, n) for (int i = 0; i < n; i++) #define all(x) (x).begin(), (x).end() #define mp make_pair #define pb push_back #define eb emplace_back typedef long long ll; using namespace std; const int mod = 1000003; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; int main(void) { cin.tie(0); ios::sync_with_stdio(false); // cout << fixed << setprecision(20); // 前計算をする // 1,000,003まで階乗modを前計算する vector<mint> facl(3 * mod); for (ll i = 0; i < 3 * mod; i++) { if (i == 0) facl[i] = (mint)1; else facl[i] = facl[i - 1] * (mint)i; } // 計算する int t; cin >> t; REP(_, t) { // 入力を受け取る ll x, d, n; cin >> x >> d >> n; if (x == 0) { cout << 0 << '\n'; continue; } if (d == 0) { mint X = (mint)x; X = X.pow(n); cout << X.x << '\n'; continue; } else { mint q = (mint)x / (mint)d; //[q,q+(n-1)]に1'000'003の倍数があるか? if ((n - 1) != (q.x + n - 1 % mod) - (q.x % mod)) { cout << 0 << '\n'; } else { mint D = d; D = D.pow(n); if (q.x == 0 or q.x + (n - 1) >= 3 * mod) { cout << 0 << '\n'; continue; } D *= facl[q.x + (n - 1)] * facl[q.x - 1].inv(); cout << D.x << '\n'; } } } return 0; }
replace
121
122
121
122
0
p03028
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define N 5 int n, ans; bitset<N> a[N], f[N], g[N]; char s[N][N]; int main() { scanf("%d", &n); for (int i = 2; i <= n; ++i) { scanf("%s", s[i] + 1); for (int j = 1; j < i; ++j) { a[i][j] = s[i][j] - '0'; a[j][i] = a[i][j] ^ 1; } } for (int i = 1; i <= n; ++i) { f[i][i] = g[i][i] = 1; for (int j = 1; j < i; ++j) if (g[i - 1][j] && a[i][j]) f[i] |= f[j]; for (int j = 1; j < i; ++j) if (f[i][j + 1] && a[j][i]) g[i] |= g[j]; } for (int i = 1; i <= n; ++i) ans += f[i][1] && g[n][i]; printf("%d\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define N 2005 int n, ans; bitset<N> a[N], f[N], g[N]; char s[N][N]; int main() { scanf("%d", &n); for (int i = 2; i <= n; ++i) { scanf("%s", s[i] + 1); for (int j = 1; j < i; ++j) { a[i][j] = s[i][j] - '0'; a[j][i] = a[i][j] ^ 1; } } for (int i = 1; i <= n; ++i) { f[i][i] = g[i][i] = 1; for (int j = 1; j < i; ++j) if (g[i - 1][j] && a[i][j]) f[i] |= f[j]; for (int j = 1; j < i; ++j) if (f[i][j + 1] && a[j][i]) g[i] |= g[j]; } for (int i = 1; i <= n; ++i) ans += f[i][1] && g[n][i]; printf("%d\n", ans); return 0; }
replace
4
5
4
5
0
p03028
C++
Runtime Error
#pragma GCC optimize(3) #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/priority_queue.hpp> #include <ext/pb_ds/tree_policy.hpp> #define MAXN 2005 #define INF 1000000000 #define MOD 1000000007 #define F first #define S second using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef pair<int, int> P; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef __gnu_pbds::priority_queue<int, greater<int>, pairing_heap_tag> pq; typedef bitset<2000> bs; int n; bs win[MAXN], twin[MAXN]; int a[MAXN][MAXN]; bs dpl[MAXN], dpr[MAXN], tdpl[MAXN], tdpr[MAXN]; string str; int main() { scanf("%d", &n); for (int i = 1; i < n; i++) { cin >> str; for (int j = 0; j < i; j++) { int x = str[j] - '0'; if (x) { win[i].set(j); twin[j].set(i); } else { win[j].set(i); twin[i].set(j); } } } for (int i = 0; i < n; i++) { dpl[i].set(i); dpr[i].set(i); tdpl[i].set(i); tdpr[i].set(i); } for (int len = 2; len <= n; len++) { for (int i = 0; i < n; i++) { int j = i + len - 1; if ((dpr[i + 1] & tdpl[j] & win[i]).count()) { dpl[i].set(j); tdpl[j].set(i); } if ((dpr[i] & tdpl[j - 1] & win[j]).count()) { dpr[i].set(j); tdpr[j].set(i); } } } int ans = 0; for (int i = 0; i < n; i++) if (dpl[i].test(n - 1) && dpr[0].test(i)) ans++; printf("%d\n", ans); return 0; }
#pragma GCC optimize(3) #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/priority_queue.hpp> #include <ext/pb_ds/tree_policy.hpp> #define MAXN 2005 #define INF 1000000000 #define MOD 1000000007 #define F first #define S second using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef pair<int, int> P; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; typedef __gnu_pbds::priority_queue<int, greater<int>, pairing_heap_tag> pq; typedef bitset<2000> bs; int n; bs win[MAXN], twin[MAXN]; int a[MAXN][MAXN]; bs dpl[MAXN], dpr[MAXN], tdpl[MAXN], tdpr[MAXN]; string str; int main() { scanf("%d", &n); for (int i = 1; i < n; i++) { cin >> str; for (int j = 0; j < i; j++) { int x = str[j] - '0'; if (x) { win[i].set(j); twin[j].set(i); } else { win[j].set(i); twin[i].set(j); } } } for (int i = 0; i < n; i++) { dpl[i].set(i); dpr[i].set(i); tdpl[i].set(i); tdpr[i].set(i); } for (int len = 2; len <= n; len++) { for (int i = 0; i + len - 1 < n; i++) { int j = i + len - 1; if ((dpr[i + 1] & tdpl[j] & win[i]).count()) { dpl[i].set(j); tdpl[j].set(i); } if ((dpr[i] & tdpl[j - 1] & win[j]).count()) { dpr[i].set(j); tdpr[j].set(i); } } } int ans = 0; for (int i = 0; i < n; i++) if (dpl[i].test(n - 1) && dpr[0].test(i)) ans++; printf("%d\n", ans); return 0; }
replace
46
47
46
47
0
p03028
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cassert> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; const ll mod = 1000003; typedef double ld; typedef complex<ld> Point; const ll INF = mod * mod; typedef pair<int, int> P; #define stop \ char nyaa; \ cin >> nyaa; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; typedef vector<int> vec; bool b[2000][2000]; bool le[2000][2000], ri[2000][2000]; void solve() { int n; cin >> n; rep1(i, n - 1) { rep(j, i) { char t; cin >> t; if (t == '1') { b[i][j] = true; } else { b[j][i] = true; } } } rep(i, n) le[i][i] = ri[i][i] = true; int ans = 0; Rep1(i, 2, n) { rep(j, n - i + 1) { int l = j; int r = j + i - 1; Rep1(k, l + 1, r) { if (b[l][k] && ri[l + 1][k] && le[r][k]) { le[r][l] = true; break; } } Rep(k, l, r) { if (b[r][k] && ri[l][k] && le[r - 1][k]) { ri[l][r] = true; break; } } } } rep(i, n) { if (ri[0][i] && le[n - 1][i]) ans++; } cout << ans << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); // cout << fixed << setprecision(5); // while (cin >> n)solve(); solve(); // stop return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; const ll mod = 1000003; typedef double ld; typedef complex<ld> Point; const ll INF = mod * mod; typedef pair<int, int> P; #define stop \ char nyaa; \ cin >> nyaa; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; typedef vector<int> vec; bool b[2000][2000]; bool le[2000][2000], ri[2000][2000]; void solve() { int n; cin >> n; rep1(i, n - 1) { rep(j, i) { char t; cin >> t; if (t == '1') { b[i][j] = true; } else { b[j][i] = true; } } } rep(i, n) le[i][i] = ri[i][i] = true; int ans = 0; Rep1(i, 2, n) { rep(j, n - i + 1) { int l = j; int r = j + i - 1; bool fl = false, fr = false; Rep1(k, l + 1, r) { fl |= b[l][k] & ri[l + 1][k] & le[r][k]; } Rep(k, l, r) { fr |= b[r][k] & ri[l][k] & le[r - 1][k]; } le[r][l] = fl, ri[l][r] = fr; } } rep(i, n) { if (ri[0][i] && le[n - 1][i]) ans++; } cout << ans << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); // cout << fixed << setprecision(5); // while (cin >> n)solve(); solve(); // stop return 0; }
replace
69
81
69
73
TLE
p03028
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define all(c) c.begin(), c.end() #define pb push_back #define fs first #define sc second #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) using namespace std; template <class S, class T> ostream &operator<<(ostream &o, const pair<S, T> &p) { return o << "(" << p.fs << "," << p.sc << ")"; } template <class T> ostream &operator<<(ostream &o, const vector<T> &vc) { o << "{"; for (const T &v : vc) o << v << ","; o << "}"; return o; } using ll = long long; template <class T> using V = vector<T>; template <class T> using VV = vector<vector<T>>; constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } #ifdef LOCAL #define show(x) \ cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl #else #define show(x) true #endif int N; bool A[2010][2010]; bool L[2010][2010]; bool R[2010][2010]; using BS = bitset<2010>; V<BS> Rix(2010); V<BS> Lxi(2010); V<BS> Aix(2010); int main() { cin.tie(0); ios::sync_with_stdio(false); // DON'T USE scanf/printf/puts !! cout << fixed << setprecision(20); cin >> N; { V<string> s(N); rep1(i, N - 1) cin >> s[i]; rep(i, N) rep(j, N) { if (i > j) A[i][j] = s[i][j] == '1'; if (j > i) A[i][j] = s[j][i] == '0'; } } if (false) { rep(i, N) { rep(j, N) cout << A[i][j] << " "; cout << endl; } } rep(i, N) { rep(j, N) if (A[i][j]) Aix[i].set(j); } for (int d = 1; d <= N; d++) { for (int l = 0; l + d - 1 < N; l++) { int r = l + d - 1; if (d == 1) { Lxi[r].set(l); Rix[l].set(r); L[l][r] = true; R[l][r] = true; } else { { // L // for(int x=l+1;x<=r;x++){ // if(A[l][x] && R[l+1][x] && L[x][r]){ // L[l][r] = true; // break; // } // } auto tmp = Aix[l] & Rix[l + 1] & Lxi[r]; if (tmp.any()) Lxi[r].set(l); } { // R for (int x = l; x < r; x++) { if (A[r][x] && L[x][r - 1] && R[l][x]) { R[l][r] = true; break; } } auto tmp = Aix[r] & Rix[l] & Lxi[r - 1]; if (tmp.any()) Rix[l].set(r); } } } } int ans = 0; rep(i, N) if (Rix[0][i] && Lxi[N - 1][i]) { ans++; show(i); } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i <= (int)(n); i++) #define all(c) c.begin(), c.end() #define pb push_back #define fs first #define sc second #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) using namespace std; template <class S, class T> ostream &operator<<(ostream &o, const pair<S, T> &p) { return o << "(" << p.fs << "," << p.sc << ")"; } template <class T> ostream &operator<<(ostream &o, const vector<T> &vc) { o << "{"; for (const T &v : vc) o << v << ","; o << "}"; return o; } using ll = long long; template <class T> using V = vector<T>; template <class T> using VV = vector<vector<T>>; constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); } #ifdef LOCAL #define show(x) \ cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl #else #define show(x) true #endif int N; bool A[2010][2010]; bool L[2010][2010]; bool R[2010][2010]; using BS = bitset<2010>; V<BS> Rix(2010); V<BS> Lxi(2010); V<BS> Aix(2010); int main() { cin.tie(0); ios::sync_with_stdio(false); // DON'T USE scanf/printf/puts !! cout << fixed << setprecision(20); cin >> N; { V<string> s(N); rep1(i, N - 1) cin >> s[i]; rep(i, N) rep(j, N) { if (i > j) A[i][j] = s[i][j] == '1'; if (j > i) A[i][j] = s[j][i] == '0'; } } if (false) { rep(i, N) { rep(j, N) cout << A[i][j] << " "; cout << endl; } } rep(i, N) { rep(j, N) if (A[i][j]) Aix[i].set(j); } for (int d = 1; d <= N; d++) { for (int l = 0; l + d - 1 < N; l++) { int r = l + d - 1; if (d == 1) { Lxi[r].set(l); Rix[l].set(r); L[l][r] = true; R[l][r] = true; } else { { // L // for(int x=l+1;x<=r;x++){ // if(A[l][x] && R[l+1][x] && L[x][r]){ // L[l][r] = true; // break; // } // } auto tmp = Aix[l] & Rix[l + 1] & Lxi[r]; if (tmp.any()) Lxi[r].set(l); } { // R // for(int x=l;x<r;x++){ // if(A[r][x] && L[x][r-1] && R[l][x]){ // R[l][r] = true; // break; // } // } auto tmp = Aix[r] & Rix[l] & Lxi[r - 1]; if (tmp.any()) Rix[l].set(r); } } } } int ans = 0; rep(i, N) if (Rix[0][i] && Lxi[N - 1][i]) { ans++; show(i); } cout << ans << endl; }
replace
88
94
88
94
TLE
p03028
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x, to) for (x = 0; x < (to); x++) #define FORR(x, arr) for (auto &x : arr) #define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++) #define ALL(a) (a.begin()), (a.end()) #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, 0xff, sizeof(a)) //------------------------------------------------------- int N; bitset<2020> A[2020]; bitset<2020> winL[2020], winR[2020], winRL[2020], winRR[2020]; bitset<2020> dp[2020]; void solve() { int i, j, k, l, r, x, y; string s; cin >> N; for (j = 1; j < N; j++) { cin >> s; FOR(i, j) { A[j][i] = s[i] == '1'; A[i][j] = s[i] == '0'; } } FOR(x, N) winL[x][x] = winR[x][x] = winRL[x][x] = winRR[x][x] = 1; for (l = 2; l <= N; l++) { for (x = 0; x + l <= N; x++) { y = x + l - 1; for (i = x; i < y && dp[x][y] == 0; i++) if (winL[x][i] & winR[y][i + 1]) dp[x][y] = 1; dp[y][x] = dp[x][y]; auto bs = A[x] & dp[x] & winRL[y]; if (bs.count()) winL[x][y] = winRL[y][x] = 1; bs = A[y] & dp[y] & winRR[x]; if (bs.count()) winR[y][x] = winRR[x][y] = 1; } } int ret = 0; FOR(i, N) ret += winR[i][0] & winL[i][N - 1]; cout << ret << endl; } int main(int argc, char **argv) { string s; int i; if (argc == 1) ios::sync_with_stdio(false), cin.tie(0); FOR(i, argc - 1) s += argv[i + 1], s += '\n'; FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin); cout.tie(0); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x, to) for (x = 0; x < (to); x++) #define FORR(x, arr) for (auto &x : arr) #define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++) #define ALL(a) (a.begin()), (a.end()) #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, 0xff, sizeof(a)) //------------------------------------------------------- int N; bitset<2020> A[2020]; bitset<2020> winL[2020], winR[2020], winRL[2020], winRR[2020]; bitset<2020> dp[2020]; void solve() { int i, j, k, l, r, x, y; string s; cin >> N; for (j = 1; j < N; j++) { cin >> s; FOR(i, j) { A[j][i] = s[i] == '1'; A[i][j] = s[i] == '0'; } } FOR(x, N) winL[x][x] = winR[x][x] = winRL[x][x] = winRR[x][x] = 1; for (l = 2; l <= N; l++) { for (x = 0; x + l <= N; x++) { y = x + l - 1; auto bs = winL[x] & (winR[y] >> 1); if (bs.count()) dp[x][y] = dp[y][x] = 1; bs = A[x] & dp[x] & winRL[y]; if (bs.count()) winL[x][y] = winRL[y][x] = 1; bs = A[y] & dp[y] & winRR[x]; if (bs.count()) winR[y][x] = winRR[x][y] = 1; } } int ret = 0; FOR(i, N) ret += winR[i][0] & winL[i][N - 1]; cout << ret << endl; } int main(int argc, char **argv) { string s; int i; if (argc == 1) ios::sync_with_stdio(false), cin.tie(0); FOR(i, argc - 1) s += argv[i + 1], s += '\n'; FOR(i, s.size()) ungetc(s[s.size() - 1 - i], stdin); cout.tie(0); solve(); return 0; }
replace
36
41
36
40
TLE
p03028
C++
Time Limit Exceeded
#include <bits/stdc++.h> int main() { std::cin.tie(0); std::cin.sync_with_stdio(false); size_t n; std::cin >> n; constexpr size_t max = 2002; auto a = std::vector<std::bitset<max>>(n + 2); auto insert = [&](size_t i, size_t j, bool k) { a[i][j] = k; a[j][i] = !k; }; for (size_t i = 1; i <= n; i++) { insert(i, 0, true); insert(i, n + 1, true); } for (size_t i = 2; i <= n; i++) { for (size_t j = 1; j < i; j++) { char x; std::cin >> x; insert(i, j, x == '1'); } } auto dp = std::vector<std::bitset<max>>(n + 2); for (size_t i = 0; i <= n; i++) dp[i][i + 1] = dp[i + 1][i] = true; for (size_t d = 2; d <= n + 1; d++) { for (size_t i = 0, j = d; j <= n + 1; i++, j++) { bool tmp = false; for (size_t k = i + 1; k < j; k++) { tmp |= dp[i][k] & dp[j][k] & (a[i][k] | a[j][k]); } dp[j][i] = dp[i][j] = tmp; } } int ret = 0; for (size_t i = 1; i <= n; i++) { if (dp[0][i] & dp[i][n + 1]) ret++; } std::cout << ret << std::endl; return 0; }
#include <bits/stdc++.h> int main() { std::cin.tie(0); std::cin.sync_with_stdio(false); size_t n; std::cin >> n; constexpr size_t max = 2002; auto a = std::vector<std::bitset<max>>(n + 2); auto insert = [&](size_t i, size_t j, bool k) { a[i][j] = k; a[j][i] = !k; }; for (size_t i = 1; i <= n; i++) { insert(i, 0, true); insert(i, n + 1, true); } for (size_t i = 2; i <= n; i++) { for (size_t j = 1; j < i; j++) { char x; std::cin >> x; insert(i, j, x == '1'); } } auto dp = std::vector<std::bitset<max>>(n + 2); for (size_t i = 0; i <= n; i++) dp[i][i + 1] = dp[i + 1][i] = true; for (size_t d = 2; d <= n + 1; d++) { for (size_t i = 0, j = d; j <= n + 1; i++, j++) { dp[j][i] = dp[i][j] = (dp[i] & dp[j] & (a[i] | a[j])).any(); } } int ret = 0; for (size_t i = 1; i <= n; i++) { if (dp[0][i] & dp[i][n + 1]) ret++; } std::cout << ret << std::endl; return 0; }
replace
28
33
28
29
TLE
p03029
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define mod 1000000007 #define pll pair<long long, long long> #define pdd pair<long double, long double> #define mp make_pair #define pb push_back #define pf push_front priority_queue<pll, vector<pll>, greater<pll>> pq; priority_queue<ll, vector<ll>, greater<ll>> p; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll a, p; cin >> a >> p; a *= 3; a += p; cout << a / p; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define mod 1000000007 #define pll pair<long long, long long> #define pdd pair<long double, long double> #define mp make_pair #define pb push_back #define pf push_front priority_queue<pll, vector<pll>, greater<pll>> pq; priority_queue<ll, vector<ll>, greater<ll>> p; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll a, p; cin >> a >> p; a *= 3; a += p; cout << a / 2; return 0; }
replace
21
22
21
22
0
p03029
C++
Runtime Error
#include <iostream> int main(void) { int A, P; std::cin >> A >> P; P += 3 * A; return P / 2; }
#include <iostream> int main(void) { int A, P; std::cin >> A >> P; P += 3 * A; std::cout << P / 2; return 0; }
replace
6
7
6
8
3
p03029
C++
Runtime Error
#include <iostream> using namespace std; int main(void) { int apple = 0; int apple_block = 0; int apple_pie = 0; cin >> apple; cin >> apple_block; apple_pie = ((3 * apple) + apple_block) / 2; cout << apple_pie << endl; return apple_pie; }
#include <iostream> using namespace std; int main(void) { int apple = 0; int apple_block = 0; int apple_pie = 0; cin >> apple; cin >> apple_block; apple_pie = ((3 * apple) + apple_block) / 2; cout << apple_pie << endl; return 0; }
replace
16
17
16
17
3
p03029
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/numeric> #define __ \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define pi acos(-1) #define ll long long int #define mem(a) memset(a, 0, sizeof(a)) #define mems(a) memset(a, -1, sizeof(a)) #define pii pair<int, int> #define N 100005 using namespace std; int main() { __; #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int a, p; cin >> a >> p; cout << ((3 * a) + p) / 2; return 0; }
#include <bits/stdc++.h> #include <ext/numeric> #define __ \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define pi acos(-1) #define ll long long int #define mem(a) memset(a, 0, sizeof(a)) #define mems(a) memset(a, -1, sizeof(a)) #define pii pair<int, int> #define N 100005 using namespace std; int main() { __; #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); #endif int a, p; cin >> a >> p; cout << ((3 * a) + p) / 2; return 0; }
replace
18
20
18
20
0
p03029
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // typedefs typedef long long LL; typedef vector<int> VI; typedef vector<LL> VL; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef pair<int, int> PII; typedef pair<double, double> PDD; typedef pair<LL, LL> PLL; typedef vector<PII> VII; typedef vector<PLL> VLL; // #Defines #define rep(i, a, b) for (i = a; i <= b; i++) #define repR(i, a, b) for (i = a; i >= b; i--) #define pb push_back // #define pb emplace_back #define F first #define S second #define mp make_pair #define all(c) c.begin(), c.end() #define endl '\n' #define pf printf #define sf scanf #define MOD 1000000007 // #define harmonic(n) 0.57721566490153286l+log(n) // if harmonic numbers need to be calculated, precalculate upto 1e6, then for // any x > 1e6 call harmonic(x + 0.5) #define RESET(a, b) memset(a, b, sizeof(a)) #define sqr(a) ((a) * (a)) #define optimize() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); const double PI = acos(-1); const double eps = 1e-9; const int inf = 2000000000; const LL infLL = 9000000000000000000; // Bit Operations inline bool checkBit(LL n, int i) { return n & (1LL << i); } inline LL setBit(LL n, int i) { return n | (1LL << i); ; } inline LL resetBit(LL n, int i) { return n & (~(1LL << i)); } // Rotation: S -> E -> N -> W int fx[] = {0, +1, 0, -1}; int fy[] = {-1, 0, +1, 0}; // int dx[] = {0, +1, +1, +1, 0, -1, -1, -1}; // int dy[] = {-1, -1, 0, +1, +1, +1, 0, -1}; // Inline functions inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } inline bool isLeapYear(LL year) { return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0); } inline void normal(LL &a) { a %= MOD; (a < 0) && (a += MOD); } inline LL modMul(LL a, LL b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a * b) % MOD; } inline LL modAdd(LL a, LL b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a + b) % MOD; } inline LL modSub(LL a, LL b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; } inline LL modPow(LL b, LL p) { LL r = 1; while (p) { if (p & 1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; } inline LL modInverse(LL a) { return modPow(a, MOD - 2); } inline LL modDiv(LL a, LL b) { return modMul(a, modInverse(b)); } inline bool isInside(PII p, LL n, LL m) { return (p.first >= 0 && p.first < n && p.second >= 0 && p.second < m); } inline bool isInside(PII p, LL n) { return (p.first >= 0 && p.first < n && p.second >= 0 && p.second < n); } inline bool isSquare(LL x) { LL s = sqrt(x); return (s * s == x); } inline bool isFib(LL x) { return isSquare(5 * x * x + 4) || isSquare(5 * x * x - 4); } inline bool isPowerOfTwo(LL x) { return ((1LL << (LL)log2(x)) == x); } inline LL gcd(LL a, LL b) { return __gcd(a, b); } inline LL lcm(LL a, LL b) { return (a * (b / gcd(a, b))); } // Prime Number Generator /* #define mx 1000006 bitset <mx> mark; vector <int> primes; void sieve() { mark[0] = mark[1] = 1; primes.push_back(2); int lim = sqrt(mx * 1.0) + 2; for (int i = 4; i < mx; i += 2) mark[i] = 1; for (int i = 3; i < mx; i += 2) { if (!mark[i]) { primes.push_back(i); if (i <= lim) for (int j = i * i; j < mx; j += i) mark[j] = 1; } } } */ int main() { #ifndef ONLINE_JUDGE freopen("in", "r", stdin); freopen("out", "w", stdout); #endif optimize(); int a, p; cin >> a >> p; a *= 3; a += p; a >>= 1; cout << a << endl; }
#include <bits/stdc++.h> using namespace std; // typedefs typedef long long LL; typedef vector<int> VI; typedef vector<LL> VL; typedef vector<VI> VVI; typedef vector<VL> VVL; typedef pair<int, int> PII; typedef pair<double, double> PDD; typedef pair<LL, LL> PLL; typedef vector<PII> VII; typedef vector<PLL> VLL; // #Defines #define rep(i, a, b) for (i = a; i <= b; i++) #define repR(i, a, b) for (i = a; i >= b; i--) #define pb push_back // #define pb emplace_back #define F first #define S second #define mp make_pair #define all(c) c.begin(), c.end() #define endl '\n' #define pf printf #define sf scanf #define MOD 1000000007 // #define harmonic(n) 0.57721566490153286l+log(n) // if harmonic numbers need to be calculated, precalculate upto 1e6, then for // any x > 1e6 call harmonic(x + 0.5) #define RESET(a, b) memset(a, b, sizeof(a)) #define sqr(a) ((a) * (a)) #define optimize() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); const double PI = acos(-1); const double eps = 1e-9; const int inf = 2000000000; const LL infLL = 9000000000000000000; // Bit Operations inline bool checkBit(LL n, int i) { return n & (1LL << i); } inline LL setBit(LL n, int i) { return n | (1LL << i); ; } inline LL resetBit(LL n, int i) { return n & (~(1LL << i)); } // Rotation: S -> E -> N -> W int fx[] = {0, +1, 0, -1}; int fy[] = {-1, 0, +1, 0}; // int dx[] = {0, +1, +1, +1, 0, -1, -1, -1}; // int dy[] = {-1, -1, 0, +1, +1, +1, 0, -1}; // Inline functions inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } inline bool isLeapYear(LL year) { return (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0); } inline void normal(LL &a) { a %= MOD; (a < 0) && (a += MOD); } inline LL modMul(LL a, LL b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a * b) % MOD; } inline LL modAdd(LL a, LL b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a + b) % MOD; } inline LL modSub(LL a, LL b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; } inline LL modPow(LL b, LL p) { LL r = 1; while (p) { if (p & 1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; } inline LL modInverse(LL a) { return modPow(a, MOD - 2); } inline LL modDiv(LL a, LL b) { return modMul(a, modInverse(b)); } inline bool isInside(PII p, LL n, LL m) { return (p.first >= 0 && p.first < n && p.second >= 0 && p.second < m); } inline bool isInside(PII p, LL n) { return (p.first >= 0 && p.first < n && p.second >= 0 && p.second < n); } inline bool isSquare(LL x) { LL s = sqrt(x); return (s * s == x); } inline bool isFib(LL x) { return isSquare(5 * x * x + 4) || isSquare(5 * x * x - 4); } inline bool isPowerOfTwo(LL x) { return ((1LL << (LL)log2(x)) == x); } inline LL gcd(LL a, LL b) { return __gcd(a, b); } inline LL lcm(LL a, LL b) { return (a * (b / gcd(a, b))); } // Prime Number Generator /* #define mx 1000006 bitset <mx> mark; vector <int> primes; void sieve() { mark[0] = mark[1] = 1; primes.push_back(2); int lim = sqrt(mx * 1.0) + 2; for (int i = 4; i < mx; i += 2) mark[i] = 1; for (int i = 3; i < mx; i += 2) { if (!mark[i]) { primes.push_back(i); if (i <= lim) for (int j = i * i; j < mx; j += i) mark[j] = 1; } } } */ int main() { // #ifndef ONLINE_JUDGE // freopen("in", "r", stdin); // freopen("out", "w", stdout); // #endif optimize(); int a, p; cin >> a >> p; a *= 3; a += p; a >>= 1; cout << a << endl; }
replace
139
143
139
143
0
p03029
C++
Runtime Error
#include <iostream> int main() { int a, p; std::cin >> a >> p; std::cout << (a * 3 + p) / 2 << std::endl; return 1; }
#include <iostream> int main() { int a, p; std::cin >> a >> p; std::cout << (a * 3 + p) / 2 << std::endl; return 0; }
replace
7
8
7
8
1
p03029
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; int main() { int A, P; cin >> A >> P; cout << 3 * A / P << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; int main() { int A, P; cin >> A >> P; cout << (3 * A + P) / 2 << endl; return 0; }
replace
9
10
9
10
0
p03029
C++
Runtime Error
#include <iostream> using namespace std; int main() { int a, b, c, d; cin >> a >> b; c = a * 3; d = c + b; cout << d % 0 << endl; }
#include <iostream> using namespace std; int main() { int a, b, c, d; cin >> a >> b; c = a * 3; d = c + b; cout << d / 2 << endl; }
replace
8
9
8
9
-8
p03029
C++
Runtime Error
#include <algorithm> #include <iostream> #include <math.h> #include <vector> using namespace std; typedef long long ll; int main(void) { int a, p; cin >> a >> p; cout << 3 * a / p << endl; }
#include <algorithm> #include <iostream> #include <math.h> #include <vector> using namespace std; typedef long long ll; int main(void) { int a, p; cin >> a >> p; cout << (3 * a + p) / 2 << endl; }
replace
10
11
10
11
0
p03029
C++
Runtime Error
#include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { int A = atoi(argv[1]); int P = atoi(argv[2]); printf("%d\n", ((3 * A) + P) / 2); return 0; }
#include <stdio.h> #include <stdlib.h> int main() { int A; int P; scanf("%d %d\n", &A, &P); int a = 3 * A + P; int b = (a - a % 2) / 2; printf("%d\n", b); return 0; }
replace
3
8
3
10
-11
p03029
Python
Runtime Error
A, P = map(int, input.split(" ")) print((3 * A + P) // 2)
A, P = map(int, input().split(" ")) print((3 * A + P) // 2)
replace
0
1
0
1
AttributeError: 'builtin_function_or_method' object has no attribute 'split'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03029/Python/s942506931.py", line 1, in <module> A, P = map(int, input.split(" ")) AttributeError: 'builtin_function_or_method' object has no attribute 'split'
p03029
Python
Runtime Error
a, p = map(int, input()) print((3 * a + p) // 2)
a, p = map(int, input().split()) print((3 * a + p) // 2)
replace
0
1
0
1
ValueError: invalid literal for int() with base 10: ' '
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03029/Python/s938793340.py", line 1, in <module> a, p = map(int, input()) ValueError: invalid literal for int() with base 10: ' '
p03029
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(void) { int a, p; cin >> a >> p; cout << (3 * a) / p; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main(void) { int a, p; cin >> a >> p; int kep = 3 * a + p; cout << kep / 2; return 0; }
replace
7
8
7
9
0
p03030
C++
Runtime Error
#include <algorithm> #include <iostream> #include <math.h> #include <string> #include <vector> using namespace std; int main() { string A[20], sub1; int B[20], sub2, C[20], N; int i, j; cin >> N; for (i = 0; i < N; i++) { cin >> A[i] >> B[i]; C[i] = i + 1; } for (i = 0; i < N - 1; i++) { for (j = i + 1; j < N; j++) { if (A[i] >= A[j]) { sub1 = A[i]; A[i] = A[j]; A[j] = sub1; sub2 = B[i]; B[i] = B[j]; B[j] = sub2; sub2 = C[i]; C[i] = C[j]; C[j] = sub2; } } } for (i = 0; i < N - 1; i++) { for (j = i + 1; j < N; j++) { if (A[i] == A[j]) { if (B[i] < B[j]) { sub1 = A[i]; A[i] = A[j]; A[j] = sub1; sub2 = B[i]; B[i] = B[j]; B[j] = sub2; sub2 = C[i]; C[i] = C[j]; C[j] = sub2; } } } } for (i = 0; i < N; i++) cout << C[i] << endl; return 0; }
#include <algorithm> #include <iostream> #include <math.h> #include <string> #include <vector> using namespace std; int main() { string A[100], sub1; int B[100], sub2, C[100], N; int i, j; cin >> N; for (i = 0; i < N; i++) { cin >> A[i] >> B[i]; C[i] = i + 1; } for (i = 0; i < N - 1; i++) { for (j = i + 1; j < N; j++) { if (A[i] >= A[j]) { sub1 = A[i]; A[i] = A[j]; A[j] = sub1; sub2 = B[i]; B[i] = B[j]; B[j] = sub2; sub2 = C[i]; C[i] = C[j]; C[j] = sub2; } } } for (i = 0; i < N - 1; i++) { for (j = i + 1; j < N; j++) { if (A[i] == A[j]) { if (B[i] < B[j]) { sub1 = A[i]; A[i] = A[j]; A[j] = sub1; sub2 = B[i]; B[i] = B[j]; B[j] = sub2; sub2 = C[i]; C[i] = C[j]; C[j] = sub2; } } } } for (i = 0; i < N; i++) cout << C[i] << endl; return 0; }
replace
8
10
8
10
0
p03030
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <set> #include <string> #include <time.h> #include <vector> using namespace std; typedef long long ll; static const ll INF = (ll)1 << 62; static const ll MOD = 1e9 + 7; #define rep(i, s, n) for (ll i = s; i < n; i++) #define repe(i, s, n) for (ll i = s; i <= n; i++) map<string, ll> m; int main() { ll n; cin >> n; string str[100]; ll point[100]; ll ans[100]; repe(i, 1, n) { string s; cin >> str[i]; ll p; cin >> point[i]; m[str[i]]++; } for (map<string, ll>::iterator it = m.begin(); it != m.end(); it++) { string s1 = it->first; vector<pair<ll, ll>> v; repe(i, 1, n) { if (s1 == str[i]) { v.push_back(make_pair(point[i], i)); } } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); for (vector<pair<ll, ll>>::iterator it = v.begin(); it != v.end(); it++) { cout << it->second << endl; } } return 0; }
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <set> #include <string> #include <time.h> #include <vector> using namespace std; typedef long long ll; static const ll INF = (ll)1 << 62; static const ll MOD = 1e9 + 7; #define rep(i, s, n) for (ll i = s; i < n; i++) #define repe(i, s, n) for (ll i = s; i <= n; i++) map<string, ll> m; int main() { ll n; cin >> n; string str[101]; ll point[101]; repe(i, 1, n) { string s; cin >> str[i]; ll p; cin >> point[i]; m[str[i]]++; } for (map<string, ll>::iterator it = m.begin(); it != m.end(); it++) { string s1 = it->first; vector<pair<ll, ll>> v; repe(i, 1, n) { if (s1 == str[i]) { v.push_back(make_pair(point[i], i)); } } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); for (vector<pair<ll, ll>>::iterator it = v.begin(); it != v.end(); it++) { cout << it->second << endl; } } return 0; }
replace
19
22
19
21
0
p03030
C++
Runtime Error
#include <algorithm> #include <iostream> #include <numeric> #include <vector> using namespace std; int main() { int N; cin >> N; vector<pair<string, int>> Guide(N + 1); for (int i = 1; i <= N; i++) { string S; int P; cin >> S >> P; Guide[i] = {S, P}; } vector<int> Index(N); iota(Index.begin(), Index.end(), 1); sort(Index.begin(), Index.end(), [Guide](const auto &a, const auto &b) { if (Guide[a].first == Guide[b].first) return Guide[a].second > Guide[b].second; else Guide[a].first < Guide[b].first; }); for (const auto &i : Index) cout << i << endl; }
#include <algorithm> #include <iostream> #include <numeric> #include <vector> using namespace std; int main() { int N; cin >> N; vector<pair<string, int>> Guide(N + 1); for (int i = 1; i <= N; i++) { string S; int P; cin >> S >> P; Guide[i] = {S, P}; } vector<int> Index(N); iota(Index.begin(), Index.end(), 1); sort(Index.begin(), Index.end(), [Guide](const auto &a, const auto &b) { if (Guide[a].first == Guide[b].first) return Guide[a].second > Guide[b].second; else return Guide[a].first < Guide[b].first; }); for (const auto &i : Index) cout << i << endl; }
replace
23
24
23
24
0
p03030
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define SQ(a) (a) * (a)you #define f first #define s second #define int long long #define PB push_back #define MP make_pair #define db long double #define all(a) a.begin(), a.end() #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 #define cases \ int testcases; \ cin >> testcases; \ while (testcases--) bool customsort(const pair<string, int> &a, const pair<string, int> &b) { if (a.f != b.f) { return a.f < b.f; } return a.s > b.s; } int32_t main() { IOS #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif int n; cin >> n; vector<pair<string, int>> v, v2; for (int i = 0; i < n; i++) { string s; cin >> s; int x; cin >> x; v.PB(MP(s, x)); } v2 = v; sort(v.begin(), v.end(), customsort); for (auto i : v) { int ans = 0; for (auto j : v2) { ans++; if (j == i) { cout << ans << endl; } } } return 0; }
#include <bits/stdc++.h> using namespace std; #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define endl "\n" #define SQ(a) (a) * (a)you #define f first #define s second #define int long long #define PB push_back #define MP make_pair #define db long double #define all(a) a.begin(), a.end() #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 #define cases \ int testcases; \ cin >> testcases; \ while (testcases--) bool customsort(const pair<string, int> &a, const pair<string, int> &b) { if (a.f != b.f) { return a.f < b.f; } return a.s > b.s; } int32_t main() { IOS int n; cin >> n; vector<pair<string, int>> v, v2; for (int i = 0; i < n; i++) { string s; cin >> s; int x; cin >> x; v.PB(MP(s, x)); } v2 = v; sort(v.begin(), v.end(), customsort); for (auto i : v) { int ans = 0; for (auto j : v2) { ans++; if (j == i) { cout << ans << endl; } } } return 0; }
replace
46
54
46
47
0
p03030
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long long N; cin >> N; using col = tuple<string, long long, long long>; vector<col> p(N); for (int i = 0; i < N; i++) { string a; int b; cin >> a >> b; auto g = make_tuple(a, b, i); p.at(i) = g; } sort(p.begin(), p.end()); int i = 0; while (i < N) { int init = i; string p1 = get<0>(p.at(i)); string p2 = get<0>(p.at(i + 1)); while (p1 == p2) { i++; if (i == N - 1) { break; } p1 = p2; p2 = get<0>(p.at(i + 1)); } int num = i - init + 1; vector<pair<int, int>> li(num); for (int j = 0; j < num; j++) { int a, b; tie(ignore, a, b) = p.at(j + init); auto l = make_pair(a, b); li.at(j) = l; } reverse(li.begin(), li.end()); for (int j = 0; j < num; j++) { int b, k; string a; tie(a, ignore, ignore) = p.at(j + init); tie(b, k) = li.at(j); auto g = make_tuple(a, b, k); p.at(j + init) = g; } i++; } for (int i = 0; i < N; i++) { cout << get<2>(p.at(i)) + 1 << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { long long N; cin >> N; using col = tuple<string, long long, long long>; vector<col> p(N); for (int i = 0; i < N; i++) { string a; int b; cin >> a >> b; auto g = make_tuple(a, b, i); p.at(i) = g; } sort(p.begin(), p.end()); int i = 0; while (i < N) { if (i == N - 1) { break; } int init = i; string p1 = get<0>(p.at(i)); string p2 = get<0>(p.at(i + 1)); while (p1 == p2) { i++; if (i == N - 1) { break; } p1 = p2; p2 = get<0>(p.at(i + 1)); } int num = i - init + 1; vector<pair<int, int>> li(num); for (int j = 0; j < num; j++) { int a, b; tie(ignore, a, b) = p.at(j + init); auto l = make_pair(a, b); li.at(j) = l; } reverse(li.begin(), li.end()); for (int j = 0; j < num; j++) { int b, k; string a; tie(a, ignore, ignore) = p.at(j + init); tie(b, k) = li.at(j); auto g = make_tuple(a, b, k); p.at(j + init) = g; } i++; } for (int i = 0; i < N; i++) { cout << get<2>(p.at(i)) + 1 << endl; } }
insert
19
19
19
22
0
p03030
C++
Runtime Error
#include <bits/stdc++.h> typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; typedef std::pair<int, int> pii; typedef std::pair<ll, ll> pll; typedef std::pair<double, double> pdd; using namespace std; #define fastio() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define loop(i, a, b) for (ll i = a; i < b; i++) #define loope(i, a, b) for (ll i = a; i <= b; i++) #define test() \ ull testcase; \ cin >> testcase; \ while (testcase--) #define pb push_back #define mp make_pair #define nl cout << "\n" #define prime 1000000007 #define debug(x) cout << (#x) << " : " << x, nl #define debug2(x, y) cout << (#x) << " : " << x << " " << (#y) << " : " << y, nl #define debug3(x, y, z) \ cout << (#x) << " : " << x << " " << (#y) << " : " << y << " " << (#z) \ << " : " << z, \ nl #define f first #define s second #define oa(a, n) \ loop(i, 0, n) cout << a[i] << " "; \ nl; #define ov(a) \ loop(i, 0, a.size()) cout << a[i] << " "; \ nl; #define MOD(a) (((a % prime) + prime) % prime) int main() { #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif vector<pair<string, ll>> v; map<ll, ll> m; ll n, i; cin >> n; loop(i, 1, n + 1) { string s; ll u; cin >> s >> u; v.pb(mp(s, u)); m[u] = i; } sort(v.begin(), v.end()); string s1 = v[0].first; vector<ll> v1; // loop(i,0,v.size()) // cout << v[i].first << " " << v[i].second << endl; loop(i, 0, n) { if (s1 == v[i].first) { v1.pb(v[i].second); // cout << s1 << " " << m[v[i].second] << endl; } else { sort(v1.begin(), v1.end(), greater<ll>()); for (ll j = 0; j < v1.size(); j++) cout << m[v1[j]] << endl; v1.clear(); v1.pb(v[i].second); s1 = v[i].first; } } sort(v1.begin(), v1.end(), greater<ll>()); for (ll j = 0; j < v1.size(); j++) cout << m[v1[j]] << endl; }
#include <bits/stdc++.h> typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; typedef std::pair<int, int> pii; typedef std::pair<ll, ll> pll; typedef std::pair<double, double> pdd; using namespace std; #define fastio() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define loop(i, a, b) for (ll i = a; i < b; i++) #define loope(i, a, b) for (ll i = a; i <= b; i++) #define test() \ ull testcase; \ cin >> testcase; \ while (testcase--) #define pb push_back #define mp make_pair #define nl cout << "\n" #define prime 1000000007 #define debug(x) cout << (#x) << " : " << x, nl #define debug2(x, y) cout << (#x) << " : " << x << " " << (#y) << " : " << y, nl #define debug3(x, y, z) \ cout << (#x) << " : " << x << " " << (#y) << " : " << y << " " << (#z) \ << " : " << z, \ nl #define f first #define s second #define oa(a, n) \ loop(i, 0, n) cout << a[i] << " "; \ nl; #define ov(a) \ loop(i, 0, a.size()) cout << a[i] << " "; \ nl; #define MOD(a) (((a % prime) + prime) % prime) int main() { vector<pair<string, ll>> v; map<ll, ll> m; ll n, i; cin >> n; loop(i, 1, n + 1) { string s; ll u; cin >> s >> u; v.pb(mp(s, u)); m[u] = i; } sort(v.begin(), v.end()); string s1 = v[0].first; vector<ll> v1; // loop(i,0,v.size()) // cout << v[i].first << " " << v[i].second << endl; loop(i, 0, n) { if (s1 == v[i].first) { v1.pb(v[i].second); // cout << s1 << " " << m[v[i].second] << endl; } else { sort(v1.begin(), v1.end(), greater<ll>()); for (ll j = 0; j < v1.size(); j++) cout << m[v1[j]] << endl; v1.clear(); v1.pb(v[i].second); s1 = v[i].first; } } sort(v1.begin(), v1.end(), greater<ll>()); for (ll j = 0; j < v1.size(); j++) cout << m[v1[j]] << endl; }
delete
40
47
40
40
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p03030
C++
Runtime Error
/** * Name: Ajay Subhash Jadhav * Institute: International Institute of Technology Hyderabad */ #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string.h> #include <vector> #define LL long long #define inf 0x7fffffff #define mod 1000000007 #define pb push_back #define ppi pair<int, int> #define vi vector<int> #define vii vector<ppi> #define vll vector<LL> #define mp make_pair using namespace std; void fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } void inputread() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } struct resto { string city; int points; int id; }; bool cmp(resto a, resto b) { if (a.city == b.city) return a.points > b.points; return a.city < b.city; } int main() { fastio(); inputread(); int n, m, i, j, t; cin >> n; vector<resto> a; for (i = 1; i <= n; i++) { resto r; cin >> r.city >> r.points; r.id = i; a.pb(r); } sort(a.begin(), a.end(), cmp); for (i = 0; i < n; i++) cout << a[i].id << "\n"; return 0; }
/** * Name: Ajay Subhash Jadhav * Institute: International Institute of Technology Hyderabad */ #include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctime> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string.h> #include <vector> #define LL long long #define inf 0x7fffffff #define mod 1000000007 #define pb push_back #define ppi pair<int, int> #define vi vector<int> #define vii vector<ppi> #define vll vector<LL> #define mp make_pair using namespace std; void fastio() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } void inputread() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } struct resto { string city; int points; int id; }; bool cmp(resto a, resto b) { if (a.city == b.city) return a.points > b.points; return a.city < b.city; } int main() { fastio(); int n, m, i, j, t; cin >> n; vector<resto> a; for (i = 1; i <= n; i++) { resto r; cin >> r.city >> r.points; r.id = i; a.pb(r); } sort(a.begin(), a.end(), cmp); for (i = 0; i < n; i++) cout << a[i].id << "\n"; return 0; }
delete
55
56
55
55
0
p03030
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; struct info { string cn; int score, sn; bool operator<(const info &rhs) { if (cn != rhs.cn) return cn < rhs.cn; return score > rhs.score; } } cities[100]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> cities[i].cn >> cities[i].score; cities[i].sn = i; } sort(cities, cities + n + 1); for (int i = 1; i <= n; i++) { cout << cities[i].sn << "\n"; } }
#include <bits/stdc++.h> using namespace std; struct info { string cn; int score, sn; bool operator<(const info &rhs) { if (cn != rhs.cn) return cn < rhs.cn; return score > rhs.score; } } cities[103]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> cities[i].cn >> cities[i].score; cities[i].sn = i; } sort(cities, cities + n + 1); for (int i = 1; i <= n; i++) { cout << cities[i].sn << "\n"; } }
replace
12
13
12
13
0
p03030
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (long long i = 0; i < n; i++) #define REP1(i, n) for (long long i = 1; i <= n; i++) #define ITE(arr) for (auto ite = (arr).begin(); ite != (arr).end(); ite++) #define ALL(a) (a.begin()), (a.end()) #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, 0xff, sizeof(a)) typedef long long ll; typedef pair<int, int> pii; //--------------------- #define MAXN //--------------------- ll n, p; string s; typedef pair<string, int> psi; vector<psi> vec; bool mysort(psi a, psi b) { bool ret = false; if (a.first == b.first) { ret = (a.second % 1000) > (b.second % 1000); } else { int id = 0; while (a.first[id] == b.first[id]) { id++; if (id >= a.first.length()) { ret = true; break; } if (id >= b.first.length()) { ret = false; break; } } ret = a.first[id] < b.first[id]; } } int main() { cin >> n; REP(i, n) { cin >> s >> p; vec.push_back(psi(s, p + (i + 1) * 1000)); } sort(ALL(vec), mysort); REP(i, n) cout << vec[i].second / 1000 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (long long i = 0; i < n; i++) #define REP1(i, n) for (long long i = 1; i <= n; i++) #define ITE(arr) for (auto ite = (arr).begin(); ite != (arr).end(); ite++) #define ALL(a) (a.begin()), (a.end()) #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, 0xff, sizeof(a)) typedef long long ll; typedef pair<int, int> pii; //--------------------- #define MAXN //--------------------- ll n, p; string s; typedef pair<string, int> psi; vector<psi> vec; bool mysort(psi a, psi b) { bool ret = false; if (a.first == b.first) { ret = (a.second % 1000) > (b.second % 1000); } else { int id = 0; while (a.first[id] == b.first[id]) { id++; if (id >= a.first.length()) { ret = true; break; } if (id >= b.first.length()) { ret = false; break; } } ret = a.first[id] < b.first[id]; } return ret; } int main() { cin >> n; REP(i, n) { cin >> s >> p; vec.push_back(psi(s, p + (i + 1) * 1000)); } sort(ALL(vec), mysort); REP(i, n) cout << vec[i].second / 1000 << endl; return 0; }
insert
40
40
40
41
0
p03030
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define INF 2e9 + 5 #define ll long long bool compare(const pair<string, pair<int, int>> &a, const pair<string, pair<int, int>> &b) { if (a.first < b.first) return true; if (a.first == b.first) return a.second.first > b.second.first; } int main() { vector<pair<string, pair<int, int>>> v; int n; cin >> n; for (int i = 0; i < n; i++) { string temp; int score; cin >> temp; cin >> score; v.push_back(make_pair(temp, make_pair(score, i))); } sort(v.begin(), v.end(), compare); for (int i = 0; i < v.size(); i++) cout << v[i].second.second + 1 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define INF 2e9 + 5 #define ll long long bool compare(const pair<string, pair<int, int>> &a, const pair<string, pair<int, int>> &b) { if (a.first < b.first) return true; if (a.first == b.first) return a.second.first > b.second.first; return false; } int main() { vector<pair<string, pair<int, int>>> v; int n; cin >> n; for (int i = 0; i < n; i++) { string temp; int score; cin >> temp; cin >> score; v.push_back(make_pair(temp, make_pair(score, i))); } sort(v.begin(), v.end(), compare); for (int i = 0; i < v.size(); i++) cout << v[i].second.second + 1 << endl; return 0; }
insert
11
11
11
12
0
p03030
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int n; vector<pair<string, int>> array, copy; cin >> n; array.resize(n); for (int i = 0; i < n; i++) { cin >> array[i].first >> array[i].second; } copy = array; sort(array.begin(), array.end()); for (int j = 0; j < array.size() - 1; j++) { if (array[j].first == array[j + 1].first) { int num = 0; while (array[j + num].first == array[j].first) { num++; } partial_sort(array.begin() + j, array.begin() + j + num, array.begin() + j + num, greater<pair<string, int>>()); } } for (int k = 0; k < array.size(); k++) { int m = 0; while (copy[m] != array[k]) { m++; } cout << m + 1 << endl; } return 0; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int n; vector<pair<string, int>> array, copy; cin >> n; array.resize(n); for (int i = 0; i < n; i++) { cin >> array[i].first >> array[i].second; } copy = array; sort(array.begin(), array.end()); for (int j = 0; j < array.size() - 1; j++) { if (array[j].first == array[j + 1].first) { int num = 1; while (true) { if (j + num >= array.size()) { break; } else if (array[j].first != array[j + num].first) { break; } num++; } partial_sort(array.begin() + j, array.begin() + j + num, array.begin() + j + num, greater<pair<string, int>>()); } } for (int k = 0; k < array.size(); k++) { int m = 0; while (copy[m] != array[k]) { m++; } cout << m + 1 << endl; } return 0; }
replace
21
23
21
28
0
p03030
C++
Runtime Error
#if defined(__GNUC__) #include <bits/stdc++.h> #define __int32 __int32_t // __GNUC__ #else #include "bits/stdc++.h" #endif using namespace std; #define int long long #define itn __int32 #define REP(i, n) for (itn(i) = 0; (i) < (n); ++(i)) #define REP2(i, x, n) for (itn(i) = x; (i) < (n); ++(i)) #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define SORT(x) std::sort(ALL(x)) #define RSORT(x, T) std::sort(ALL(x), greater<T>()) #define REVERCE(x) std::reverce(ALL(x)) #define ACM(x, y) std::accumulate(ALL(x), y) #define INT_POW(x, y) \ [](int a, int b) -> int { \ int c = a; \ REP(i, b - 1) { c *= a; } \ return c; \ }(x, y) #define INT_POWM(x, y, m) \ [](int a, int b, int m) -> int { \ int c = a; \ REP(i, b - 1) { \ c *= a; \ c %= m; \ } \ return c; \ }(x, y, m) itn main() { std::ios::sync_with_stdio(false); int n; cin >> n; vector<pair<pair<string, int>, int>> a; REP(i, n) { cin >> a[i].first.first >> a[i].first.second; a[i].first.second *= -1; a[i].second = i + 1; } SORT(a); REP(i, n) { cout << a[i].second << '\n'; } return 0; }
#if defined(__GNUC__) #include <bits/stdc++.h> #define __int32 __int32_t // __GNUC__ #else #include "bits/stdc++.h" #endif using namespace std; #define int long long #define itn __int32 #define REP(i, n) for (itn(i) = 0; (i) < (n); ++(i)) #define REP2(i, x, n) for (itn(i) = x; (i) < (n); ++(i)) #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define SORT(x) std::sort(ALL(x)) #define RSORT(x, T) std::sort(ALL(x), greater<T>()) #define REVERCE(x) std::reverce(ALL(x)) #define ACM(x, y) std::accumulate(ALL(x), y) #define INT_POW(x, y) \ [](int a, int b) -> int { \ int c = a; \ REP(i, b - 1) { c *= a; } \ return c; \ }(x, y) #define INT_POWM(x, y, m) \ [](int a, int b, int m) -> int { \ int c = a; \ REP(i, b - 1) { \ c *= a; \ c %= m; \ } \ return c; \ }(x, y, m) itn main() { std::ios::sync_with_stdio(false); int n; cin >> n; vector<pair<pair<string, int>, int>> a(n); REP(i, n) { cin >> a[i].first.first >> a[i].first.second; a[i].first.second *= -1; a[i].second = i + 1; } SORT(a); REP(i, n) { cout << a[i].second << '\n'; } return 0; }
replace
44
45
44
45
-11
p03030
C++
Runtime Error
#include <stdio.h> #include <string.h> int main() { int i, j; int num; scanf("%d", &num); /* 文字列 */ int score[101]; int sort[101]; char moji[101][10], tmp[10]; int test; /* 3つの文字列を入力 */ for (i = 1; i < num + 1; i++) { sort[i] = i; scanf("%s %d", moji[i], &score[i]); } for (i = 2; i < num + 1; i++) { for (j = 2; j < num + 1; j++) { if (strcmp(moji[j - 1], moji[j]) > 0) { strcpy(tmp, moji[j - 1]); strcpy(moji[j - 1], moji[j]); strcpy(moji[j], tmp); test = score[j - 1]; score[j - 1] = score[j]; score[j] = test; test = sort[j - 1]; sort[j - 1] = sort[j]; sort[j] = test; } else if (strcmp(moji[j - 1], moji[j]) == 0) { if (score[j - 1] < score[j]) { strcpy(tmp, moji[j - 1]); strcpy(moji[j - 1], moji[j]); strcpy(moji[j], tmp); test = score[j - 1]; score[j - 1] = score[j]; score[j] = test; test = sort[j - 1]; sort[j - 1] = sort[j]; sort[j] = test; } } } } for (i = 1; i < num + 1; i++) { printf("%d\n", sort[i]); } return 0; }
#include <stdio.h> #include <string.h> int main() { int i, j; int num; scanf("%d", &num); /* 文字列 */ int score[101]; int sort[101]; char moji[101][20], tmp[20]; int test; /* 3つの文字列を入力 */ for (i = 1; i < num + 1; i++) { sort[i] = i; scanf("%s %d", moji[i], &score[i]); } for (i = 2; i < num + 1; i++) { for (j = 2; j < num + 1; j++) { if (strcmp(moji[j - 1], moji[j]) > 0) { strcpy(tmp, moji[j - 1]); strcpy(moji[j - 1], moji[j]); strcpy(moji[j], tmp); test = score[j - 1]; score[j - 1] = score[j]; score[j] = test; test = sort[j - 1]; sort[j - 1] = sort[j]; sort[j] = test; } else if (strcmp(moji[j - 1], moji[j]) == 0) { if (score[j - 1] < score[j]) { strcpy(tmp, moji[j - 1]); strcpy(moji[j - 1], moji[j]); strcpy(moji[j], tmp); test = score[j - 1]; score[j - 1] = score[j]; score[j] = test; test = sort[j - 1]; sort[j - 1] = sort[j]; sort[j] = test; } } } } for (i = 1; i < num + 1; i++) { printf("%d\n", sort[i]); } return 0; }
replace
11
12
11
12
-6
*** stack smashing detected ***: terminated
p03030
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; pair<pair<string, int>, int> a[100]; cin >> n; for (int i = 0; i < n; i++) { int b; string x; cin >> x; cin >> b; a[i] = make_pair(make_pair(x, b), i); } for (int i = 0; i < n - 1; i++) for (int j = n; j >= i + 1; j--) { if (a[j - 1].first.first < a[j].first.first) { swap(a[j - 1], a[j]); } if (a[j - 1].first.first == a[j].first.first) if (a[j - 1].first.second > a[j].first.second) { swap(a[j - 1], a[j]); } } for (int i = 0; i < n; i++) { cout << a[n - i - 1].second + 1 << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; pair<pair<string, int>, int> a[111]; cin >> n; for (int i = 0; i < n; i++) { int b; string x; cin >> x; cin >> b; a[i] = make_pair(make_pair(x, b), i); } for (int i = 0; i < n - 1; i++) for (int j = n; j >= i + 1; j--) { if (a[j - 1].first.first < a[j].first.first) { swap(a[j - 1], a[j]); } if (a[j - 1].first.first == a[j].first.first) if (a[j - 1].first.second > a[j].first.second) { swap(a[j - 1], a[j]); } } for (int i = 0; i < n; i++) { cout << a[n - i - 1].second + 1 << endl; } return 0; }
replace
4
5
4
5
0
p03030
Python
Runtime Error
n = int(input()) a = [] for i in range(n): s, p = list(map(int, input().split())) a.append((s, -int(p), i)) a.sort() for _, _, i in a: print(i + 1)
n = int(input()) a = [] for i in range(n): s, p = input().split() a.append((s, -int(p), i)) a.sort() for _, _, i in a: print(i + 1)
replace
3
4
3
4
ValueError: invalid literal for int() with base 10: 'khabarovsk'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03030/Python/s542428073.py", line 4, in <module> s, p = list(map(int, input().split())) ValueError: invalid literal for int() with base 10: 'khabarovsk'
p03030
C++
Runtime Error
#include <algorithm> #include <chrono> #include <cmath> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; #define fs first #define sc second #define INF 1000000000 #define MOD 1000000007 #define EPS 0.00000001 int main() { int N; cin >> N; vector<pair<pair<string, int>, int>> V(N); for (int i = 0; i < N; i++) { string S; cin >> S; int P; cin >> P; V[i] = pair<pair<string, int>, int>(pair<string, int>(S, P), i + 1); } sort(V.begin(), V.end()); for (int i = 0; i < N; i++) { string C = V[i].fs.fs; int j = i + 1; int p = i; while (V[j].fs.fs == C) { j++; i++; if (j >= N || i >= N) break; } reverse(V.begin() + p, V.begin() + j); } for (int i = 0; i < N; i++) { cout << V[i].sc << endl; } return 0; }
#include <algorithm> #include <chrono> #include <cmath> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; #define fs first #define sc second #define INF 1000000000 #define MOD 1000000007 #define EPS 0.00000001 int main() { int N; cin >> N; vector<pair<pair<string, int>, int>> V(N); for (int i = 0; i < N; i++) { string S; cin >> S; int P; cin >> P; V[i] = pair<pair<string, int>, int>(pair<string, int>(S, P), i + 1); } sort(V.begin(), V.end()); for (int i = 0; i < N; i++) { string C = V[i].fs.fs; int j = i + 1; if (j >= N) break; int p = i; while (V[j].fs.fs == C) { j++; i++; if (j >= N || i >= N) break; } reverse(V.begin() + p, V.begin() + j); } for (int i = 0; i < N; i++) { cout << V[i].sc << endl; } return 0; }
insert
38
38
38
40
0
p03030
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; typedef vector<int> vec1; typedef vector<string> vec2; int main() { int n; cin >> n; vector<tuple<string, int, int>> t; for (int i = 1; i < n; i++) { string s; int p; cin >> s >> p; p = -p; t.push_back(tie(s, p, i)); } sort(t.begin(), t.end()); for (int i = 0; i < n; i++) { cout << get<2>(t[i]) << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; typedef vector<int> vec1; typedef vector<string> vec2; int main() { int n; cin >> n; vector<tuple<string, int, int>> t; for (int i = 1; i < n + 1; i++) { string s; int p; cin >> s >> p; p = -p; t.push_back(tie(s, p, i)); } sort(t.begin(), t.end()); for (int i = 0; i < n; i++) { cout << get<2>(t[i]) << endl; } }
replace
11
12
11
12
0
p03030
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef pair<string, int> guide; int main() { int N; cin >> N; vector<guide> G; vector<guide> C; for (int i = 0; i < N; i++) { string s; int p; cin >> s >> p; G.push_back(guide(s, p)); C.push_back(guide(s, p)); } sort(C.begin(), C.end()); for (int i = 0; i < N - 1; i++) { for (int j = N - 1; j >= i - 1; j--) { if (C[j].first == C[j - 1].first) { if (C[j].second > C[j - 1].second) { guide tmp = C[j]; C[j] = C[j - 1]; C[j - 1] = tmp; } } } } for (int i = 0; i < N; i++) { guide c = C[i]; for (int j = 0; j < N; j++) { if (c == G[j]) cout << j + 1 << endl; } } return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef pair<string, int> guide; int main() { int N; cin >> N; vector<guide> G; vector<guide> C; for (int i = 0; i < N; i++) { string s; int p; cin >> s >> p; G.push_back(guide(s, p)); C.push_back(guide(s, p)); } sort(C.begin(), C.end()); for (int i = 0; i < N - 1; i++) { for (int j = N - 1; j >= i + 1; j--) { if (C[j].first == C[j - 1].first) { if (C[j].second > C[j - 1].second) { guide tmp = C[j]; C[j] = C[j - 1]; C[j - 1] = tmp; } } } } for (int i = 0; i < N; i++) { guide c = C[i]; for (int j = 0; j < N; j++) { if (c == G[j]) cout << j + 1 << endl; } } return 0; }
replace
22
23
22
23
-11
p03030
C++
Runtime Error
#include <bits/stdc++.h> #define ff first #define ss second #define ll long long #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("inp.txt", "r", stdin); freopen("outp.txt", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; map<string, vector<pair<int, int>>> m; for (int i = 1; i <= n; i++) { string s; int x; cin >> s >> x; m[s].push_back({x, i}); } for (auto &i : m) { sort(i.ss.begin(), i.ss.end(), greater<pair<int, int>>()); for (auto j : i.ss) cout << j.ss << endl; } return 0; }
#include <bits/stdc++.h> #define ff first #define ss second #define ll long long #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; map<string, vector<pair<int, int>>> m; for (int i = 1; i <= n; i++) { string s; int x; cin >> s >> x; m[s].push_back({x, i}); } for (auto &i : m) { sort(i.ss.begin(), i.ss.end(), greater<pair<int, int>>()); for (auto j : i.ss) cout << j.ss << endl; } return 0; }
delete
8
12
8
8
0
p03030
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int num_of_tuple = 0; cin >> num_of_tuple; string a; int b = 0; vector<tuple<string, int, int>> v(num_of_tuple); for (int i = 0; i < num_of_tuple; ++i) { cin >> a >> b; v.at(i) = make_tuple(a, b, 1 + i); // 3番目の要素にインデックスの代わりを入れる } // 市名順にソート sort( v.begin(), v.end(), [](const tuple<string, int, int> &t1, const tuple<string, int, int> &t2) { if (get<0>(t1) != get<0>(t2)) { return get<0>(t1) < get<0>(t2); } else { get<1>(t1) > get<1>(t2); } }); // ソートしたものを出力 for (tuple<string, int, int> i : v) { string s; int x = 0, y = 0; tie(s, x, y) = i; // cout << s << " " << x << " " << y << endl; // //入っている要素を確かめるためのcout cout << y << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int num_of_tuple = 0; cin >> num_of_tuple; string a; int b = 0; vector<tuple<string, int, int>> v(num_of_tuple); for (int i = 0; i < num_of_tuple; ++i) { cin >> a >> b; v.at(i) = make_tuple(a, b, 1 + i); // 3番目の要素にインデックスの代わりを入れる } // 市名順にソート sort( v.begin(), v.end(), [](const tuple<string, int, int> &t1, const tuple<string, int, int> &t2) { if (get<0>(t1) != get<0>(t2)) { return get<0>(t1) < get<0>(t2); } else { return get<1>(t1) > get<1>(t2); } }); // ソートしたものを出力 for (tuple<string, int, int> i : v) { string s; int x = 0, y = 0; tie(s, x, y) = i; // cout << s << " " << x << " " << y << endl; // //入っている要素を確かめるためのcout cout << y << endl; } }
replace
25
26
25
26
0
p03030
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main(void) { int N; cin >> N; vector<int> P(N); vector<string> S(N), C(N); vector<int> Q(N), R(N); for (int i = 0; i < N; i++) { cin >> S[i] >> P[i]; C[i] = S[i]; Q[i] = R[i] = 0; } sort(C.begin(), C.end()); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (C[i] == S[j] && Q[i] < P[j]) { Q[i] = P[j]; R[i] = j + 1; } } S[R[i] - 1] = "ZZZZZ"; P[R[i] - 1] = 0; } for (int i = 0; i < N; i++) { cout << R[i] << endl; } }
#include <bits/stdc++.h> using namespace std; int main(void) { int N; cin >> N; vector<int> P(N); vector<string> S(N), C(N); vector<int> Q(N), R(N); for (int i = 0; i < N; i++) { cin >> S[i] >> P[i]; C[i] = S[i]; Q[i] = R[i] = 0; } sort(C.begin(), C.end()); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (C[i] == S[j] && Q[i] <= P[j]) { Q[i] = P[j]; R[i] = j + 1; } } S[R[i] - 1] = "ZZZZZ"; P[R[i] - 1] = 0; } for (int i = 0; i < N; i++) { cout << R[i] << endl; } }
replace
17
18
17
18
0
p03030
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { pair<pair<string, int>, int> p[120]; int n, a; string s; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%s%d", &s, &a); p[i] = make_pair(make_pair(s, -a), i); } sort(p, p + n); for (int i = 0; i < n; i++) printf("%d\n", p[i].second + 1); }
#include <bits/stdc++.h> using namespace std; int main() { pair<pair<string, int>, int> p[120]; int n, a; string s; scanf("%d", &n); for (int i = 0; i < n; i++) { cin >> s >> a; p[i] = make_pair(make_pair(s, -a), i); } sort(p, p + n); for (int i = 0; i < n; i++) printf("%d\n", p[i].second + 1); }
replace
9
10
9
10
-11
p03030
C++
Runtime Error
// in the name of god // if you read this code please search about imam hussain #include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define endl "\n"; #define migmig \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define read \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout); const int maxn = 1e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9; const int del = 728729; bool sortbysec(const pair<string, pair<int, int>> &a, const pair<string, pair<int, int>> &b) { if (a.first > b.first) return 1; if (a.first == b.first) return a.second.first < b.second.first; } int main() { migmig; vector<pair<string, pair<int, int>>> v; int n; cin >> n; string x; int y; for (int i = 1; i <= n; i++) { cin >> x >> y; v.pb(make_pair(x, make_pair(y, i))); } sort(v.begin(), v.end(), sortbysec); for (int i = n - 1; i >= 0; i--) { cout << v[i].second.second << endl; } return 0; }
// in the name of god // if you read this code please search about imam hussain #include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define endl "\n"; #define migmig \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define read \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout); const int maxn = 1e5 + 5; const int mod = 1e9 + 7; const int inf = 1e9; const int del = 728729; bool sortbysec(const pair<string, pair<int, int>> &a, const pair<string, pair<int, int>> &b) { if (a.first > b.first) return 1; if (a.first == b.first && a.second.first < b.second.first) return 1; return 0; } int main() { migmig; vector<pair<string, pair<int, int>>> v; int n; cin >> n; string x; int y; for (int i = 1; i <= n; i++) { cin >> x >> y; v.pb(make_pair(x, make_pair(y, i))); } sort(v.begin(), v.end(), sortbysec); for (int i = n - 1; i >= 0; i--) { cout << v[i].second.second << endl; } return 0; }
replace
25
27
25
28
0
p03030
Python
Runtime Error
#!/usr/bin/env python3 n = int(input()) res = [(i, *input().split()) for i in range(n)] res.sort(key=lambda x: (x[1], -int(x[2]))) for r in res: print(r[0] + 1)
#!/usr/bin/env python3 n = int(input()) res = [[i] + input().split() for i in range(n)] res.sort(key=lambda x: (x[1], -int(x[2]))) for r in res: print(r[0] + 1)
replace
2
3
2
3
0
p03030
C++
Runtime Error
// gauravsinghh #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ll long long int #define ld long double #define db double #define pii pair<int, int> #define pll pair<long long, long long> #define sii set<int> #define sll set<long long> #define vii vector<int> #define vll vector<long long> #define mii map<int, int> #define mll map<long long, long long> #define lob lower_bound #define upb upper_bound #define ff first #define ss second #define pb push_back #define pf push_front #define ins insert #define mp make_pair #define w(t) \ cin >> t; \ while (t--) #define on cout << "\n" #define o2(a, b) cout << a << " " << b #define os cout << " " #define bitcount __builtin_popcount #define gcd __gcd #define endl "\n" #define present(s, x) (s.find(x) != s.end()) #define cpresent(s, x) (find(all(s), x) != s.end()) #define ford(container, it) \ for (__typeof(container.begin()) it = container.begin(); \ it != container.end(); it++) #define fors(container, it, a, b) \ for (__typeof(container.begin()) it = a; it != b; it++) #define MOD 1000000007 #define EPSILON 1e-9 #define PI 3.14159265358979323846 #define inf 999999999999999999 #define siz 100005 #define SIZ 1000005 #define SIZE 200005 #define fbo find_by_order #define ook order_of_key #define sz(s) (int)s.size() #define mem(n, m) memset(n, m, sizeof(n)) #define rep(i, n) for (ll i = 0; i < n; i++) #define ren(i, n) for (ll i = n - 1; i >= 0; i--) #define all(x) x.begin(), x.end() #define fo(i, a, b) for (ll i = a; i <= b; i++) #define ffo(i, a, b) for (ll i = a; i >= b; i--) #define MAX 100005 #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; // #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") void io_set() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } bool comp(const pair<string, ll> &a, const pair<string, ll> &b) { return (a.first < b.first || (a.first == b.first && a.second > b.second)); } signed main() { IOS io_set(); ll n, p; string s; cin >> n; ll tt = n; vector<pair<string, ll>> a, b; while (tt--) { cin >> s >> p; a.pb(mp(s, p)); b.pb(mp(s, p)); } sort(all(b), comp); map<pair<string, ll>, ll> mpp; ll j = 1; for (auto it : a) { mpp[{it.first, it.second}] = j; j++; } for (auto it : b) { cout << mpp[{it.first, it.second}] << endl; } return 0; }
// gauravsinghh #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ll long long int #define ld long double #define db double #define pii pair<int, int> #define pll pair<long long, long long> #define sii set<int> #define sll set<long long> #define vii vector<int> #define vll vector<long long> #define mii map<int, int> #define mll map<long long, long long> #define lob lower_bound #define upb upper_bound #define ff first #define ss second #define pb push_back #define pf push_front #define ins insert #define mp make_pair #define w(t) \ cin >> t; \ while (t--) #define on cout << "\n" #define o2(a, b) cout << a << " " << b #define os cout << " " #define bitcount __builtin_popcount #define gcd __gcd #define endl "\n" #define present(s, x) (s.find(x) != s.end()) #define cpresent(s, x) (find(all(s), x) != s.end()) #define ford(container, it) \ for (__typeof(container.begin()) it = container.begin(); \ it != container.end(); it++) #define fors(container, it, a, b) \ for (__typeof(container.begin()) it = a; it != b; it++) #define MOD 1000000007 #define EPSILON 1e-9 #define PI 3.14159265358979323846 #define inf 999999999999999999 #define siz 100005 #define SIZ 1000005 #define SIZE 200005 #define fbo find_by_order #define ook order_of_key #define sz(s) (int)s.size() #define mem(n, m) memset(n, m, sizeof(n)) #define rep(i, n) for (ll i = 0; i < n; i++) #define ren(i, n) for (ll i = n - 1; i >= 0; i--) #define all(x) x.begin(), x.end() #define fo(i, a, b) for (ll i = a; i <= b; i++) #define ffo(i, a, b) for (ll i = a; i >= b; i--) #define MAX 100005 #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; // #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") // #pragma GCC optimization ("unroll-loops") void io_set() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } bool comp(const pair<string, ll> &a, const pair<string, ll> &b) { return (a.first < b.first || (a.first == b.first && a.second > b.second)); } signed main() { IOS // io_set(); ll n, p; string s; cin >> n; ll tt = n; vector<pair<string, ll>> a, b; while (tt--) { cin >> s >> p; a.pb(mp(s, p)); b.pb(mp(s, p)); } sort(all(b), comp); map<pair<string, ll>, ll> mpp; ll j = 1; for (auto it : a) { mpp[{it.first, it.second}] = j; j++; } for (auto it : b) { cout << mpp[{it.first, it.second}] << endl; } return 0; }
replace
82
84
82
86
0
p03030
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; int n, c[105]; vector<pair<string, int>> f; int main() { cin >> n; for (int i = 0; i < n; i++) { string s; int p; cin >> s >> p; c[p] = i + 1; f.push_back({s, p}); } sort(f.begin(), f.end()); int cnt = 1; for (int i = 0; i < n; i++) { if (f[i].first == f[i + 1].first && i != n) { cnt++; continue; } else { for (int j = i; cnt > 0; j--, cnt--) { cout << c[f[j].second] << endl; } cnt = 1; } } }
#include <algorithm> #include <iostream> #include <vector> using namespace std; int n, c[105]; vector<pair<string, int>> f; int main() { cin >> n; for (int i = 0; i < n; i++) { string s; int p; cin >> s >> p; c[p] = i + 1; f.push_back({s, p}); } sort(f.begin(), f.end()); int cnt = 1; for (int i = 0; i < n; i++) { if (i != n - 1) { if (f[i].first == f[i + 1].first) { cnt++; } else { for (int j = i; cnt > 0; j--, cnt--) { cout << c[f[j].second] << endl; } cnt = 1; } } else { for (int j = i; cnt > 0; j--, cnt--) { cout << c[f[j].second] << endl; } cnt = 1; } } }
replace
18
21
18
27
0
p03030
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> #include <vector> using namespace std; int main() { int N; cin >> N; string RestrunStr[100]; int RestrunNum[100]; for (int i = 1; i <= N; i++) { int P; string S; cin >> S >> P; RestrunStr[i] = S; RestrunNum[i] = P; } map<int, int> ans; int i = 1; int num = 1; for (i = 1; i <= N; i++) { num = 1; for (int j = 1; j <= N; j++) { if (RestrunStr[i] < RestrunStr[j]) { } else if (RestrunStr[i] == RestrunStr[j]) { if (RestrunNum[i] > RestrunNum[j]) { } else if (RestrunNum[i] == RestrunNum[j]) { } else { num++; } } else { num++; } } ans[num] = i; } for (int aa = 1; aa <= N; aa++) { cout << ans[aa] << endl; } }
#include <algorithm> #include <iostream> #include <map> #include <vector> using namespace std; int main() { int N; cin >> N; string RestrunStr[255]; int RestrunNum[255]; for (int i = 1; i <= N; i++) { int P; string S; cin >> S >> P; RestrunStr[i] = S; RestrunNum[i] = P; } map<int, int> ans; int i = 1; int num = 1; for (i = 1; i <= N; i++) { num = 1; for (int j = 1; j <= N; j++) { if (RestrunStr[i] < RestrunStr[j]) { } else if (RestrunStr[i] == RestrunStr[j]) { if (RestrunNum[i] > RestrunNum[j]) { } else if (RestrunNum[i] == RestrunNum[j]) { } else { num++; } } else { num++; } } ans[num] = i; } for (int aa = 1; aa <= N; aa++) { cout << ans[aa] << endl; } }
replace
9
11
9
11
0
p03030
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { char in[120]; pair<pair<string, int>, int> p[11]; int a; cin >> a; for (int i = 0; i < a; i++) { int t; cin >> in >> t; // string tmp = in; p[i] = make_pair(make_pair(in, -t), i); } sort(p, p + a); for (int i = 0; i < a; i++) { cout << p[i].second + 1 << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { char in[120]; pair<pair<string, int>, int> p[110]; int a; cin >> a; for (int i = 0; i < a; i++) { int t; cin >> in >> t; // string tmp = in; p[i] = make_pair(make_pair(in, -t), i); } sort(p, p + a); for (int i = 0; i < a; i++) { cout << p[i].second + 1 << endl; } }
replace
5
6
5
6
0
p03030
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; struct restaurant { int no; string name; int pt; }; int cmp(const void *v1, const void *v2) { restaurant *r1 = (restaurant *)v1; restaurant *r2 = (restaurant *)v2; if (r1->name > r2->name) return 1; if (r1->name < r2->name) return -1; if (r1->pt > r2->pt) return -1; if (r1->pt < r2->pt) return 1; return 0; } int main() { int n; cin >> n; vector<string> s(n); vector<int> p(n); rep(i, n) cin >> s[i] >> p[i]; restaurant rs[109]; rep(i, n) rs[i] = {.no = i + 1, .name = s[i], .pt = p[i]}; qsort(rs, n, sizeof(restaurant), cmp); rep(i, n) cout << rs[i].no << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; struct restaurant { int no; string name; int pt; }; int cmp(const void *v1, const void *v2) { restaurant *r1 = (restaurant *)v1; restaurant *r2 = (restaurant *)v2; if (r1->name > r2->name) return 1; if (r1->name < r2->name) return -1; if (r1->pt > r2->pt) return -1; if (r1->pt < r2->pt) return 1; return 0; } int main() { int n; cin >> n; vector<string> s(n); vector<int> p(n); rep(i, n) cin >> s[i] >> p[i]; vector<pair<pair<string, int>, int>> r(n); rep(i, n) r[i] = make_pair(make_pair(s[i], -p[i]), i + 1); sort(r.begin(), r.end()); rep(i, n) cout << r[i].second << endl; return 0; }
replace
33
37
33
37
-11
p03030
Python
Runtime Error
N = int(input()) SP = [(i + 1, input().split()) for i in range(N)] P = [[0, 0, 0] for _ in range(N)] for i in range(N): P[i][0] = SP[i][0] P[i][1] = SP[i][1][0] P[i][2] = int(SP[i][1][1]) P.sort(key=lambda x: x[1][1], reverse=True) P.sort(key=lambda x: x[1][0]) for p in P: print(p[0])
N = int(input()) SP = [(i + 1, input().split()) for i in range(N)] P = [[0, 0, 0] for _ in range(N)] for i in range(N): P[i][0] = SP[i][0] P[i][1] = SP[i][1][0] P[i][2] = int(SP[i][1][1]) P.sort(key=lambda x: x[2], reverse=True) P.sort(key=lambda x: x[1]) for p in P: print(p[0])
replace
7
9
7
9
0
p03030
C++
Runtime Error
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> p; const int INF = (1 << 28); const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() int n; vector<pair<string, pair<int, int>>> s; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) { string s1; int a; cin >> s1 >> a; s.push_back(make_pair(s1, make_pair(a, i + 1))); } sort(s.begin(), s.end()); int temp; bool c = false; for (int i = 0; i < n; i++) { if (s[i].first == s[i + 1].first && c == false) { temp = i; c = true; } else if (s[i].first == s[i + 1].first && c == true) { } else if (s[i].first != s[i + 1].first && c == true) { for (int j = i; j >= temp; j--) { cout << s[j].second.second << "\n"; } c = false; } else { cout << s[i].second.second << "\n"; } } }
#include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> p; const int INF = (1 << 28); const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define INF 2e9 #define ALL(v) v.begin(), v.end() int n; vector<pair<string, pair<int, int>>> s; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; i++) { string s1; int a; cin >> s1 >> a; s.push_back(make_pair(s1, make_pair(a, i + 1))); } sort(s.begin(), s.end()); int temp; bool c = false; for (int i = 0; i < n; i++) { if (i == n - 1 && c == true) { for (int j = n - 1; j >= temp; j--) { cout << s[j].second.second << "\n"; } } else if (i == n - 1 && c == false) { cout << s[i].second.second << "\n"; } else if (s[i].first == s[i + 1].first && c == false) { temp = i; c = true; } else if (s[i].first == s[i + 1].first && c == true) { } else if (s[i].first != s[i + 1].first && c == true) { for (int j = i; j >= temp; j--) { cout << s[j].second.second << "\n"; } c = false; } else { cout << s[i].second.second << "\n"; } } }
replace
50
51
50
57
0
p03030
Python
Runtime Error
# input N = int(input()) SA = [str(input()) for i in range(N)] # process cities = list(set([x.split()[0] for x in SA])) cities.sort() for y in cities: each_SA = [i for i in SA if y in i] each_points = [int(x.split()[1]) for x in each_SA] each_points.sort(reverse=True) for j in each_points: print(SA.index(y + " " + str(j)) + 1)
# input N = int(input()) SA = [str(input()) for i in range(N)] # process cities = list(set([x.split()[0] for x in SA])) cities.sort() for y in cities: each_SA = [] for i in SA: if i.split()[0] == y: each_SA.append(i) each_points = [int(x.split()[1]) for x in each_SA] each_points.sort(reverse=True) for j in each_points: print(SA.index(y + " " + str(j)) + 1)
replace
9
10
9
13
0
p03030
Python
Runtime Error
# ABC128-B # ソートが大事な問題 import itemgetter a = int(input()) book = [] for i in range(a): array = input().split() book.append((array[0], int(array[1]) * -1, i)) ans = sorted(book, key=itemgetter(0, 1)) for i in range(a): print(ans[i][2] + 1)
# ABC128-B # ソートが大事な問題 from operator import itemgetter a = int(input()) book = [] for i in range(a): array = input().split() book.append((array[0], int(array[1]) * -1, i)) ans = sorted(book, key=itemgetter(0, 1)) for i in range(a): print(ans[i][2] + 1)
replace
2
3
2
3
ModuleNotFoundError: No module named 'itemgetter'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03030/Python/s634731574.py", line 3, in <module> import itemgetter ModuleNotFoundError: No module named 'itemgetter'
p03030
C++
Runtime Error
// ROAD TO GREEN #include <algorithm> #include <bitset> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <vector> #define ll long long #define uint unsigned int #define ull unsigned ll #define mp make_pair #define pb push_back #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define speedhack() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define do(x) \ for (int i = 1; i <= x; i++) { \ solve(); \ } #define s(x) x.size() using namespace std; const ll MAXN = 2e9 + 2; const ll SIZE = 1e5 + 2; const ll mod = 1e9 + 7; bool cmp(pair<string, int> a, pair<string, int> b) { if (a.first < b.first) return true; else if (a.first == b.first) { return a.second > b.second; } } void solve() { int n; cin >> n; vector<pair<string, int>> v; map<pair<string, int>, int> mapp; ; for (int i = 1; i <= n; i++) { string s; cin >> s; int a; cin >> a; v.push_back(mp(s, a)); mapp[v[i - 1]] = i; } sort(all(v), cmp); for (int i = 0; i < s(v); i++) { cout << mapp[v[i]] << endl; } } int main() { speedhack() // int it; cin >> it; int it = 1; do (it); return 0; }
// ROAD TO GREEN #include <algorithm> #include <bitset> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <vector> #define ll long long #define uint unsigned int #define ull unsigned ll #define mp make_pair #define pb push_back #define all(x) x.begin(), x.end() #define allr(x) x.rbegin(), x.rend() #define speedhack() \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define do(x) \ for (int i = 1; i <= x; i++) { \ solve(); \ } #define s(x) x.size() using namespace std; const ll MAXN = 2e9 + 2; const ll SIZE = 1e5 + 2; const ll mod = 1e9 + 7; bool cmp(pair<string, int> a, pair<string, int> b) { if (a.first < b.first) return true; else if (a.first == b.first) { return a.second > b.second; } else { return false; } } void solve() { int n; cin >> n; vector<pair<string, int>> v; map<pair<string, int>, int> mapp; ; for (int i = 1; i <= n; i++) { string s; cin >> s; int a; cin >> a; v.push_back(mp(s, a)); mapp[v[i - 1]] = i; } sort(all(v), cmp); for (int i = 0; i < s(v); i++) { cout << mapp[v[i]] << endl; } } int main() { speedhack() // int it; cin >> it; int it = 1; do (it); return 0; }
insert
40
40
40
42
0
p03031
C++
Runtime Error
#include <algorithm> #include <iostream> #include <tuple> #include <vector> using namespace std; int main() { int N, M; cin >> N >> M; vector<int> s(M); for (int i = 0; i < N; i++) { int k; cin >> k; for (int j = 0; j < k; j++) { int a; cin >> a; s[i] |= (1 << --a); } } vector<int> P(M); for (auto &p : P) cin >> p; int ans = 0; for (int b = 0; b < (1 << N); b++) { int ok = 1; for (int i = 0; i < M; i++) { int bb = b & s[i]; int cnt = 0; while (bb) { cnt += (1 & bb); bb >>= 1; } cnt = (cnt & 1); if (cnt != P[i]) ok = 0; } ans += ok; } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <tuple> #include <vector> using namespace std; int main() { int N, M; cin >> N >> M; vector<int> s(M); for (int i = 0; i < M; i++) { int k; cin >> k; for (int j = 0; j < k; j++) { int a; cin >> a; s[i] |= (1 << --a); } } vector<int> P(M); for (auto &p : P) cin >> p; int ans = 0; for (int b = 0; b < (1 << N); b++) { int ok = 1; for (int i = 0; i < M; i++) { int bb = b & s[i]; int cnt = 0; while (bb) { cnt += (1 & bb); bb >>= 1; } cnt = (cnt & 1); if (cnt != P[i]) ok = 0; } ans += ok; } cout << ans << endl; return 0; }
replace
10
11
10
11
0
p03031
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<int>> vv(m); for (int i = 0; i < m; i++) { int k; cin >> k; for (int j = 0; j < k; j++) { int h; cin >> h; vv[i].push_back(--h); } } vector<int> swi(m); for (auto &x : swi) cin >> x; int ret = 0; for (int i = 0; 1 << n; i++) { bool flag = true; for (int j = 0; j < m; j++) { int on = 0; for (const auto &x : vv[j]) { if (i >> x & 1) on++; } if (on % 2 != swi[j]) flag = false; } if (flag) ret++; } cout << ret << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<int>> vv(m); for (int i = 0; i < m; i++) { int k; cin >> k; for (int j = 0; j < k; j++) { int h; cin >> h; vv[i].push_back(--h); } } vector<int> swi(m); for (auto &x : swi) cin >> x; int ret = 0; for (int i = 0; i < 1 << n; i++) { bool flag = true; for (int j = 0; j < m; j++) { int on = 0; for (const auto &x : vv[j]) { if (i >> x & 1) on++; } if (on % 2 != swi[j]) flag = false; } if (flag) ret++; } cout << ret << endl; }
replace
21
22
21
22
TLE
p03031
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <stdio.h> #include <string> #include <vector> #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<vector<int>> vvi; typedef vector<int> vi; typedef vector<string> vs; typedef vector<vector<string>> vvs; typedef vector<ll> vll; typedef pair<int, int> pii; typedef queue<int> qi; typedef queue<string> qs; #define rep(i, n) for (int i = 0; i < (n); ++i) #define repp(i, a, b) for (int i = (a); i <= (b); i++) #define repm(i, a, b) for (int i = (a); i >= (b); i--) #define all(v) v.begin(), v.end() // sort( all(v) ) などと使える int n, m; vector<vector<int>> ks; vector<int> p; bool isOK(int bit) { bool res = true; rep(i, m) { int k_i = ks[i][0]; int s_cnt = 0; for (int j = 1; j <= k_i; j++) { int s = ks[i][j]; if (bit & (1 << s)) s_cnt++; } if (s_cnt % 2 != p[i]) res = false; } return res; } int main() { cin >> n >> m; ks.resize(m); rep(i, m) { int k_i; cin >> k_i; ks[i].resize(k_i); ks[i][0] = k_i; for (int j = 1; j <= k_i; j++) { int s_ij; cin >> s_ij; ks[i][j] = s_ij - 1; } } p.resize(m); rep(i, m) cin >> p[i]; int cnt = 0; for (int bit = 0; bit < (1 << n); bit++) { if (isOK(bit)) cnt++; } cout << cnt << endl; }
#include <algorithm> #include <bitset> #include <cmath> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <stdio.h> #include <string> #include <vector> #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<vector<int>> vvi; typedef vector<int> vi; typedef vector<string> vs; typedef vector<vector<string>> vvs; typedef vector<ll> vll; typedef pair<int, int> pii; typedef queue<int> qi; typedef queue<string> qs; #define rep(i, n) for (int i = 0; i < (n); ++i) #define repp(i, a, b) for (int i = (a); i <= (b); i++) #define repm(i, a, b) for (int i = (a); i >= (b); i--) #define all(v) v.begin(), v.end() // sort( all(v) ) などと使える int n, m; vector<vector<int>> ks; vector<int> p; bool isOK(int bit) { bool res = true; rep(i, m) { int k_i = ks[i][0]; int s_cnt = 0; for (int j = 1; j <= k_i; j++) { int s = ks[i][j]; if (bit & (1 << s)) s_cnt++; } if (s_cnt % 2 != p[i]) res = false; } return res; } int main() { cin >> n >> m; ks.resize(m); rep(i, m) { int k_i; cin >> k_i; ks[i].resize(k_i + 1); ks[i][0] = k_i; for (int j = 1; j <= k_i; j++) { int s_ij; cin >> s_ij; ks[i][j] = s_ij - 1; } } p.resize(m); rep(i, m) cin >> p[i]; int cnt = 0; for (int bit = 0; bit < (1 << n); bit++) { if (isOK(bit)) cnt++; } cout << cnt << endl; }
replace
71
72
71
72
0
p03031
C++
Runtime Error
#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 endl "\n" using ll = long long; using P = pair<int, int>; using mp = map<string, int>; const int MOD = 1e9 + 7; const int INF = 1001001001; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; vector<vector<int>> s(m); vector<int> P(m); rep(i, m) { int k; cin >> k; rep(j, k) { int x; cin >> x; x--; s[j].push_back(x); } } rep(i, m) { cin >> P[i]; } int ans = 0; for (int i = 0; i < (1 << n); ++i) { bool ok = true; rep(j, m) { int cnt = 0; for (auto &p : s[j]) { if ((i >> p) & 1) { cnt++; } } if (cnt % 2 != P[j]) { ok = false; } } if (ok) { ans++; } } cout << ans << endl; return 0; }
#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 endl "\n" using ll = long long; using P = pair<int, int>; using mp = map<string, int>; const int MOD = 1e9 + 7; const int INF = 1001001001; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; vector<vector<int>> s(m); vector<int> P(m); rep(i, m) { int k; cin >> k; rep(j, k) { int x; cin >> x; x--; s[i].push_back(x); } } rep(i, m) { cin >> P[i]; } int ans = 0; for (int i = 0; i < (1 << n); ++i) { bool ok = true; rep(j, m) { int cnt = 0; for (auto &p : s[j]) { if ((i >> p) & 1) { cnt++; } } if (cnt % 2 != P[j]) { ok = false; } } if (ok) { ans++; } } cout << ans << endl; return 0; }
replace
32
33
32
33
0
p03031
C++
Runtime Error
// auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2, // 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of // }; // for (int tmp = 0; tmp < (1 << ビット数); tmp++) { // bitset<ビット数> s(tmp); // // (ビット列sに対する処理) // } // sort(配列変数.begin(), 配列変数.end()); // do { // // 順列に対する処理 // } while (next_permutation(配列変数.begin(), 配列変数.end())); // const double PI = acos(-1); M_PI // cout << fixed << setprecision(10); #include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG / GCC環境下で[] による配列要素参照のエラーを出す #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() // sort(all(vec)); ,reverse(all(vec));etc int main() { int n, m; cin >> n >> m; vector<bitset<10>> vec(m); vector<int> k(m); vector<int> p(m); rep(i, m) { cin >> k.at(i); rep(j, k.at(i)) { int pos; cin >> pos; vec.at(i).set(pos, 1); } } // cout<<vec.at(0)<<vec.at(1)<<endl; rep(i, m) { cin >> p.at(i); } int sum = 0; for (int tmp = 0; tmp < (1 << n); tmp++) { bitset<10> cnt(tmp); rep(i, m) { int match = (vec.at(i) & cnt).count(); if ((match % 2) != p.at(i)) { goto SKIP; } } sum += 1; // cout<<"hit:"<<cnt<<endl; SKIP: int alias; // cout<<cnt<<endl; } cout << sum << endl; }
// auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2, // 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of // }; // for (int tmp = 0; tmp < (1 << ビット数); tmp++) { // bitset<ビット数> s(tmp); // // (ビット列sに対する処理) // } // sort(配列変数.begin(), 配列変数.end()); // do { // // 順列に対する処理 // } while (next_permutation(配列変数.begin(), 配列変数.end())); // const double PI = acos(-1); M_PI // cout << fixed << setprecision(10); #include <bits/stdc++.h> using namespace std; #define _GLIBCXX_DEBUG / GCC環境下で[] による配列要素参照のエラーを出す #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(v) v.begin(), v.end() // sort(all(vec)); ,reverse(all(vec));etc int main() { int n, m; cin >> n >> m; vector<bitset<10>> vec(m); vector<int> k(m); vector<int> p(m); rep(i, m) { cin >> k.at(i); rep(j, k.at(i)) { int pos; cin >> pos; vec.at(i).set(pos - 1, 1); } } // cout<<vec.at(0)<<vec.at(1)<<endl; rep(i, m) { cin >> p.at(i); } int sum = 0; for (int tmp = 0; tmp < (1 << n); tmp++) { bitset<10> cnt(tmp); rep(i, m) { int match = (vec.at(i) & cnt).count(); if ((match % 2) != p.at(i)) { goto SKIP; } } sum += 1; // cout<<"hit:"<<cnt<<endl; SKIP: int alias; // cout<<cnt<<endl; } cout << sum << endl; }
replace
30
31
30
31
0
p03031
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <vector> using ll = long long; int main() { int N, M; std::cin >> N >> M; // i番目のスイッチのつけられる電球の番号 std::vector<std::vector<int>> k(N); for (int i = 0; i < M; i++) { int p; std::cin >> p; for (int j = 0; j < p; j++) { int in; std::cin >> in; in--; k[in].emplace_back(i); } } std::vector<int> m(M); for (int i = 0; i < M; i++) { int p; std::cin >> p; if (p == 1) { m[i]++; } } int ans = 0; for (int i = 0; i < (1 << N); i++) { std::vector<int> cm(m); for (int j = 0; j < N; j++) { int l = (i >> j) & 1; if (l == 0) continue; for (int i = 0; i < k[j].size(); i++) { cm[k[l][i]]++; } } bool flag = true; for (int j = 0; j < M; j++) { if (cm[j] % 2 == 1) { flag = false; break; } } if (flag) { ans++; } } std::cout << ans << std::endl; return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <vector> using ll = long long; int main() { int N, M; std::cin >> N >> M; // i番目のスイッチのつけられる電球の番号 std::vector<std::vector<int>> k(N); for (int i = 0; i < M; i++) { int p; std::cin >> p; for (int j = 0; j < p; j++) { int in; std::cin >> in; in--; k[in].emplace_back(i); } } std::vector<int> m(M); for (int i = 0; i < M; i++) { int p; std::cin >> p; if (p == 1) { m[i]++; } } int ans = 0; for (int i = 0; i < (1 << N); i++) { std::vector<int> cm(m); for (int j = 0; j < N; j++) { int l = (i >> j) & 1; if (l == 0) continue; for (int i = 0; i < k[j].size(); i++) { cm[k[j][i]]++; } } bool flag = true; for (int j = 0; j < M; j++) { if (cm[j] % 2 == 1) { flag = false; break; } } if (flag) { ans++; } } std::cout << ans << std::endl; return 0; }
replace
50
51
50
51
0
p03031
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> P1; typedef pair<P, P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define mod 1000000007 #define fi first #define sc second #define rep(i, x) for (int i = 0; i < x; i++) #define repn(i, x) for (int i = 1; i <= x; i++) #define SORT(x) sort(x.begin(), x.end()) #define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end()) #define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin()) #define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin()) int main() { ll N, M; cin >> N >> M; vector<vector<ll>> s(M); vector<ll> p; vector<ll> K; ll i, j, k, l; ll ans = 0; rep(i, M) { ll a; cin >> a; K.pb(a); rep(j, a) { cin >> s[i][j]; s[i][j]--; } } rep(i, M) { ll b; cin >> b; p.pb(b); } rep(i, 1 << N) { bool ok = true; rep(j, M) { int cnt = 0; rep(k, K[j]) { if ((i >> s[j][k]) & 1) cnt++; } if (cnt % 2 != p.at(j)) ok = false; } if (ok) ans++; } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<int, P> P1; typedef pair<P, P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define mod 1000000007 #define fi first #define sc second #define rep(i, x) for (int i = 0; i < x; i++) #define repn(i, x) for (int i = 1; i <= x; i++) #define SORT(x) sort(x.begin(), x.end()) #define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end()) #define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin()) #define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin()) int main() { ll N, M; cin >> N >> M; vector<vector<ll>> s(M); vector<ll> p; vector<ll> K; ll i, j, k, l; ll ans = 0; rep(i, M) { ll a; cin >> a; K.pb(a); rep(j, a) { ll c; cin >> c; c--; s[i].pb(c); } } rep(i, M) { ll b; cin >> b; p.pb(b); } rep(i, 1 << N) { bool ok = true; rep(j, M) { int cnt = 0; rep(k, K[j]) { if ((i >> s[j][k]) & 1) cnt++; } if (cnt % 2 != p.at(j)) ok = false; } if (ok) ans++; } cout << ans << endl; }
replace
37
39
37
41
-11
p03031
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n, m; cin >> n >> m; vector<vector<int>> s(m); for (int i = 0; i < n; i++) { int k; cin >> k; for (int j = 0; j < k; j++) { int temp; cin >> temp; temp--; s[i].push_back(temp); } } vector<int> p(m); for (int i = 0; i < m; i++) cin >> p[i]; ll ans = 0; for (int bit = 0; bit < (1 << n); bit++) { bool flg = true; for (int i = 0; i < m; i++) { int cnt = 0; for (int v : s[i]) { if (bit & (1 << v)) cnt++; } if (cnt % 2 != p[i]) flg = false; } if (flg) ans++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n, m; cin >> n >> m; vector<vector<int>> s(m); for (int i = 0; i < m; i++) { int k; cin >> k; for (int j = 0; j < k; j++) { int temp; cin >> temp; temp--; s[i].push_back(temp); } } vector<int> p(m); for (int i = 0; i < m; i++) cin >> p[i]; ll ans = 0; for (int bit = 0; bit < (1 << n); bit++) { bool flg = true; for (int i = 0; i < m; i++) { int cnt = 0; for (int v : s[i]) { if (bit & (1 << v)) cnt++; } if (cnt % 2 != p[i]) flg = false; } if (flg) ans++; } cout << ans << endl; return 0; }
replace
8
9
8
9
0