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
p03148
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < int(n); i++) #define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--) #define reps(i, n) for (int i = 1; i <= int(n); i++) #define rreps(i, n) for (int i = int(n); i >= 1; i--) #define repi(i, a, b) for (int i = (a); i < int(b); i++) #define all(a) (a).begin(), (a).end() #define bit(b) (1ll << (b)) #define uniq(v) (v).erase(unique(all(v)), (v).end()) using namespace std; using i32 = int; using i64 = long long; using f80 = long double; using vi32 = vector<i32>; using vi64 = vector<i64>; using vf80 = vector<f80>; using vstr = vector<string>; void ioinit() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); } i64 gcd(i64 a, i64 b) { if (a % b == 0) return b; else return gcd(b, a % b); } i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; } template <class T> bool amax(T &x, T y) { if (x < y) { x = y; return 1; } else return 0; } template <class T> bool amin(T &x, T y) { if (x > y) { x = y; return 1; } else return 0; } template <class T> i64 lbi(vector<T> &v, T e) { return lower_bound(all(v), e) - v.begin(); } template <class T> i64 ubi(vector<T> &v, T e) { return upper_bound(all(v), e) - v.begin(); } int main() { ioinit(); int n, k; cin >> n >> k; vector<int> v0, v1; { vector<vector<int>> v(100010); rep(i, n) { int t, d; cin >> t >> d; v[t].push_back(d); } rep(i, 100001) { if (v[i].size() == 0) continue; sort(all(v[i])); v1.push_back(v[i][v[i].size() - 1]); rep(j, v[i].size() - 1) v0.push_back(v[i][j]); } } sort(all(v0)); reverse(all(v0)); sort(all(v1)); reverse(all(v1)); { i64 ans = 0, sum = 0; i32 cnt = 0, kind = 0; rep(i, min(k, (int)v0.size())) { sum += v0[i]; cnt++; } rep(i, max(0, k - cnt)) { sum += v1[i]; kind++; } amax(ans, sum + kind * kind); while (cnt > 0) { sum -= v0[--cnt]; sum += v1[kind++]; amax(ans, sum + (i64)kind * kind); } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < int(n); i++) #define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--) #define reps(i, n) for (int i = 1; i <= int(n); i++) #define rreps(i, n) for (int i = int(n); i >= 1; i--) #define repi(i, a, b) for (int i = (a); i < int(b); i++) #define all(a) (a).begin(), (a).end() #define bit(b) (1ll << (b)) #define uniq(v) (v).erase(unique(all(v)), (v).end()) using namespace std; using i32 = int; using i64 = long long; using f80 = long double; using vi32 = vector<i32>; using vi64 = vector<i64>; using vf80 = vector<f80>; using vstr = vector<string>; void ioinit() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); } i64 gcd(i64 a, i64 b) { if (a % b == 0) return b; else return gcd(b, a % b); } i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; } template <class T> bool amax(T &x, T y) { if (x < y) { x = y; return 1; } else return 0; } template <class T> bool amin(T &x, T y) { if (x > y) { x = y; return 1; } else return 0; } template <class T> i64 lbi(vector<T> &v, T e) { return lower_bound(all(v), e) - v.begin(); } template <class T> i64 ubi(vector<T> &v, T e) { return upper_bound(all(v), e) - v.begin(); } int main() { ioinit(); int n, k; cin >> n >> k; vector<int> v0, v1; { vector<vector<int>> v(100010); rep(i, n) { int t, d; cin >> t >> d; v[t].push_back(d); } rep(i, 100001) { if (v[i].size() == 0) continue; sort(all(v[i])); v1.push_back(v[i][v[i].size() - 1]); rep(j, v[i].size() - 1) v0.push_back(v[i][j]); } } sort(all(v0)); reverse(all(v0)); sort(all(v1)); reverse(all(v1)); { i64 ans = 0, sum = 0; i32 cnt = 0, kind = 0; rep(i, min(k, (int)v0.size())) { sum += v0[i]; cnt++; } rep(i, max(0, k - cnt)) { sum += v1[i]; kind++; } amax(ans, sum + (i64)kind * kind); while (cnt > 0 && kind < v1.size()) { sum -= v0[--cnt]; sum += v1[kind++]; amax(ans, sum + (i64)kind * kind); } cout << ans << endl; } return 0; }
replace
88
90
88
90
0
p03148
C++
Runtime Error
#include <bits/stdc++.h> #define int long long using namespace std; const int MOD = 1e9 + 7; signed main() { int N, K; cin >> N >> K; typedef pair<int, int> P; std::vector<P> v(N); for (int i = 0; i < N; i++) { int a, b; cin >> a >> b; a--; v[i] = P(b, a); } sort(v.rbegin(), v.rend()); int ans = 0; std::vector<int> usedc(N, 0); stack<int> sta; int res = 0; int color = 0; for (int i = 0; i < K; i++) { res += v[i].first; if (usedc[v[i].second]++ == 0) color++; else sta.push(v[i].first); } ans = res + color * color; for (int i = K; i < N; i++) { if (usedc[v[i].second]++) continue; int a = sta.top(); sta.pop(); res -= a; res += v[i].first; color++; ans = max(ans, res + color * color); } cout << ans << endl; }
#include <bits/stdc++.h> #define int long long using namespace std; const int MOD = 1e9 + 7; signed main() { int N, K; cin >> N >> K; typedef pair<int, int> P; std::vector<P> v(N); for (int i = 0; i < N; i++) { int a, b; cin >> a >> b; a--; v[i] = P(b, a); } sort(v.rbegin(), v.rend()); int ans = 0; std::vector<int> usedc(N, 0); stack<int> sta; int res = 0; int color = 0; for (int i = 0; i < K; i++) { res += v[i].first; if (usedc[v[i].second]++ == 0) color++; else sta.push(v[i].first); } ans = res + color * color; for (int i = K; i < N && sta.size(); i++) { if (usedc[v[i].second]++) continue; int a = sta.top(); sta.pop(); res -= a; res += v[i].first; color++; ans = max(ans, res + color * color); } cout << ans << endl; }
replace
30
31
30
31
0
p03148
Python
Runtime Error
from collections import defaultdict from heapq import heappush, heappop n, k = map(int, input().split()) dic = defaultdict(list) for _ in range(n): t, d = map(int, input().split()) dic[t].append(d) maxs = [] for key in dic: dic[key].sort() maxs.append((dic[key].pop(), key)) maxs.sort(reverse=True) queSize = 0 que = [] queScore = 0 defaultScore = 0 cnt = 0 ans = 0 for v, key in maxs: defaultScore += v + cnt * 2 + 1 cnt += 1 for add in dic[key]: heappush(que, add) queSize += 1 queScore += add while queSize > k - cnt: queScore -= heappop(que) queSize -= 1 ans = max(ans, defaultScore + queScore) print(ans)
from collections import defaultdict from heapq import heappush, heappop n, k = map(int, input().split()) dic = defaultdict(list) for _ in range(n): t, d = map(int, input().split()) dic[t].append(d) maxs = [] for key in dic: dic[key].sort() maxs.append((dic[key].pop(), key)) maxs.sort(reverse=True) queSize = 0 que = [] queScore = 0 defaultScore = 0 cnt = 0 ans = 0 for v, key in maxs: defaultScore += v + cnt * 2 + 1 cnt += 1 if cnt >= k: ans = max(ans, defaultScore) break for add in dic[key]: heappush(que, add) queSize += 1 queScore += add while queSize > k - cnt: queScore -= heappop(que) queSize -= 1 ans = max(ans, defaultScore + queScore) print(ans)
insert
25
25
25
28
0
p03148
Python
Runtime Error
from collections import deque def main(): N, K = map(int, input().split()) sushis = [None] * N for i in range(N): t, d = map(int, input().split()) sushis[i] = (t, d) sushis.sort(key=lambda a: (-a[1], a[0])) tmp = 0 types = set() stack = deque() ans = 0 for i in range(len(sushis)): t, d = sushis[i] if i < K: if t in types: stack.append(d) types.add(t) tmp += d else: if t not in types: types.add(t) tmp += d tmp -= stack.pop() ans = max(ans, tmp + len(types) ** 2) print(ans) if __name__ == "__main__": main()
from collections import deque def main(): N, K = map(int, input().split()) sushis = [None] * N for i in range(N): t, d = map(int, input().split()) sushis[i] = (t, d) sushis.sort(key=lambda a: (-a[1], a[0])) tmp = 0 types = set() stack = deque() ans = 0 for i in range(len(sushis)): t, d = sushis[i] if i < K: if t in types: stack.append(d) types.add(t) tmp += d else: if t not in types and len(stack): types.add(t) tmp += d tmp -= stack.pop() ans = max(ans, tmp + len(types) ** 2) print(ans) if __name__ == "__main__": main()
replace
22
23
22
23
0
p03148
Python
Runtime Error
import heapq INF = float("inf") n, k = map(int, input().split()) sushi = {} for _ in range(n): t, d = map(int, input().split()) if t not in sushi: sushi[t] = [] sushi[t].append(d) for s in sushi.values(): s.sort(reverse=True) eat_counts = {s: 0 for s in sushi.keys()} # まだ食べてないやつ news = [] # リピート repeats = [] # 食べた履歴 eats = [] # 各寿司の一番おいしいやつを heap へ for name, deli_li in sushi.items(): # (-おいしさ, name) heapq.heappush(news, (-deli_li[0], name)) sum_deli = 0 variety = 0 for _ in range(k): # おいしいやつから食べる if news and (not repeats or news[0] <= repeats[0]): deli, name = heapq.heappop(news) variety += 1 else: deli, name = heapq.heappop(repeats) sum_deli += -deli eat_counts[name] += 1 heapq.heappush(eats, (-deli, name)) if eat_counts[name] < len(sushi[name]): heapq.heappush(repeats, (-sushi[name][eat_counts[name]], name)) # 美味しいやつから順に食べた # 種類増やしたらもっと得点上がるか確かめる ans = sum_deli + variety**2 while True: if not news: break # 食べたやつポイント小さいやつから置き換えたい ate_min_deli, ate_min_name = heapq.heappop(eats) eat_counts[ate_min_name] -= 1 if eat_counts[ate_min_name] <= 0: # これは種類減っちゃうからだめ continue sum_deli -= ate_min_deli deli, name = heapq.heappop(news) variety += 1 sum_deli += -deli eat_counts[name] += 1 ans = max(ans, sum_deli + variety**2) print(ans)
import heapq INF = float("inf") n, k = map(int, input().split()) sushi = {} for _ in range(n): t, d = map(int, input().split()) if t not in sushi: sushi[t] = [] sushi[t].append(d) for s in sushi.values(): s.sort(reverse=True) eat_counts = {s: 0 for s in sushi.keys()} # まだ食べてないやつ news = [] # リピート repeats = [] # 食べた履歴 eats = [] # 各寿司の一番おいしいやつを heap へ for name, deli_li in sushi.items(): # (-おいしさ, name) heapq.heappush(news, (-deli_li[0], name)) sum_deli = 0 variety = 0 for _ in range(k): # おいしいやつから食べる if news and (not repeats or news[0] <= repeats[0]): deli, name = heapq.heappop(news) variety += 1 else: deli, name = heapq.heappop(repeats) sum_deli += -deli eat_counts[name] += 1 heapq.heappush(eats, (-deli, name)) if eat_counts[name] < len(sushi[name]): heapq.heappush(repeats, (-sushi[name][eat_counts[name]], name)) # 美味しいやつから順に食べた # 種類増やしたらもっと得点上がるか確かめる ans = sum_deli + variety**2 while True: if not news or not eats: break # 食べたやつポイント小さいやつから置き換えたい ate_min_deli, ate_min_name = heapq.heappop(eats) eat_counts[ate_min_name] -= 1 if eat_counts[ate_min_name] <= 0: # これは種類減っちゃうからだめ continue sum_deli -= ate_min_deli deli, name = heapq.heappop(news) variety += 1 sum_deli += -deli eat_counts[name] += 1 ans = max(ans, sum_deli + variety**2) print(ans)
replace
50
51
50
51
0
p03148
Python
Runtime Error
N, K = map(int, input().split()) umai = {} mazui = [] for _ in range(N): t, d = map(int, input().split()) if t not in umai: umai[t] = d else: tmp = umai[t] if tmp < d: umai[t] = d mazui.append((t, tmp)) else: mazui.append((t, d)) umai = sorted(umai.items(), key=lambda x: -x[1]) mazui = sorted(mazui, key=lambda x: -x[1]) umai_len = len(umai) mazui_len = len(mazui) acc_umai = [0 for _ in range(umai_len)] acc_umai[0] = umai[0][1] for i in range(umai_len - 1): acc_umai[i + 1] = acc_umai[i] + umai[i + 1][1] acc_mazui = [0 for _ in range(mazui_len)] acc_mazui[0] = mazui[0][1] for i in range(mazui_len - 1): acc_mazui[i + 1] = acc_mazui[i] + mazui[i + 1][1] acc_mazui.insert(0, 0) ans = [] for i in range(1, K + 1): if umai_len < i or mazui_len < K - i: continue ans.append(acc_umai[i - 1] + acc_mazui[K - i] + i**2) print(max(ans))
N, K = map(int, input().split()) umai = {} mazui = [] for _ in range(N): t, d = map(int, input().split()) if t not in umai: umai[t] = d else: tmp = umai[t] if tmp < d: umai[t] = d mazui.append((t, tmp)) else: mazui.append((t, d)) umai = sorted(umai.items(), key=lambda x: -x[1]) mazui = sorted(mazui, key=lambda x: -x[1]) umai_len = len(umai) mazui_len = len(mazui) acc_umai = [0 for _ in range(umai_len)] acc_umai[0] = umai[0][1] for i in range(umai_len - 1): acc_umai[i + 1] = acc_umai[i] + umai[i + 1][1] acc_mazui = [0 for _ in range(mazui_len)] if mazui_len > 0: acc_mazui[0] = mazui[0][1] for i in range(mazui_len - 1): acc_mazui[i + 1] = acc_mazui[i] + mazui[i + 1][1] acc_mazui.insert(0, 0) ans = [] for i in range(1, K + 1): if umai_len < i or mazui_len < K - i: continue ans.append(acc_umai[i - 1] + acc_mazui[K - i] + i**2) print(max(ans))
replace
28
31
28
32
0
p03148
Python
Runtime Error
def main(): n, k = map(int, input().split()) sushi = [list(map(int, input().split())) for _ in range(n)] sushi = sorted(sushi, key=lambda x: x[1], reverse=True) first = set() second = [] point = 0 for s in sushi[:k]: if s[0] not in first: first.add(s[0]) else: second.append(s) point += s[1] point += len(first) ** 2 ans = point for s in sushi[k:]: if s[0] not in first: point = ( point + s[1] - second.pop()[1] + (len(first) + 1) ** 2 - len(first) ** 2 ) first.add(s[0]) ans = max(ans, point) print(ans) main()
def main(): n, k = map(int, input().split()) sushi = [list(map(int, input().split())) for _ in range(n)] sushi = sorted(sushi, key=lambda x: x[1], reverse=True) first = set() second = [] point = 0 for s in sushi[:k]: if s[0] not in first: first.add(s[0]) else: second.append(s) point += s[1] point += len(first) ** 2 ans = point for s in sushi[k:]: if len(second) == 0: break if s[0] not in first: point = ( point + s[1] - second.pop()[1] + (len(first) + 1) ** 2 - len(first) ** 2 ) first.add(s[0]) ans = max(ans, point) print(ans) main()
insert
18
18
18
20
0
p03148
C++
Runtime Error
//{{{ #include <algorithm> #include <cmath> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <sys/time.h> #include <unordered_map> #include <unordered_set> #include <vector> using ll = long long; enum : int { M = (int)1e9 + 7 }; enum : ll { MLL = (ll)1e18L + 9 }; using namespace std; #ifdef LOCAL #include "rprint2.hpp" #else #define FUNC(name) \ template <ostream &out = cout, class... T> void name(T &&...) {} FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu); #endif template <class S, class T> istream &operator>>(istream &in, pair<S, T> &p) { return in >> p.first >> p.second; } template <class T> istream &operator>>(istream &in, vector<T> &v) { for (auto &e : v) { in >> e; } return in; } //}}} int main() { cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n >> k; vector<pair<int, int>> dts(n); for (int i = 0; i < n; i++) { int t, d; cin >> t >> d; dts[i] = {d, t}; } sort(dts.rbegin(), dts.rend()); set<int> eaten; ll acc = 0; priority_queue<int, vector<int>, greater<int>> pq; for (int i = 0; i < k; i++) { acc += dts[i].first; if (eaten.count(dts[i].second)) { pq.push(dts[i].first); } else { eaten.insert(dts[i].second); } } ll ans = acc + eaten.size() * eaten.size(); for (int i = k; i < n; i++) { printde(eaten); int t = dts[i].second; if (!eaten.count(t)) { eaten.insert(t); acc -= pq.top(); pq.pop(); acc += dts[i].first; ll cand = acc + ll(eaten.size() * eaten.size()); printde(ans, cand); ans = max(ans, cand); } } cout << ans << '\n'; }
//{{{ #include <algorithm> #include <cmath> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <sys/time.h> #include <unordered_map> #include <unordered_set> #include <vector> using ll = long long; enum : int { M = (int)1e9 + 7 }; enum : ll { MLL = (ll)1e18L + 9 }; using namespace std; #ifdef LOCAL #include "rprint2.hpp" #else #define FUNC(name) \ template <ostream &out = cout, class... T> void name(T &&...) {} FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu); #endif template <class S, class T> istream &operator>>(istream &in, pair<S, T> &p) { return in >> p.first >> p.second; } template <class T> istream &operator>>(istream &in, vector<T> &v) { for (auto &e : v) { in >> e; } return in; } //}}} int main() { cin.tie(0); ios::sync_with_stdio(false); int n, k; cin >> n >> k; vector<pair<int, int>> dts(n); for (int i = 0; i < n; i++) { int t, d; cin >> t >> d; dts[i] = {d, t}; } sort(dts.rbegin(), dts.rend()); set<int> eaten; ll acc = 0; priority_queue<int, vector<int>, greater<int>> pq; for (int i = 0; i < k; i++) { acc += dts[i].first; if (eaten.count(dts[i].second)) { pq.push(dts[i].first); } else { eaten.insert(dts[i].second); } } ll ans = acc + eaten.size() * eaten.size(); for (int i = k; i < n; i++) { if (pq.empty()) { break; } printde(eaten); int t = dts[i].second; if (!eaten.count(t)) { eaten.insert(t); acc -= pq.top(); pq.pop(); acc += dts[i].first; ll cand = acc + ll(eaten.size() * eaten.size()); printde(ans, cand); ans = max(ans, cand); } } cout << ans << '\n'; }
insert
65
65
65
68
0
p03148
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string.h> #include <string> #include <vector> // output #define SPBR(w, n) std::cout << (w + 1 == n ? '\n' : ' '); #define YES cout << "YES" << endl #define Yes cout << "Yes" << endl #define NO cout << "NO" << endl #define No cout << "No" << endl // utility #define ALL(i) (i).begin(), (i).end() #define FOR(i, a, n) for (int i = (a); i < (n); ++i) #define RFOR(i, a, n) for (int i = (n)-1; i >= (a); --i) #define REP(i, n) for (int i = 0; i < int(n); ++i) #define RREP(i, n) for (int i = int(n) - 1; i >= 0; --i) #define IN(a, x, b) (a <= x && x < b) #define OUT(a, x, b) (x < a || b <= x) 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; } // type/const #define int ll using ll = long long; using ull = unsigned long long; using ld = long double; const int MOD = 1000000007; /* const int MOD = 998244353; */ const int INF = 1e18; const double PI = acos(-1); using namespace std; struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } INIT; signed main() { int N, K; cin >> N >> K; vector<int> t(N), d(N); REP(i, N) { cin >> t[i] >> d[i]; t[i]--; } priority_queue<int> q; priority_queue<int, vector<int>, greater<int>> eat; vector<pair<int, int>> MAX(N, {-INF, -1}); vector<bool> used(N, false); int ret = 0; REP(i, N) { if (MAX[t[i]].first < d[i]) { if (MAX[t[i]].second != -1) used[MAX[t[i]].second] = false; if (MAX[t[i]].first != -INF) ret -= MAX[t[i]].first; ret += d[i]; MAX[t[i]] = {d[i], i}; used[MAX[t[i]].second] = true; } } int cnt = 0; REP(i, N) { if (used[i]) { cnt++; eat.push(d[i]); } else q.push(d[i]); } while ((int)eat.size() > K) { cnt--; ret -= eat.top(); eat.pop(); } REP(i, K - eat.size()) { ret += q.top(); q.pop(); } int ans = ret + cnt * cnt; while (!eat.empty()) { cnt--; ret -= eat.top(); eat.pop(); ret += q.top(); q.pop(); chmax(ans, ret + cnt * cnt); } cout << ans << "\n"; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string.h> #include <string> #include <vector> // output #define SPBR(w, n) std::cout << (w + 1 == n ? '\n' : ' '); #define YES cout << "YES" << endl #define Yes cout << "Yes" << endl #define NO cout << "NO" << endl #define No cout << "No" << endl // utility #define ALL(i) (i).begin(), (i).end() #define FOR(i, a, n) for (int i = (a); i < (n); ++i) #define RFOR(i, a, n) for (int i = (n)-1; i >= (a); --i) #define REP(i, n) for (int i = 0; i < int(n); ++i) #define RREP(i, n) for (int i = int(n) - 1; i >= 0; --i) #define IN(a, x, b) (a <= x && x < b) #define OUT(a, x, b) (x < a || b <= x) 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; } // type/const #define int ll using ll = long long; using ull = unsigned long long; using ld = long double; const int MOD = 1000000007; /* const int MOD = 998244353; */ const int INF = 1e18; const double PI = acos(-1); using namespace std; struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } INIT; signed main() { int N, K; cin >> N >> K; vector<int> t(N), d(N); REP(i, N) { cin >> t[i] >> d[i]; t[i]--; } priority_queue<int> q; priority_queue<int, vector<int>, greater<int>> eat; vector<pair<int, int>> MAX(N, {-INF, -1}); vector<bool> used(N, false); int ret = 0; REP(i, N) { if (MAX[t[i]].first < d[i]) { if (MAX[t[i]].second != -1) used[MAX[t[i]].second] = false; if (MAX[t[i]].first != -INF) ret -= MAX[t[i]].first; ret += d[i]; MAX[t[i]] = {d[i], i}; used[MAX[t[i]].second] = true; } } int cnt = 0; REP(i, N) { if (used[i]) { cnt++; eat.push(d[i]); } else q.push(d[i]); } while ((int)eat.size() > K) { cnt--; ret -= eat.top(); eat.pop(); } REP(i, K - eat.size()) { ret += q.top(); q.pop(); } int ans = ret + cnt * cnt; while (!eat.empty() && !q.empty()) { cnt--; ret -= eat.top(); eat.pop(); ret += q.top(); q.pop(); chmax(ans, ret + cnt * cnt); } cout << ans << "\n"; return 0; }
replace
112
113
112
113
0
p03148
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n, k; cin >> n >> k; vector<vector<int>> v(n); for (int i = 0; i < n; i++) { int t, d; cin >> t >> d; v[t - 1].push_back(d); } vector<ll> a{0}, b{0}; for (auto &e : v) { if (e.empty()) { continue; } sort(begin(e), end(e)); a.push_back(e.back()); for (auto it = begin(e); it != end(e) - 1; it++) { b.push_back(*it); } } sort(rbegin(a), rend(a) - 1); sort(rbegin(b), rend(b) - 1); for (int i = 0; i + 1 < a.size(); i++) { a[i + 1] += a[i]; } for (int i = 0; i + 1 < b.size(); i++) { b[i + 1] += b[i]; } ll r = 0; for (ll x = 1; x <= min(k, (int)a.size()); x++) { r = max(r, a[x] + b[k - x] + x * x); } cout << r << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int n, k; cin >> n >> k; vector<vector<int>> v(n); for (int i = 0; i < n; i++) { int t, d; cin >> t >> d; v[t - 1].push_back(d); } vector<ll> a{0}, b{0}; for (auto &e : v) { if (e.empty()) { continue; } sort(begin(e), end(e)); a.push_back(e.back()); for (auto it = begin(e); it != end(e) - 1; it++) { b.push_back(*it); } } sort(rbegin(a), rend(a) - 1); sort(rbegin(b), rend(b) - 1); for (int i = 0; i + 1 < a.size(); i++) { a[i + 1] += a[i]; } for (int i = 0; i + 1 < b.size(); i++) { b[i + 1] += b[i]; } ll r = 0; for (ll x = max(1, k - ((int)b.size() - 1)); x <= min(k, (int)a.size() - 1); x++) { r = max(r, a[x] + b[k - x] + x * x); } cout << r << endl; }
replace
33
34
33
35
0
p03148
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ft first #define sc second #define lb lower_bound #define ub upper_bound #define pb push_back #define pt(sth) cout << sth << "\n" #define chmax(a, b) \ { \ if (a < b) \ a = b; \ } #define chmin(a, b) \ { \ if (a > b) \ a = b; \ } #define moC(a, s, b) (a) = ((a)s(b) + MOD) % MOD using namespace std; typedef long long ll; typedef pair<ll, ll> P; static const ll INF = 1e18; static const ll MAX = 1e5 + 7; static const ll MOD = 1e9 + 7; ll max(ll a, ll b) { return a > b ? a : b; } ll min(ll a, ll b) { return a < b ? a : b; } int main(void) { ll N, K; cin >> N >> K; ll i; vector<P> su(N); ll ty = 0; ll cnt[MAX] = {}; for (i = 0; i < N; i++) { cin >> su[i].sc >> su[i].ft; su[i].sc--; } sort(su.rbegin(), su.rend()); ll ans = 0; ll t = 0; priority_queue<P> q; for (i = 0; i < K; i++) { q.push({-su[i].ft, su[i].sc}); t += su[i].ft; cnt[su[i].sc]++; if (cnt[su[i].sc] == 1) ty++; } ans = t; ans += ty * ty; for (i = K; i < N; i++) { while (1) { P f = q.top(); q.pop(); if (cnt[f.sc] > 1) { t -= -f.ft; cnt[f.sc]--; q.push({-su[i].ft, su[i].sc}); t += su[i].ft; cnt[su[i].sc]++; if (cnt[su[i].sc] == 1) ty++; chmax(ans, t + ty * ty); break; } } } pt(ans); }
#include <bits/stdc++.h> #define ft first #define sc second #define lb lower_bound #define ub upper_bound #define pb push_back #define pt(sth) cout << sth << "\n" #define chmax(a, b) \ { \ if (a < b) \ a = b; \ } #define chmin(a, b) \ { \ if (a > b) \ a = b; \ } #define moC(a, s, b) (a) = ((a)s(b) + MOD) % MOD using namespace std; typedef long long ll; typedef pair<ll, ll> P; static const ll INF = 1e18; static const ll MAX = 1e5 + 7; static const ll MOD = 1e9 + 7; ll max(ll a, ll b) { return a > b ? a : b; } ll min(ll a, ll b) { return a < b ? a : b; } int main(void) { ll N, K; cin >> N >> K; ll i; vector<P> su(N); ll ty = 0; ll cnt[MAX] = {}; for (i = 0; i < N; i++) { cin >> su[i].sc >> su[i].ft; su[i].sc--; } sort(su.rbegin(), su.rend()); ll ans = 0; ll t = 0; priority_queue<P> q; for (i = 0; i < K; i++) { q.push({-su[i].ft, su[i].sc}); t += su[i].ft; cnt[su[i].sc]++; if (cnt[su[i].sc] == 1) ty++; } ans = t; ans += ty * ty; for (i = K; i < N; i++) { while (q.size()) { P f = q.top(); q.pop(); if (cnt[f.sc] > 1) { t -= -f.ft; cnt[f.sc]--; q.push({-su[i].ft, su[i].sc}); t += su[i].ft; cnt[su[i].sc]++; if (cnt[su[i].sc] == 1) ty++; chmax(ans, t + ty * ty); break; } } } pt(ans); }
replace
55
57
55
56
TLE
p03148
C++
Runtime Error
#include <algorithm> #include <assert.h> #include <cstring> #include <iterator> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <stdlib.h> #include <string> #include <vector> #pragma warning(disable : 4996) typedef long long ll; #define MIN(a, b) ((a) > (b) ? (b) : (a)) #define MAX(a, b) ((a) < (b) ? (b) : (a)) #define LINF 9223300000000000000 #define INF 2140000000 const long long MOD = 1000000007; using namespace std; int main(int argc, char *argv[]) { int n, k; scanf("%d%d", &n, &k); vector<pair<int, int>> z; int i; for (i = 0; i < n; i++) { int t, d; scanf("%d%d", &t, &d); z.push_back(make_pair(d, t)); } sort(z.rbegin(), z.rend()); vector<pair<int, int>> z0; set<int> kind; ll pts = 0; for (i = 0; i < k; i++) { pts += z[i].first; if (!kind.insert(z[i].second).second) { z0.push_back(z[i]); // can be deleted } } reverse(z0.begin(), z0.end()); ll val = pts + (ll)kind.size() * kind.size(); ll max = val; int id = 0; for (i = k; i < n; i++) { if (kind.insert(z[i].second).second) { pts += (z[i].first - z0[id].first); id++; val = pts + (ll)kind.size() * kind.size(); max = MAX(max, val); } if (id == z0.size()) { break; } } printf("%lld\n", max); return 0; }
#include <algorithm> #include <assert.h> #include <cstring> #include <iterator> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stdio.h> #include <stdlib.h> #include <string> #include <vector> #pragma warning(disable : 4996) typedef long long ll; #define MIN(a, b) ((a) > (b) ? (b) : (a)) #define MAX(a, b) ((a) < (b) ? (b) : (a)) #define LINF 9223300000000000000 #define INF 2140000000 const long long MOD = 1000000007; using namespace std; int main(int argc, char *argv[]) { int n, k; scanf("%d%d", &n, &k); vector<pair<int, int>> z; int i; for (i = 0; i < n; i++) { int t, d; scanf("%d%d", &t, &d); z.push_back(make_pair(d, t)); } sort(z.rbegin(), z.rend()); vector<pair<int, int>> z0; set<int> kind; ll pts = 0; for (i = 0; i < k; i++) { pts += z[i].first; if (!kind.insert(z[i].second).second) { z0.push_back(z[i]); // can be deleted } } reverse(z0.begin(), z0.end()); ll val = pts + (ll)kind.size() * kind.size(); ll max = val; if (z0.empty()) { printf("%lld\n", max); return 0; } int id = 0; for (i = k; i < n; i++) { if (kind.insert(z[i].second).second) { pts += (z[i].first - z0[id].first); id++; val = pts + (ll)kind.size() * kind.size(); max = MAX(max, val); } if (id == z0.size()) { break; } } printf("%lld\n", max); return 0; }
insert
49
49
49
53
0
p03148
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int N, K; cin >> N >> K; vector<ll> t(N), d(N); for (int i = 0; i < N; i++) { cin >> t[i] >> d[i]; t[i]--; } vector<pair<ll, int>> A(N); for (int i = 0; i < N; i++) { A[i] = make_pair(d[i], t[i]); } sort(A.begin(), A.end()); reverse(A.begin(), A.end()); ll x = 0, y = 0; vector<bool> used(N); priority_queue<ll, vector<ll>, greater<ll>> que; for (int i = 0; i < K; i++) { y += A[i].first; if (!used[A[i].second]) { x++; used[A[i].second] = true; } else { que.push(A[i].first); } } ll ans = y + x * x; for (int i = K; i < N; i++) { if (used[A[i].second]) continue; y -= que.top(); que.pop(); y += A[i].first; x++; used[A[i].second] = true; ans = max(ans, y + x * x); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int N, K; cin >> N >> K; vector<ll> t(N), d(N); for (int i = 0; i < N; i++) { cin >> t[i] >> d[i]; t[i]--; } vector<pair<ll, int>> A(N); for (int i = 0; i < N; i++) { A[i] = make_pair(d[i], t[i]); } sort(A.begin(), A.end()); reverse(A.begin(), A.end()); ll x = 0, y = 0; vector<bool> used(N); priority_queue<ll, vector<ll>, greater<ll>> que; for (int i = 0; i < K; i++) { y += A[i].first; if (!used[A[i].second]) { x++; used[A[i].second] = true; } else { que.push(A[i].first); } } ll ans = y + x * x; for (int i = K; i < N && !que.empty(); i++) { if (used[A[i].second]) continue; y -= que.top(); que.pop(); y += A[i].first; x++; used[A[i].second] = true; ans = max(ans, y + x * x); } cout << ans << endl; }
replace
32
33
32
33
0
p03148
C++
Runtime Error
#include <algorithm> #include <functional> #include <queue> #include <stdio.h> #include <vector> using namespace std; using ll = long long; using pii = pair<ll, ll>; ll n, k; pii s[100000]; vector<ll> u, v; int main() { scanf("%lld %lld", &n, &k); for (int i = 0; i < n; i++) scanf("%lld %lld", &s[i].first, &s[i].second); sort(s, s + n); for (int i = 0; i < n; i++) { if (n <= i + 1 || s[i].first != s[i + 1].first) u.emplace_back(s[i].second); else v.emplace_back(s[i].second); } sort(u.begin(), u.end(), greater<ll>()); sort(v.begin(), v.end(), greater<ll>()); priority_queue<ll> hoketu; while (k < u.size() + v.size()) { hoketu.emplace(v.back()); v.pop_back(); } ll max_r = 0, cur = 0; for (ll e : u) cur += e; for (ll e : v) cur += e; while (!u.empty()) { max_r = max(max_r, cur + ((ll)u.size()) * ((ll)u.size())); cur -= u.back(); hoketu.emplace(u.back()); u.pop_back(); cur += hoketu.top(); hoketu.pop(); } printf("%lld\n", max(max_r, cur)); }
#include <algorithm> #include <functional> #include <queue> #include <stdio.h> #include <vector> using namespace std; using ll = long long; using pii = pair<ll, ll>; ll n, k; pii s[100000]; vector<ll> u, v; int main() { scanf("%lld %lld", &n, &k); for (int i = 0; i < n; i++) scanf("%lld %lld", &s[i].first, &s[i].second); sort(s, s + n); for (int i = 0; i < n; i++) { if (n <= i + 1 || s[i].first != s[i + 1].first) u.emplace_back(s[i].second); else v.emplace_back(s[i].second); } sort(u.begin(), u.end(), greater<ll>()); sort(v.begin(), v.end(), greater<ll>()); priority_queue<ll> hoketu; while (k < u.size() + v.size()) { if (v.empty()) { hoketu.emplace(u.back()); u.pop_back(); } else { hoketu.emplace(v.back()); v.pop_back(); } } ll max_r = 0, cur = 0; for (ll e : u) cur += e; for (ll e : v) cur += e; while (!u.empty()) { max_r = max(max_r, cur + ((ll)u.size()) * ((ll)u.size())); cur -= u.back(); hoketu.emplace(u.back()); u.pop_back(); cur += hoketu.top(); hoketu.pop(); } printf("%lld\n", max(max_r, cur)); }
replace
27
29
27
34
0
p03148
C++
Runtime Error
#include <algorithm> #include <assert.h> #include <cmath> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using int64 = long long; using int128 = __int128; #define repeat(i, n) for (auto i = decltype(n)(); (i) < (n); (i)++) int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, K; cin >> N >> K; vector<int64> t(N), d(N); repeat(i, N) { cin >> t[i] >> d[i]; } vector<int> indices(N); iota(begin(indices), end(indices), 0); sort(begin(indices), end(indices), [&](int i, int j) { return d[i] > d[j]; }); using P = pair<int, int>; // (美味しさ, 種類) int64 x = 0, sum_d = 0; vector<int> counter(N, 0); priority_queue<P, vector<P>, greater<P>> pque; repeat(i, K) { int idx = indices[i]; sum_d += d[idx]; counter[t[idx]]++; if (counter[t[idx]] == 1) x++; else pque.push(P(d[idx], t[idx])); } int64 ans = sum_d + x * x; for (int i = K; i < N; i++) { int idx = indices[i]; if (!pque.empty() and counter[t[idx]] == 0) { sum_d -= pque.top().first; pque.pop(); sum_d += d[idx]; x++; counter[t[idx]]++; } ans = max(ans, sum_d + x * x); } cout << ans << endl; return 0; }
#include <algorithm> #include <assert.h> #include <cmath> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using int64 = long long; using int128 = __int128; #define repeat(i, n) for (auto i = decltype(n)(); (i) < (n); (i)++) int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, K; cin >> N >> K; vector<int64> t(N), d(N); repeat(i, N) { cin >> t[i] >> d[i]; t[i]--; } vector<int> indices(N); iota(begin(indices), end(indices), 0); sort(begin(indices), end(indices), [&](int i, int j) { return d[i] > d[j]; }); using P = pair<int, int>; // (美味しさ, 種類) int64 x = 0, sum_d = 0; vector<int> counter(N, 0); priority_queue<P, vector<P>, greater<P>> pque; repeat(i, K) { int idx = indices[i]; sum_d += d[idx]; counter[t[idx]]++; if (counter[t[idx]] == 1) x++; else pque.push(P(d[idx], t[idx])); } int64 ans = sum_d + x * x; for (int i = K; i < N; i++) { int idx = indices[i]; if (!pque.empty() and counter[t[idx]] == 0) { sum_d -= pque.top().first; pque.pop(); sum_d += d[idx]; x++; counter[t[idx]]++; } ans = max(ans, sum_d + x * x); } cout << ans << endl; return 0; }
replace
33
34
33
37
0
p03148
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int count_and_compress(vector<long long> &a) { vector<long long> b = a; sort(b.begin(), b.end()); b.erase(unique(b.begin(), b.end())); for (auto &e : a) { e = (lower_bound(b.begin(), b.end(), e) - b.begin()); } return b.size(); } int main() { int n, k; cin >> n >> k; vector<long long> t(n), d(n); for (int i = 0; i < n; i++) { cin >> t[i] >> d[i]; } int sz = count_and_compress(t); vector<vector<long long>> g(sz); for (int i = 0; i < n; i++) { g[t[i]].emplace_back(d[i]); } for (auto &v : g) { sort(v.begin(), v.end(), greater<long long>()); } vector<long long> f(1, 0), s(1, 0); for (int i = 0; i < sz; i++) { for (int j = 0; j < (int)g[i].size(); j++) { if (j == 0) f.emplace_back(g[i][j]); else s.emplace_back(g[i][j]); } } sort(f.begin() + 1, f.end(), greater<long long>()); sort(s.begin() + 1, s.end(), greater<long long>()); for (long long i = 1; i < (int)f.size(); i++) { f[i] += (2 * i - 1); } for (int i = 0; i + 1 < (int)f.size(); i++) { f[i + 1] += f[i]; } for (int i = 0; i + 1 < (int)s.size(); i++) { s[i + 1] += s[i]; } long long ans = 0; for (int i = 1; i <= k; i++) { int j = k - i; if (i < f.size() and j < s.size()) { long long res = f[i] + s[j]; ans = max(ans, res); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int count_and_compress(vector<long long> &a) { vector<long long> b = a; sort(b.begin(), b.end()); b.erase(unique(b.begin(), b.end()), b.end()); for (auto &e : a) { e = (lower_bound(b.begin(), b.end(), e) - b.begin()); } return b.size(); } int main() { int n, k; cin >> n >> k; vector<long long> t(n), d(n); for (int i = 0; i < n; i++) { cin >> t[i] >> d[i]; } int sz = count_and_compress(t); vector<vector<long long>> g(sz); for (int i = 0; i < n; i++) { g[t[i]].emplace_back(d[i]); } for (auto &v : g) { sort(v.begin(), v.end(), greater<long long>()); } vector<long long> f(1, 0), s(1, 0); for (int i = 0; i < sz; i++) { for (int j = 0; j < (int)g[i].size(); j++) { if (j == 0) f.emplace_back(g[i][j]); else s.emplace_back(g[i][j]); } } sort(f.begin() + 1, f.end(), greater<long long>()); sort(s.begin() + 1, s.end(), greater<long long>()); for (long long i = 1; i < (int)f.size(); i++) { f[i] += (2 * i - 1); } for (int i = 0; i + 1 < (int)f.size(); i++) { f[i + 1] += f[i]; } for (int i = 0; i + 1 < (int)s.size(); i++) { s[i + 1] += s[i]; } long long ans = 0; for (int i = 1; i <= k; i++) { int j = k - i; if (i < f.size() and j < s.size()) { long long res = f[i] + s[j]; ans = max(ans, res); } } cout << ans << endl; return 0; }
replace
6
7
6
7
0
p03148
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define REP(i, a, n) for (int i = (a); i < (int)(n); i++) #define rep(i, n) REP(i, 0, n) #define FOR(it, c) \ for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; struct ST { ll t, d; }; bool operator<(const ST &a, const ST &b) { return a.d > b.d; } int main() { int N, K; cin >> N >> K; vector<ST> v; rep(i, N) { ll t, d; cin >> t >> d; v.push_back((ST){t, d}); } sort(ALLOF(v)); ll sum = 0; map<ll, ll> mx, nx; vector<ll> w; vector<ST> w2; rep(i, N) { if (i < K) { sum += v[i].d; if (mx.count(v[i].t) > 0) w.push_back(v[i].d); else { mx[v[i].t] = v[i].d; } } else { if (mx.count(v[i].t) == 0 && nx.count(v[i].t) == 0) { nx[v[i].t] = v[i].d; w2.push_back(v[i]); } } } ll x = mx.size(); ll ret = sum + x * x; rep(i, w2.size()) { if (w.size() - 1 - i < 0) break; sum -= w[w.size() - 1 - i]; sum += w2[i].d; x++; ret = max(ret, sum + x * x); } cout << ret << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, a, n) for (int i = (a); i < (int)(n); i++) #define rep(i, n) REP(i, 0, n) #define FOR(it, c) \ for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it) #define ALLOF(c) (c).begin(), (c).end() typedef long long ll; typedef unsigned long long ull; struct ST { ll t, d; }; bool operator<(const ST &a, const ST &b) { return a.d > b.d; } int main() { int N, K; cin >> N >> K; vector<ST> v; rep(i, N) { ll t, d; cin >> t >> d; v.push_back((ST){t, d}); } sort(ALLOF(v)); ll sum = 0; map<ll, ll> mx, nx; vector<ll> w; vector<ST> w2; rep(i, N) { if (i < K) { sum += v[i].d; if (mx.count(v[i].t) > 0) w.push_back(v[i].d); else { mx[v[i].t] = v[i].d; } } else { if (mx.count(v[i].t) == 0 && nx.count(v[i].t) == 0) { nx[v[i].t] = v[i].d; w2.push_back(v[i]); } } } ll x = mx.size(); ll ret = sum + x * x; rep(i, w2.size()) { if (x >= K) break; if (w.size() - 1 - i < 0) break; sum -= w[w.size() - 1 - i]; sum += w2[i].d; x++; ret = max(ret, sum + x * x); } cout << ret << endl; return 0; }
insert
49
49
49
51
0
p03148
C++
Runtime Error
#include <algorithm> #include <cstdlib> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define repb(i, a, b) for (int i = a; i < b; i++) using namespace std; typedef pair<int, int> P; typedef long long int ll; const int INF = 1 << 30; int main() { int n, k; cin >> n >> k; vector<P> sushi(n); rep(i, n) { int t, d; cin >> t >> d; sushi[i] = P(d, --t); } sort(sushi.begin(), sushi.end(), greater<P>()); vector<bool> include(k, false); vector<int> selected; ll kind = 0LL; ll sum = 0LL; rep(i, k) { P p = sushi[i]; if (!include[p.second]) { include[p.second] = true; kind++; } else { selected.push_back(p.first); } sum += p.first; } sort(selected.begin(), selected.end(), greater<int>()); ll ans = sum + kind * kind; ll id = (ll)kind; while (!selected.empty() && id < n) { if (include[sushi[id].second]) { id++; continue; } include[sushi[id].second] = true; sum -= selected.back(); selected.pop_back(); sum += sushi[id].first; id++; kind++; ans = max(ans, sum + kind * kind); } cout << ans << endl; // system("read -n 1 -s -p \"Press any key to continue...\""); }
#include <algorithm> #include <cstdlib> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> #define rep(i, n) for (int i = 0; i < n; i++) #define repb(i, a, b) for (int i = a; i < b; i++) using namespace std; typedef pair<int, int> P; typedef long long int ll; const int INF = 1 << 30; int main() { int n, k; cin >> n >> k; vector<P> sushi(n); rep(i, n) { int t, d; cin >> t >> d; sushi[i] = P(d, --t); } sort(sushi.begin(), sushi.end(), greater<P>()); vector<bool> include(n, false); vector<int> selected; ll kind = 0LL; ll sum = 0LL; rep(i, k) { P p = sushi[i]; if (!include[p.second]) { include[p.second] = true; kind++; } else { selected.push_back(p.first); } sum += p.first; } sort(selected.begin(), selected.end(), greater<int>()); ll ans = sum + kind * kind; ll id = (ll)kind; while (!selected.empty() && id < n) { if (include[sushi[id].second]) { id++; continue; } include[sushi[id].second] = true; sum -= selected.back(); selected.pop_back(); sum += sushi[id].first; id++; kind++; ans = max(ans, sum + kind * kind); } cout << ans << endl; // system("read -n 1 -s -p \"Press any key to continue...\""); }
replace
30
31
30
31
0
p03148
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1000000007; const int MAXN = 100000; vector<ll> sushi[MAXN + 1]; vector<ll> best; vector<ll> rest; int main() { cin.tie(0); ios_base::sync_with_stdio(false); ll n, k; cin >> n >> k; ll t[n], d[n]; for (int i = 0; i < n; i++) cin >> t[i] >> d[i]; for (int i = 0; i < n; i++) { sushi[t[i]].push_back(d[i]); } for (int i = 1; i <= MAXN; i++) { if (sushi[i].empty()) continue; sort(sushi[i].rbegin(), sushi[i].rend()); best.push_back(sushi[i][0]); for (int j = 1; j < sushi[i].size(); j++) { rest.push_back(sushi[i][j]); } } sort(best.rbegin(), best.rend()); sort(rest.rbegin(), rest.rend()); ll bsize = best.size(); ll rsize = rest.size(); ll sumbest[bsize], sumrest[rsize]; sumbest[0] = best[0]; for (int i = 1; i < bsize; i++) sumbest[i] = sumbest[i - 1] + best[i]; sumrest[0] = rest[0]; for (int i = 1; i < rsize; i++) sumrest[i] = sumrest[i - 1] + rest[i]; ll ans = 0; for (ll i = 0; i <= min(k, bsize); i++) { // best * i & rest * (k - i) ll sum = 0; if (i - 1 >= 0) { sum += sumbest[i - 1]; } if (k - i - 1 >= 0 && k - i - 1 < rsize) { sum += sumrest[k - i - 1]; } ans = max(ans, sum + i * i); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1000000007; const int MAXN = 100000; vector<ll> sushi[MAXN + 1]; vector<ll> best; vector<ll> rest; int main() { cin.tie(0); ios_base::sync_with_stdio(false); ll n, k; cin >> n >> k; ll t[n], d[n]; for (int i = 0; i < n; i++) cin >> t[i] >> d[i]; for (int i = 0; i < n; i++) { sushi[t[i]].push_back(d[i]); } for (int i = 1; i <= MAXN; i++) { if (sushi[i].empty()) continue; sort(sushi[i].rbegin(), sushi[i].rend()); best.push_back(sushi[i][0]); for (int j = 1; j < sushi[i].size(); j++) { rest.push_back(sushi[i][j]); } } sort(best.rbegin(), best.rend()); sort(rest.rbegin(), rest.rend()); ll bsize = best.size(); ll rsize = rest.size(); ll sumbest[bsize], sumrest[rsize]; sumbest[0] = best[0]; for (int i = 1; i < bsize; i++) sumbest[i] = sumbest[i - 1] + best[i]; if (!rest.empty()) { sumrest[0] = rest[0]; } for (int i = 1; i < rsize; i++) sumrest[i] = sumrest[i - 1] + rest[i]; ll ans = 0; for (ll i = 0; i <= min(k, bsize); i++) { // best * i & rest * (k - i) ll sum = 0; if (i - 1 >= 0) { sum += sumbest[i - 1]; } if (k - i - 1 >= 0 && k - i - 1 < rsize) { sum += sumrest[k - i - 1]; } ans = max(ans, sum + i * i); } cout << ans << endl; }
replace
41
42
41
44
0
p03148
C++
Runtime Error
#include <algorithm> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <vector> #define _USE_MATH_DEFINES #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> using namespace std; #define SE second #define FI first #define EPS 1e-12 #define ull unsigned long long #define ll long long #define VI vector<ll> #define PII pair<ll, ll> #define VVI vector<vector<ll>> #define REP(i, n) for (int i = 0, _n = (n); (i) < (int)_n; ++i) #define RANGE(i, a, b) for (int i = (int)a, _b = (int)(b); (i) < _b; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define ALL(c) (c).begin(), (c).end() #define ALLR(c) (c).rbegin(), (c).rend() #define PB push_back #define MP(a, b) make_pair(a, b) #define POPCOUNT __builtin_popcount #define POPCOUNTLL __builtin_popcountll #define CLEAR(table, v) memset(table, v, sizeof(table)); #define PRINT1(table, D0) \ REP(d0, D0) cout << table[d0] << " "; \ cout << "\n"; #define PRINT2(table, D0, D1) \ REP(d0, D0) { \ REP(d1, D1) cout << table[d0][d1] << " "; \ cout << "\n"; \ } #define PRINT3(table, D0, D1, D2) \ REP(d0, D0) { \ REP(d1, D1) { \ REP(d2, D2) cout << table[d0][d1][d2] << " "; \ cout << "\n"; \ } \ cout << "\n"; \ } #define UNIFORM_DOUBLE(a, b) \ (((b - a) * (double)rand() / RAND_MAX) + a) // [a, b) #define UNIFORM_LL(a, b) (ll) UNIFORM_DOUBLE(a, b) // [a, b) #define IN(v, lo, hi) ((lo) <= (v) && (v) < (hi)) #define DD(v) cout << #v << ": " << v << endl template <typename T0, typename T1> std::ostream &operator<<(std::ostream &os, const map<T0, T1> &v) { for (typename map<T0, T1>::const_iterator p = v.begin(); p != v.end(); p++) { os << p->first << ": " << p->second << " "; } return os; } template <typename T0, typename T1> std::ostream &operator<<(std::ostream &os, const pair<T0, T1> &v) { os << v.FI << ": " << v.SE << " "; return os; } template <typename T> std::ostream &operator<<(std::ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); i++) { os << v[i] << " "; } return os; } template <typename T> std::ostream &operator<<(std::ostream &os, const vector<vector<T>> &v) { for (int i = 0; i < (int)v.size(); i++) { os << v[i] << endl; } return os; } template <typename T> std::ostream &operator<<(std::ostream &os, const set<T> &v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; } template <typename T> std::ostream &operator<<(std::ostream &os, const deque<T> &v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; } #define MOD 1000000007LL #define INF (1LL << 60) int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, K; while (cin >> N >> K) { vector<PII> DT(N); REP(i, N) cin >> DT[i].SE >> DT[i].FI; sort(ALLR(DT)); // DD(DT); ll sum = 0; ll kind = 0; VI co(N + 1); stack<ll> st; REP(i, K) { sum += DT[i].FI; if (co[DT[i].SE] == 0) kind++; if (co[DT[i].SE]) st.push(DT[i].FI); co[DT[i].SE]++; } VI co2(co); // stack<ll> st2(st); // for(int i=K-1;i>=0;i--) { // if(2<=co2[DT[i].SE]) { // assert(st2.top()==DT[i].FI); // st2.pop(); // co2[DT[i].SE]--; // } // } ll ans = sum + kind * kind; ll rmi = K - 1; RANGE(i, K, N) { if (co[DT[i].SE]) continue; if (st.empty()) break; while (0 <= rmi && co2[DT[rmi].SE] <= 1) rmi--; if (rmi < 0) break; co2[DT[rmi].SE]--; assert(0 < co2[DT[rmi].SE]); assert(st.top() == DT[rmi].FI); // sum -= DT[rmi].FI; sum -= st.top(); st.pop(); sum += DT[i].FI; co[DT[i].SE]++; kind++; ans = max<ll>(ans, sum + kind * kind); } // ll kind = 0; // VI co(N+1); // REP(i, K) { // sum += DT[i].FI; // if(co[DT[i].SE]==0) kind++; // co[DT[i].SE]++; // } // ll rmi = K-1; // ll addi = K; // ll ans = sum + kind*kind; //// DD(ans); // while(1) { // while(0<=rmi && co[DT[rmi].SE]<=1) rmi--; // if(rmi<0) break; // while(addi<N && 0<co[DT[addi].SE]) addi++; // if(addi==N) break; //// DD(rmi);DD(addi);DD(co); // co[DT[rmi].SE]--; // sum -= DT[rmi].FI; // sum += DT[addi].FI; // kind++; // co[DT[addi].SE]++; // ans = max(ans, sum+kind*kind); // } cout << ans << endl; // break; } return 0; }
#include <algorithm> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <vector> #define _USE_MATH_DEFINES #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> using namespace std; #define SE second #define FI first #define EPS 1e-12 #define ull unsigned long long #define ll long long #define VI vector<ll> #define PII pair<ll, ll> #define VVI vector<vector<ll>> #define REP(i, n) for (int i = 0, _n = (n); (i) < (int)_n; ++i) #define RANGE(i, a, b) for (int i = (int)a, _b = (int)(b); (i) < _b; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define ALL(c) (c).begin(), (c).end() #define ALLR(c) (c).rbegin(), (c).rend() #define PB push_back #define MP(a, b) make_pair(a, b) #define POPCOUNT __builtin_popcount #define POPCOUNTLL __builtin_popcountll #define CLEAR(table, v) memset(table, v, sizeof(table)); #define PRINT1(table, D0) \ REP(d0, D0) cout << table[d0] << " "; \ cout << "\n"; #define PRINT2(table, D0, D1) \ REP(d0, D0) { \ REP(d1, D1) cout << table[d0][d1] << " "; \ cout << "\n"; \ } #define PRINT3(table, D0, D1, D2) \ REP(d0, D0) { \ REP(d1, D1) { \ REP(d2, D2) cout << table[d0][d1][d2] << " "; \ cout << "\n"; \ } \ cout << "\n"; \ } #define UNIFORM_DOUBLE(a, b) \ (((b - a) * (double)rand() / RAND_MAX) + a) // [a, b) #define UNIFORM_LL(a, b) (ll) UNIFORM_DOUBLE(a, b) // [a, b) #define IN(v, lo, hi) ((lo) <= (v) && (v) < (hi)) #define DD(v) cout << #v << ": " << v << endl template <typename T0, typename T1> std::ostream &operator<<(std::ostream &os, const map<T0, T1> &v) { for (typename map<T0, T1>::const_iterator p = v.begin(); p != v.end(); p++) { os << p->first << ": " << p->second << " "; } return os; } template <typename T0, typename T1> std::ostream &operator<<(std::ostream &os, const pair<T0, T1> &v) { os << v.FI << ": " << v.SE << " "; return os; } template <typename T> std::ostream &operator<<(std::ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); i++) { os << v[i] << " "; } return os; } template <typename T> std::ostream &operator<<(std::ostream &os, const vector<vector<T>> &v) { for (int i = 0; i < (int)v.size(); i++) { os << v[i] << endl; } return os; } template <typename T> std::ostream &operator<<(std::ostream &os, const set<T> &v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; } template <typename T> std::ostream &operator<<(std::ostream &os, const deque<T> &v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; } #define MOD 1000000007LL #define INF (1LL << 60) int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, K; while (cin >> N >> K) { vector<PII> DT(N); REP(i, N) cin >> DT[i].SE >> DT[i].FI; sort(ALLR(DT)); // DD(DT); ll sum = 0; ll kind = 0; VI co(N + 1); stack<ll> st; REP(i, K) { sum += DT[i].FI; if (co[DT[i].SE] == 0) kind++; if (co[DT[i].SE]) st.push(DT[i].FI); co[DT[i].SE]++; } VI co2(co); // stack<ll> st2(st); // for(int i=K-1;i>=0;i--) { // if(2<=co2[DT[i].SE]) { // assert(st2.top()==DT[i].FI); // st2.pop(); // co2[DT[i].SE]--; // } // } ll ans = sum + kind * kind; ll rmi = K - 1; RANGE(i, K, N) { if (co[DT[i].SE]) continue; if (st.empty()) break; while (0 <= rmi && co2[DT[rmi].SE] <= 1) rmi--; if (rmi < 0) break; co2[DT[rmi].SE]--; assert(0 < co2[DT[rmi].SE]); // assert(st.top()==DT[rmi].FI); // sum -= DT[rmi].FI; sum -= st.top(); st.pop(); sum += DT[i].FI; co[DT[i].SE]++; kind++; ans = max<ll>(ans, sum + kind * kind); } // ll kind = 0; // VI co(N+1); // REP(i, K) { // sum += DT[i].FI; // if(co[DT[i].SE]==0) kind++; // co[DT[i].SE]++; // } // ll rmi = K-1; // ll addi = K; // ll ans = sum + kind*kind; //// DD(ans); // while(1) { // while(0<=rmi && co[DT[rmi].SE]<=1) rmi--; // if(rmi<0) break; // while(addi<N && 0<co[DT[addi].SE]) addi++; // if(addi==N) break; //// DD(rmi);DD(addi);DD(co); // co[DT[rmi].SE]--; // sum -= DT[rmi].FI; // sum += DT[addi].FI; // kind++; // co[DT[addi].SE]++; // ans = max(ans, sum+kind*kind); // } cout << ans << endl; // break; } return 0; }
replace
148
149
148
149
0
p03148
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define rep(i, a, n) for (int(i) = (int)(a); (i) < (int)(n); ++(i)) #define repe(i, a, n) for (int(i) = (int)(a); (i) <= (int)(n); ++(i)) #define repif(i, a, x) for (int(i) = (int)(a); (x); ++(i)) #define repr(i, a, n) for (int(i) = ((int)(a)-1); (i) >= (int)(n); --(i)) #define reper(i, a, n) for (int(i) = (int)(a); (i) >= (int)(n); --(i)) #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) #define SIZE(x) ((int)(x).size()) #define ALL(x) (x).begin(), (x).end() #define RNG(x, a, n) &((x)[a]), &((x)[n]) #define ADD(a, b) ((((a + MOD) % MOD) + ((b + MOD) % MOD)) % MOD) #define MUL(a, b) ((((a) % MOD) * ((b) % MOD)) % MOD) #define CEIL(x) ((int)ceil(((double)x))) #define POW(x, y) ((int)pow(x, y)) #define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end()) #define YES cout << "YES" << endl #define NO cout << "NO" << endl #define Yes cout << "Yes" << endl #define No cout << "No" << endl #define yes cout << "yes" << endl; #define no cout << "no" << endl; #define fcout cout << fixed << setprecision(10) #define pb push_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define PI (acos(-1)) #define EPS (1e-10) #define INF LLONG_MAX #define MOD 1000000007 using namespace std; using VI = vector<int>; using PII = pair<int, int>; using VPII = vector<PII>; template <typename T, typename C> using PQ = priority_queue<T, vector<T>, C>; using Complex = complex<double>; int N, K; VPII v; map<int, bool> m; PQ<int, greater<int>> pq0; PQ<int, less<int>> pq1; signed main() { cin >> N >> K; rep(i, 0, N) { int t, d; cin >> t >> d; v.pb({d, t}); } sort(ALL(v), greater<PII>()); int ans = 0, n = 0; rep(i, 0, N) { if (i < K) { ans += v[i].first; if (m[v[i].second]) pq0.push(v[i].first); else m[v[i].second] = true, n++; } else if (!m[v[i].second]) pq1.push(v[i].first), m[v[i].second] = true; } ans += n * n; int prev = ans; repe(i, n + 1, K) { int v0, v1; v0 = pq0.top(), pq0.pop(); v1 = pq1.top(), pq1.pop(); prev = prev - v0 - (i - 1) * (i - 1) + v1 + i * i; chmax(ans, prev); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define int long long #define rep(i, a, n) for (int(i) = (int)(a); (i) < (int)(n); ++(i)) #define repe(i, a, n) for (int(i) = (int)(a); (i) <= (int)(n); ++(i)) #define repif(i, a, x) for (int(i) = (int)(a); (x); ++(i)) #define repr(i, a, n) for (int(i) = ((int)(a)-1); (i) >= (int)(n); --(i)) #define reper(i, a, n) for (int(i) = (int)(a); (i) >= (int)(n); --(i)) #define chmax(a, b) a = max(a, b) #define chmin(a, b) a = min(a, b) #define SIZE(x) ((int)(x).size()) #define ALL(x) (x).begin(), (x).end() #define RNG(x, a, n) &((x)[a]), &((x)[n]) #define ADD(a, b) ((((a + MOD) % MOD) + ((b + MOD) % MOD)) % MOD) #define MUL(a, b) ((((a) % MOD) * ((b) % MOD)) % MOD) #define CEIL(x) ((int)ceil(((double)x))) #define POW(x, y) ((int)pow(x, y)) #define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end()) #define YES cout << "YES" << endl #define NO cout << "NO" << endl #define Yes cout << "Yes" << endl #define No cout << "No" << endl #define yes cout << "yes" << endl; #define no cout << "no" << endl; #define fcout cout << fixed << setprecision(10) #define pb push_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define PI (acos(-1)) #define EPS (1e-10) #define INF LLONG_MAX #define MOD 1000000007 using namespace std; using VI = vector<int>; using PII = pair<int, int>; using VPII = vector<PII>; template <typename T, typename C> using PQ = priority_queue<T, vector<T>, C>; using Complex = complex<double>; int N, K; VPII v; map<int, bool> m; PQ<int, greater<int>> pq0; PQ<int, less<int>> pq1; signed main() { cin >> N >> K; rep(i, 0, N) { int t, d; cin >> t >> d; v.pb({d, t}); } sort(ALL(v), greater<PII>()); int ans = 0, n = 0; rep(i, 0, N) { if (i < K) { ans += v[i].first; if (m[v[i].second]) pq0.push(v[i].first); else m[v[i].second] = true, n++; } else if (!m[v[i].second]) pq1.push(v[i].first), m[v[i].second] = true; } ans += n * n; int prev = ans; repe(i, n + 1, K) { if (pq0.empty() || pq1.empty()) break; int v0, v1; v0 = pq0.top(), pq0.pop(); v1 = pq1.top(), pq1.pop(); prev = prev - v0 - (i - 1) * (i - 1) + v1 + i * i; chmax(ans, prev); } cout << ans << endl; return 0; }
insert
70
70
70
72
0
p03148
C++
Runtime Error
#include <algorithm> #include <climits> #include <cmath> #include <deque> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <utility> using namespace std; pair<long long, int> dt[100000]; int main() { int N; int K; cin >> N >> K; for (int i = 0; i < N; i++) { int t; long long d; cin >> t >> d; dt[i] = make_pair(d, t); } sort(dt, dt + N); long long ans = 0; map<int, int> type_counts; for (int i = 0; i < K; i++) { ans += dt[N - 1 - i].first; if (type_counts.find(dt[N - 1 - i].second) != type_counts.end()) { type_counts[dt[N - 1 - i].second]++; } else { type_counts[dt[N - 1 - i].second] = 1; } } long long type_num = type_counts.size(); ans += type_num * type_num; vector<long long> discard_order; for (int i = N - K; i < N; i++) { if (type_counts[dt[i].second] != 1) { discard_order.push_back(dt[i].first); type_counts[dt[i].second]--; } } if (discard_order.size() == 0) { cout << ans << endl; } long long tmp_ans = ans; int discard_ind = 0; for (int i = N - 1 - K; i >= 0; i--) { if (type_counts.find(dt[i].second) != type_counts.end()) { continue; } tmp_ans = tmp_ans - type_num * type_num + (type_num + 1) * (type_num + 1) + dt[i].first - discard_order[discard_ind]; ans = max(ans, tmp_ans); type_num++; discard_ind++; type_counts[dt[i].second] = 1; if (discard_ind >= discard_order.size()) { break; } } cout << ans << endl; return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <deque> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <utility> using namespace std; pair<long long, int> dt[100000]; int main() { int N; int K; cin >> N >> K; for (int i = 0; i < N; i++) { int t; long long d; cin >> t >> d; dt[i] = make_pair(d, t); } sort(dt, dt + N); long long ans = 0; map<int, int> type_counts; for (int i = 0; i < K; i++) { ans += dt[N - 1 - i].first; if (type_counts.find(dt[N - 1 - i].second) != type_counts.end()) { type_counts[dt[N - 1 - i].second]++; } else { type_counts[dt[N - 1 - i].second] = 1; } } long long type_num = type_counts.size(); ans += type_num * type_num; vector<long long> discard_order; for (int i = N - K; i < N; i++) { if (type_counts[dt[i].second] != 1) { discard_order.push_back(dt[i].first); type_counts[dt[i].second]--; } } if (discard_order.size() == 0) { cout << ans << endl; return 0; } long long tmp_ans = ans; int discard_ind = 0; for (int i = N - 1 - K; i >= 0; i--) { if (type_counts.find(dt[i].second) != type_counts.end()) { continue; } tmp_ans = tmp_ans - type_num * type_num + (type_num + 1) * (type_num + 1) + dt[i].first - discard_order[discard_ind]; ans = max(ans, tmp_ans); type_num++; discard_ind++; type_counts[dt[i].second] = 1; if (discard_ind >= discard_order.size()) { break; } } cout << ans << endl; return 0; }
insert
53
53
53
54
0
p03148
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // -- #define HOGE \ std::cin.tie(0); \ std::ios::sync_with_stdio(false); template <typename T> void CIN_VAR(T &t) { cin >> t; } template <typename A, typename... R> void CIN_VAR(A &car, R &...cdr) { std::cin >> car; CIN_VAR(cdr...); } #define VAR(type, ...) \ type __VA_ARGS__; \ CIN_VAR(__VA_ARGS__); #define VEC(t, c, n) \ std::vector<t> c(n); \ for (auto &i : c) \ std::cin >> i; #define MAT(t, c, m, n) \ std::vector<std::vector<t>> c(m, std::vector<t>(n)); \ for (auto &row : c) \ for (auto &w : row) \ std::cin >> w; #define ALL(c) (c).begin(), (c).end() #define CALL(c) (c).cbegin(), (c).cend() #define RALL(c) (c).rbegin(), (c).rend() #define CRALL(c) (c).crbegin(), (c).crend() #define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++) #define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++) #define PSORT(s, p, e) partial_sort((s), next((s), (p)), (e)) #define IN(a, x, b) (a <= x && x < b) template <class T> inline T CHMAX(T &x, const T y) { return x = (x < y) ? y : x; } template <class T> inline T CHMIN(T &x, const T y) { return x = (x > y) ? y : x; } #define SDESC(t) [](t &x, t &y) { return x > y; } #define VIEW(v, t) \ for_each((v).begin(), (v).end(), [](t &a) { cout << a << " "; }); \ cout << "\n"; #define COUT(dist) std::cout << (dist); #define WS std::cout << " "; #define NL std::cout << "\n"; // -- // -- using PII = pair<int, int>; using PLL = pair<long long, long long>; using LL = long long; using ULL = unsigned long long; template <class T> using V = vector<T>; template <class T> using V2 = vector<vector<T>>; template <class T, int W = 255> using A = array<T, W>; template <class T, int W = 255, int H = 255> using A2 = array<array<T, W>, W>; constexpr int dx[] = {-1, 0, 1, 0}; constexpr int dy[] = {0, -1, 0, 1}; // -- LL n, k; V<LL> t, d; V<PLL> pv; std::set<int> s; std::stack<int> st; int main() { HOGE; cin >> n; cin >> k; t.resize(n); d.resize(n); pv.resize(n); REP(i, n) { cin >> t[i]; cin >> d[i]; } { REP(i, n) pv[i] = PLL(d[i], t[i]); std::sort(ALL(pv), SDESC(PLL)); REP(i, n) std::tie(d[i], t[i]) = pv[i]; } LL ans = 0; REP(i, k) { if (s.count(t[i])) st.push(d[i]); s.insert(t[i]); ans += d[i]; } LL sum = ans; ans += (LL)((LL)s.size() * (LL)s.size()); FOR(i, k, n) { if (s.empty()) break; if (s.count(t[i])) continue; s.insert(t[i]); sum -= st.top(); st.pop(); sum += d[i]; CHMAX<LL>(ans, sum + (LL)(s.size() * s.size())); } COUT(ans) NL; }
#include <bits/stdc++.h> using namespace std; // -- #define HOGE \ std::cin.tie(0); \ std::ios::sync_with_stdio(false); template <typename T> void CIN_VAR(T &t) { cin >> t; } template <typename A, typename... R> void CIN_VAR(A &car, R &...cdr) { std::cin >> car; CIN_VAR(cdr...); } #define VAR(type, ...) \ type __VA_ARGS__; \ CIN_VAR(__VA_ARGS__); #define VEC(t, c, n) \ std::vector<t> c(n); \ for (auto &i : c) \ std::cin >> i; #define MAT(t, c, m, n) \ std::vector<std::vector<t>> c(m, std::vector<t>(n)); \ for (auto &row : c) \ for (auto &w : row) \ std::cin >> w; #define ALL(c) (c).begin(), (c).end() #define CALL(c) (c).cbegin(), (c).cend() #define RALL(c) (c).rbegin(), (c).rend() #define CRALL(c) (c).crbegin(), (c).crend() #define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++) #define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++) #define PSORT(s, p, e) partial_sort((s), next((s), (p)), (e)) #define IN(a, x, b) (a <= x && x < b) template <class T> inline T CHMAX(T &x, const T y) { return x = (x < y) ? y : x; } template <class T> inline T CHMIN(T &x, const T y) { return x = (x > y) ? y : x; } #define SDESC(t) [](t &x, t &y) { return x > y; } #define VIEW(v, t) \ for_each((v).begin(), (v).end(), [](t &a) { cout << a << " "; }); \ cout << "\n"; #define COUT(dist) std::cout << (dist); #define WS std::cout << " "; #define NL std::cout << "\n"; // -- // -- using PII = pair<int, int>; using PLL = pair<long long, long long>; using LL = long long; using ULL = unsigned long long; template <class T> using V = vector<T>; template <class T> using V2 = vector<vector<T>>; template <class T, int W = 255> using A = array<T, W>; template <class T, int W = 255, int H = 255> using A2 = array<array<T, W>, W>; constexpr int dx[] = {-1, 0, 1, 0}; constexpr int dy[] = {0, -1, 0, 1}; // -- LL n, k; V<LL> t, d; V<PLL> pv; std::set<int> s; std::stack<int> st; int main() { HOGE; cin >> n; cin >> k; t.resize(n); d.resize(n); pv.resize(n); REP(i, n) { cin >> t[i]; cin >> d[i]; } { REP(i, n) pv[i] = PLL(d[i], t[i]); std::sort(ALL(pv), SDESC(PLL)); REP(i, n) std::tie(d[i], t[i]) = pv[i]; } LL ans = 0; REP(i, k) { if (s.count(t[i])) st.push(d[i]); s.insert(t[i]); ans += d[i]; } LL sum = ans; ans += (LL)((LL)s.size() * (LL)s.size()); FOR(i, k, n) { if (st.empty()) break; if (s.count(t[i])) continue; s.insert(t[i]); sum -= st.top(); st.pop(); sum += d[i]; CHMAX<LL>(ans, sum + (LL)(s.size() * s.size())); } COUT(ans) NL; }
replace
98
99
98
99
0
p03148
C++
Runtime Error
#include <bits/stdc++.h> #define fi first #define se second #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define rep2(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define rev(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--) #define rev2(i, a, b) for (int(i) = (a)-1; (i) >= (b); (i)--) #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() #define pb push_back #define eb emplace_back #define yn \ { puts("Yes"); } \ else { \ puts("No"); \ } using namespace std; using ll = long long; using P = pair<int, int>; using Pll = pair<long long, long long>; template <class T> using Vec = vector<T>; template <class T> using VVec = vector<vector<T>>; long long TEN(int i) { return !i ? 1 : TEN(i - 1) * 10LL; } template <class T, class U> bool chmin(T &a, const U &b) { if (a > b) { a = b; return 1; } return 0; } template <class T, class U> bool chmax(T &a, const U &b) { if (a < b) { a = b; return 1; } return 0; } struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } iosetup; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// int N, K; int t[100005], d[100005]; int main() { cin >> N >> K; rep(i, N) cin >> t[i] >> d[i]; set<int> st; int syu = 0; rep(i, N) st.insert(t[i]); syu = st.size(); rep(i, N) t[i]--; VVec<P> ho(N); rep(i, N) ho[t[i]].eb(d[i], 0); rep(i, N) sort(rrng(ho[i])); rep(i, N) if (ho[i].size()) ho[i][0].se = 1; priority_queue<P> Q; rep(i, N) rep(j, ho[i].size()) Q.push({ho[i][j].fi, ho[i][j].se}); /* while (!Q.empty()) { auto [oi, mask] = Q.top(); Q.pop(); cout << oi << " " << mask << endl; } */ ll ans = 0; int cnt = 0; Vec<int> ko0; rep(i, K) { auto [oi, mask] = Q.top(); Q.pop(); cnt += mask; if (!mask) ko0.pb(oi); ans += oi; } ans += (ll)cnt * cnt; sort(rrng(ko0)); ll before_ans = ans; rep2(i, cnt + 1, syu + 1) { ll tans = before_ans; tans -= ko0[ko0.size() - 1]; ko0.pop_back(); int oi, mask = 0; while (!mask) { tie(oi, mask) = Q.top(); Q.pop(); } tans += oi; tans -= (ll)(i - 1) * (i - 1); tans += (ll)i * i; chmax(ans, tans); before_ans = tans; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define rep2(i, a, b) for (int(i) = (a); (i) < (b); (i)++) #define rev(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--) #define rev2(i, a, b) for (int(i) = (a)-1; (i) >= (b); (i)--) #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() #define pb push_back #define eb emplace_back #define yn \ { puts("Yes"); } \ else { \ puts("No"); \ } using namespace std; using ll = long long; using P = pair<int, int>; using Pll = pair<long long, long long>; template <class T> using Vec = vector<T>; template <class T> using VVec = vector<vector<T>>; long long TEN(int i) { return !i ? 1 : TEN(i - 1) * 10LL; } template <class T, class U> bool chmin(T &a, const U &b) { if (a > b) { a = b; return 1; } return 0; } template <class T, class U> bool chmax(T &a, const U &b) { if (a < b) { a = b; return 1; } return 0; } struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } iosetup; //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~// int N, K; int t[100005], d[100005]; int main() { cin >> N >> K; rep(i, N) cin >> t[i] >> d[i]; set<int> st; int syu = 0; rep(i, N) st.insert(t[i]); syu = st.size(); rep(i, N) t[i]--; VVec<P> ho(N); rep(i, N) ho[t[i]].eb(d[i], 0); rep(i, N) sort(rrng(ho[i])); rep(i, N) if (ho[i].size()) ho[i][0].se = 1; priority_queue<P> Q; rep(i, N) rep(j, ho[i].size()) Q.push({ho[i][j].fi, ho[i][j].se}); /* while (!Q.empty()) { auto [oi, mask] = Q.top(); Q.pop(); cout << oi << " " << mask << endl; } */ ll ans = 0; int cnt = 0; Vec<int> ko0; rep(i, K) { auto [oi, mask] = Q.top(); Q.pop(); cnt += mask; if (!mask) ko0.pb(oi); ans += oi; } ans += (ll)cnt * cnt; sort(rrng(ko0)); ll before_ans = ans; rep2(i, cnt + 1, syu + 1) { ll tans = before_ans; if (ko0.size() == 0) break; tans -= ko0[ko0.size() - 1]; ko0.pop_back(); int oi, mask = 0; while (!mask) { tie(oi, mask) = Q.top(); Q.pop(); } tans += oi; tans -= (ll)(i - 1) * (i - 1); tans += (ll)i * i; chmax(ans, tans); before_ans = tans; } cout << ans << endl; return 0; }
insert
93
93
93
95
0
p03148
C++
Runtime Error
#include <bits/stdc++.h> #define whlie while #define pb push_back #define eb emplace_back #define fi first #define se second #define rep(i, N) for (int i = 0; i < (N); i++) #define repr(i, N) for (int i = (N)-1; i >= 0; i--) #define rep1(i, N) for (int i = 1; i <= (N); i++) #define repr1(i, N) for (int i = (N); i > 0; i--) #define each(x, v) for (auto &x : v) #define all(v) (v).begin(), (v).end() #define sz(v) ((int)(v).size()) #define ini(...) \ int __VA_ARGS__; \ in(__VA_ARGS__) #define inl(...) \ ll __VA_ARGS__; \ in(__VA_ARGS__) #define ins(...) \ string __VA_ARGS__; \ in(__VA_ARGS__) using namespace std; void solve(); using ll = long long; using vl = vector<ll>; using vi = vector<int>; using vvi = vector<vector<int>>; constexpr int inf = 1001001001; constexpr ll infLL = (1LL << 61) - 1; struct IoSetupNya { IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7); } } iosetupnya; template <typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; } template <typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; } template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int s = (int)v.size(); rep(i, s) os << (i ? " " : "") << v[i]; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; } void in() {} template <typename T, class... U> void in(T &t, U &...u) { cin >> t; in(u...); } void out() { cout << "\n"; } template <typename T, class... U> void out(const T &t, const U &...u) { cout << t; if (sizeof...(u)) cout << " "; out(u...); } template <typename T> void die(T x) { out(x); exit(0); } #ifdef NyaanDebug #include "NyaanDebug.h" #define trc(...) \ do { \ cerr << #__VA_ARGS__ << " = "; \ dbg_out(__VA_ARGS__); \ } while (0) #define trca(v, N) \ do { \ cerr << #v << " = "; \ array_out(v, N); \ cout << endl; \ } while (0) #else #define trc(...) #define trca(...) int main() { solve(); } #endif using P = pair<int, int>; using vp = vector<P>; constexpr int MOD = /**/ 1000000007; //*/ 998244353; ///////// void solve() { ini(N, K); vp p(N); in(p); int M, m; // 種類数のcnt { set<int> s; each(x, p) s.insert(x.first); M = s.size(); } auto f = [](P a, P b) { return a.se > b.se; }; vl ans(K + 1, -infLL); vvi cnt(N + 1); set<int> s; sort(all(p), f); ll cur = 0; rep(i, K) { cur += p[i].se; cnt[p[i].fi].pb(p[i].se); s.insert(p[i].fi); } ans[m = s.size()] = cur; priority_queue<P, vector<P>, decltype(f)> Q(f); each(i, s) { if (cnt[i].size() > 1) { sort(all(cnt[i]), greater<int>()); rep1(j, (int)cnt[i].size() - 1) Q.push(P(i, cnt[i][j])); } } auto g = [](P a, P b) { return a.se < b.se; }; priority_queue<P, vector<P>, decltype(g)> Q2(g); for (int i = K; i < N; i++) Q2.push(p[i]); for (int i = s.size() + 1; i <= min(M, K); i++) { auto x = Q.top(); Q.pop(); cur -= x.second; P nxt; do { nxt = Q2.top(); Q2.pop(); } while (s.find(nxt.first) != s.end()); cur += nxt.second; s.insert(nxt.first); ans[i] = cur; } ll bns = -inf; for (ll i = m; i <= M; i++) { amax(bns, ans[i] + i * i); } out(bns); }
#include <bits/stdc++.h> #define whlie while #define pb push_back #define eb emplace_back #define fi first #define se second #define rep(i, N) for (int i = 0; i < (N); i++) #define repr(i, N) for (int i = (N)-1; i >= 0; i--) #define rep1(i, N) for (int i = 1; i <= (N); i++) #define repr1(i, N) for (int i = (N); i > 0; i--) #define each(x, v) for (auto &x : v) #define all(v) (v).begin(), (v).end() #define sz(v) ((int)(v).size()) #define ini(...) \ int __VA_ARGS__; \ in(__VA_ARGS__) #define inl(...) \ ll __VA_ARGS__; \ in(__VA_ARGS__) #define ins(...) \ string __VA_ARGS__; \ in(__VA_ARGS__) using namespace std; void solve(); using ll = long long; using vl = vector<ll>; using vi = vector<int>; using vvi = vector<vector<int>>; constexpr int inf = 1001001001; constexpr ll infLL = (1LL << 61) - 1; struct IoSetupNya { IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7); } } iosetupnya; template <typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; } template <typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; } template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int s = (int)v.size(); rep(i, s) os << (i ? " " : "") << v[i]; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; } void in() {} template <typename T, class... U> void in(T &t, U &...u) { cin >> t; in(u...); } void out() { cout << "\n"; } template <typename T, class... U> void out(const T &t, const U &...u) { cout << t; if (sizeof...(u)) cout << " "; out(u...); } template <typename T> void die(T x) { out(x); exit(0); } #ifdef NyaanDebug #include "NyaanDebug.h" #define trc(...) \ do { \ cerr << #__VA_ARGS__ << " = "; \ dbg_out(__VA_ARGS__); \ } while (0) #define trca(v, N) \ do { \ cerr << #v << " = "; \ array_out(v, N); \ cout << endl; \ } while (0) #else #define trc(...) #define trca(...) int main() { solve(); } #endif using P = pair<int, int>; using vp = vector<P>; constexpr int MOD = /**/ 1000000007; //*/ 998244353; ///////// void solve() { ini(N, K); vp p(N); in(p); int M, m; // 種類数のcnt { set<int> s; each(x, p) s.insert(x.first); M = s.size(); } auto f = [](P a, P b) { return a.se > b.se; }; vl ans(K + 1, -infLL); vvi cnt(N + 1); set<int> s; sort(all(p), f); ll cur = 0; rep(i, K) { cur += p[i].se; cnt[p[i].fi].pb(p[i].se); s.insert(p[i].fi); } ans[m = s.size()] = cur; priority_queue<P, vector<P>, decltype(f)> Q(f); each(i, s) { if (cnt[i].size() > 1) { sort(all(cnt[i]), greater<int>()); rep1(j, (int)cnt[i].size() - 1) Q.push(P(i, cnt[i][j])); } } auto g = [](P a, P b) { return a.se < b.se; }; priority_queue<P, vector<P>, decltype(g)> Q2(g); for (int i = K; i < N; i++) Q2.push(p[i]); for (int i = s.size() + 1; i <= min(M, K); i++) { auto x = Q.top(); Q.pop(); cur -= x.second; P nxt; do { nxt = Q2.top(); Q2.pop(); } while (s.find(nxt.first) != s.end()); cur += nxt.second; s.insert(nxt.first); ans[i] = cur; } ll bns = -inf; for (ll i = m; i <= min(M, K); i++) { amax(bns, ans[i] + i * i); } out(bns); }
replace
159
160
159
160
0
p03148
C++
Time Limit Exceeded
#include <algorithm> #include <cassert> #include <cmath> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unistd.h> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<vvl> vvvl; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<bool> vb; typedef vector<vector<bool>> vvb; typedef vector<string> vs; typedef vector<vector<string>> vvs; typedef vector<char> vc; typedef vector<vector<char>> vvc; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<vvd> vvvd; typedef pair<int, int> P; typedef pair<ll, ll> PL; typedef vector<P> vp; typedef vector<PL> vpl; typedef vector<vector<P>> vvp; typedef vector<vector<PL>> vvpl; const int INF = 1001001001; const ll LINF = 1e16; const double pi = 3.1415926535897932; const string endstr = "\n"; #define FOR(i, a, b) for (ll i = (a); i < b; i++) #define REP(i, n) for (ll i = 0; i < n; i++) #define FORMAP(it, m) for (auto it = m.begin(); it != m.end(); it++) #define ff first #define ss second #define pb push_back template <typename T> T gcd(T a, T b) { return (a == 0) ? b : gcd(b % a, a); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } bool p_comp_fs(const PL p1, const PL p2) { return p1.first < p2.first; }; bool p_comp_fg(const PL p1, const PL p2) { return p1.first > p2.first; }; bool p_comp_ss(const PL p1, const PL p2) { return p1.second < p2.second; }; bool p_comp_sg(const PL p1, const PL p2) { return p1.second > p2.second; }; template <typename T> vector<T> uniquen(vector<T> vec) { vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec; } int main() { ll N, K; cin >> N >> K; vpl dt(N); REP(i, N) { ll t, d; cin >> t >> d; dt[i] = PL(d, t); } sort(dt.begin(), dt.end(), p_comp_fg); set<ll> unq_t; multimap<ll, ll> dup; ll deli = 0; REP(i, K) { ll d = dt[i].ff, t = dt[i].ss; deli += d; if (unq_t.count(t) > 0) { dup.insert(make_pair(d, t)); } else { unq_t.insert(t); } } ll x = unq_t.size(); ll ans = deli + x * x; REP(i, N) { ll d = dt[i].ff, t = dt[i].ss; if (unq_t.count(t) > 0) continue; unq_t.insert(t); x++; deli += d - dup.begin()->ff; ans = max(ans, deli + x * x); dup.erase(dup.begin()); } cout << ans << endl; return 0; }
#include <algorithm> #include <cassert> #include <cmath> #include <deque> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unistd.h> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<vvl> vvvl; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<bool> vb; typedef vector<vector<bool>> vvb; typedef vector<string> vs; typedef vector<vector<string>> vvs; typedef vector<char> vc; typedef vector<vector<char>> vvc; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<vvd> vvvd; typedef pair<int, int> P; typedef pair<ll, ll> PL; typedef vector<P> vp; typedef vector<PL> vpl; typedef vector<vector<P>> vvp; typedef vector<vector<PL>> vvpl; const int INF = 1001001001; const ll LINF = 1e16; const double pi = 3.1415926535897932; const string endstr = "\n"; #define FOR(i, a, b) for (ll i = (a); i < b; i++) #define REP(i, n) for (ll i = 0; i < n; i++) #define FORMAP(it, m) for (auto it = m.begin(); it != m.end(); it++) #define ff first #define ss second #define pb push_back template <typename T> T gcd(T a, T b) { return (a == 0) ? b : gcd(b % a, a); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } bool p_comp_fs(const PL p1, const PL p2) { return p1.first < p2.first; }; bool p_comp_fg(const PL p1, const PL p2) { return p1.first > p2.first; }; bool p_comp_ss(const PL p1, const PL p2) { return p1.second < p2.second; }; bool p_comp_sg(const PL p1, const PL p2) { return p1.second > p2.second; }; template <typename T> vector<T> uniquen(vector<T> vec) { vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec; } int main() { ll N, K; cin >> N >> K; vpl dt(N); REP(i, N) { ll t, d; cin >> t >> d; dt[i] = PL(d, t); } sort(dt.begin(), dt.end(), p_comp_fg); set<ll> unq_t; multimap<ll, ll> dup; ll deli = 0; REP(i, K) { ll d = dt[i].ff, t = dt[i].ss; deli += d; if (unq_t.count(t) > 0) { dup.insert(make_pair(d, t)); } else { unq_t.insert(t); } } ll x = unq_t.size(); ll ans = deli + x * x; REP(i, N) { ll d = dt[i].ff, t = dt[i].ss; if (unq_t.count(t) > 0) continue; if (dup.size() < 1) break; unq_t.insert(t); x++; deli += d - dup.begin()->ff; ans = max(ans, deli + x * x); dup.erase(dup.begin()); } cout << ans << endl; return 0; }
insert
91
91
91
93
TLE
p03148
C++
Runtime Error
#include <algorithm> #include <iostream> #include <queue> using namespace std; typedef pair<int, int> P; int main() { int N, K; cin >> N >> K; P p[100000]; long s = 0; int cnt[100001] = {0}; long ans = 0; for (int i = 0; i < N; i++) { int t, d; cin >> t >> d; p[i] = P(d, t); } sort(p, p + N, greater<P>()); for (int i = 0; i < K; i++) { if (cnt[p[i].second] == 0) s++; cnt[p[i].second]++; ans += p[i].first; } ans += s * s; long ans_m = ans; int l = K - 1; int r = K; while (l >= 0 && K <= N - 1) { if (/*2*s+1 >= (p[l].first - p[r].first) && */ cnt[p[l].second] >= 2 && cnt[p[r].second] == 0) { ans += 2 * s + 1 - (p[l].first - p[r].first); cnt[p[l].second]--; cnt[p[r].second]++; l--; r++; s++; } else if (cnt[p[l].second] <= 1) { l--; } else if (cnt[p[r].second] > 0) { r++; } /*else if(2*s+1 < (p[l].first - p[r].first)){ //l--; }*/ ans_m = max(ans, ans_m); } cout << ans_m << endl; }
#include <algorithm> #include <iostream> #include <queue> using namespace std; typedef pair<int, int> P; int main() { int N, K; cin >> N >> K; P p[100000]; long s = 0; int cnt[100001] = {0}; long ans = 0; for (int i = 0; i < N; i++) { int t, d; cin >> t >> d; p[i] = P(d, t); } sort(p, p + N, greater<P>()); for (int i = 0; i < K; i++) { if (cnt[p[i].second] == 0) s++; cnt[p[i].second]++; ans += p[i].first; } ans += s * s; long ans_m = ans; int l = K - 1; int r = K; while (l >= 0 && r <= N - 1) { if (/*2*s+1 >= (p[l].first - p[r].first) && */ cnt[p[l].second] >= 2 && cnt[p[r].second] == 0) { ans += 2 * s + 1 - (p[l].first - p[r].first); cnt[p[l].second]--; cnt[p[r].second]++; l--; r++; s++; } else if (cnt[p[l].second] <= 1) { l--; } else if (cnt[p[r].second] > 0) { r++; } /*else if(2*s+1 < (p[l].first - p[r].first)){ //l--; }*/ ans_m = max(ans, ans_m); } cout << ans_m << endl; }
replace
31
32
31
32
0
p03148
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<int> v[100001]; int n, k; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { ll t, d; cin >> t >> d; v[t].push_back(d); } // 種類数が増えない vector<ll> ans0; // 種類数が増える vector<ll> ans1; for (int i = 0; i <= n; i++) { if (v[i].empty()) { continue; } sort(v[i].begin(), v[i].end(), greater<ll>()); ans1.push_back(v[i][0]); for (int j = 1; j < v[i].size(); j++) { ans0.push_back(v[i][j]); } } sort(ans0.begin(), ans0.end(), greater<ll>()); sort(ans1.begin(), ans1.end(), greater<ll>()); ll ans = 0LL; for (ll i = 1; i <= k; i++) { if (ans0.size() < k - i) { continue; } if (ans1.size() < i) { continue; } ll t = accumulate(ans1.begin(), ans1.begin() + i, 0LL) + accumulate(ans0.begin(), ans0.begin() + k - i, 0LL) + i * i; ans = max(ans, t); } ll t = accumulate(ans1.begin(), ans1.begin() + k, 0LL) + k * k; ans = max(ans, t); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<int> v[100001]; int n, k; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { ll t, d; cin >> t >> d; v[t].push_back(d); } // 種類数が増えない vector<ll> ans0; // 種類数が増える vector<ll> ans1; for (int i = 0; i <= n; i++) { if (v[i].empty()) { continue; } sort(v[i].begin(), v[i].end(), greater<ll>()); ans1.push_back(v[i][0]); for (int j = 1; j < v[i].size(); j++) { ans0.push_back(v[i][j]); } } sort(ans0.begin(), ans0.end(), greater<ll>()); sort(ans1.begin(), ans1.end(), greater<ll>()); ll ans = 0LL; for (ll i = 1; i <= k; i++) { if (ans0.size() < k - i) { continue; } if (ans1.size() < i) { continue; } ll t = accumulate(ans1.begin(), ans1.begin() + i, 0LL) + accumulate(ans0.begin(), ans0.begin() + k - i, 0LL) + i * i; ans = max(ans, t); } cout << ans << endl; }
delete
40
42
40
40
0
p03148
C++
Runtime Error
#include <algorithm> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long int ll; typedef pair<ll, ll> P; #define EPS (1e-7) #define INF 1e18 #define max(p, q) ((p) > (q) ? (p) : (q)) #define min(p, q) ((p) < (q) ? (p) : (q)) #define PI (acos(-1)) #define REP(i, n) for (int i = 0; i < (int)(n); i++) int main() { ll N, K; cin >> N >> K; vector<P> t(N); REP(i, N) cin >> t[i].first >> t[i].second; sort(t.begin(), t.end(), [](P a, P b) { return a.second > b.second; }); priority_queue<ll, vector<ll>, greater<ll>> red; set<ll> a; ll sum = 0; REP(i, K) { sum += t[i].second; if (a.find(t[i].first) != a.end()) red.push(t[i].second); else a.insert(t[i].first); } ll tmp = sum + a.size() * a.size(); for (int i = K; i < N; i++) { if (a.find(t[i].first) == a.end()) { a.insert(t[i].first); sum -= red.top(); sum += t[i].second; red.pop(); tmp = max(tmp, sum + a.size() * a.size()); } } cout << tmp << endl; return 0; }
#include <algorithm> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long int ll; typedef pair<ll, ll> P; #define EPS (1e-7) #define INF 1e18 #define max(p, q) ((p) > (q) ? (p) : (q)) #define min(p, q) ((p) < (q) ? (p) : (q)) #define PI (acos(-1)) #define REP(i, n) for (int i = 0; i < (int)(n); i++) int main() { ll N, K; cin >> N >> K; vector<P> t(N); REP(i, N) cin >> t[i].first >> t[i].second; sort(t.begin(), t.end(), [](P a, P b) { return a.second > b.second; }); priority_queue<ll, vector<ll>, greater<ll>> red; set<ll> a; ll sum = 0; REP(i, K) { sum += t[i].second; if (a.find(t[i].first) != a.end()) red.push(t[i].second); else a.insert(t[i].first); } ll tmp = sum + a.size() * a.size(); for (int i = K; i < N; i++) { if (a.find(t[i].first) == a.end() && a.size() != K) { a.insert(t[i].first); sum -= red.top(); sum += t[i].second; red.pop(); tmp = max(tmp, sum + a.size() * a.size()); } } cout << tmp << endl; return 0; }
replace
48
49
48
49
0
p03148
C++
Runtime Error
#include <algorithm> #include <iostream> #include <set> #include <stack> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> P; #define MOD 1000000007 #define REP(i, N) for (int i = 0; i < N; ++i) #define REP1(i, N) for (int i = 1; i <= N; ++i) #define RREP(i, N) for (int i = N - 1; i >= 0; --i) #define ALL(a) a.begin(), a.end() int main() { int n, k; cin >> n >> k; vector<P> vec; REP(i, n) { int t, d; cin >> t >> d; t--; vec.push_back(P(d, t)); } sort(ALL(vec)); reverse(ALL(vec)); set<int> set; stack<int> stack; ll sum = 0; REP(i, k) { if (set.count(vec[i].second)) { stack.push(vec[i].first); } else { set.insert(vec[i].second); } sum += vec[i].first; } ll ans = sum + set.size() * set.size(); for (int i = k; i < n; ++i) { if (set.count(vec[i].second)) continue; sum -= stack.top(); stack.pop(); set.insert(vec[i].second); sum += vec[i].first; ll res = sum + set.size() * set.size(); ans = max(ans, res); } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <set> #include <stack> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> P; #define MOD 1000000007 #define REP(i, N) for (int i = 0; i < N; ++i) #define REP1(i, N) for (int i = 1; i <= N; ++i) #define RREP(i, N) for (int i = N - 1; i >= 0; --i) #define ALL(a) a.begin(), a.end() int main() { int n, k; cin >> n >> k; vector<P> vec; REP(i, n) { int t, d; cin >> t >> d; t--; vec.push_back(P(d, t)); } sort(ALL(vec)); reverse(ALL(vec)); set<int> set; stack<int> stack; ll sum = 0; REP(i, k) { if (set.count(vec[i].second)) { stack.push(vec[i].first); } else { set.insert(vec[i].second); } sum += vec[i].first; } ll ans = sum + set.size() * set.size(); for (int i = k; i < n; ++i) { if (set.count(vec[i].second)) continue; if (stack.empty()) break; sum -= stack.top(); stack.pop(); set.insert(vec[i].second); sum += vec[i].first; ll res = sum + set.size() * set.size(); ans = max(ans, res); } cout << ans << endl; return 0; }
insert
44
44
44
46
0
p03148
C++
Runtime Error
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, n) FOR(i, 0, n) #define RFOR(i, a, b) for (int i = (a)-1; i >= (b); i--) #define rrep(i, n) RFOR(i, n, 0) #define fi first #define se second using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> pll; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, K; cin >> N >> K; ll t[N], d[N]; map<ll, ll> mp1; rep(i, N) { cin >> t[i] >> d[i]; } vector<pll> v; rep(i, N) { v.push_back((pll){d[i], t[i]}); }; sort(v.begin(), v.end()); reverse(v.begin(), v.end()); map<ll, ll> mp; ll ans = 0; ll typ = 0; vector<ll> w; for (ll i = 0; i < K; i++) { pll p = v[i]; auto it = mp.find(p.se); if (it == mp.end()) { mp[p.se] = 0; typ++; } mp[p.se]++; if (mp[p.se] >= 2) w.push_back(p.fi); ans += p.fi; } ans += typ * typ; // cout << "first:" << ans << endl; ll ans2 = ans; ll anst = ans; for (int i = K; i < N; i++) { pll p = v[i]; // cout << i << " " << p.se << endl; auto it = mp.find(p.se); if (it != mp.end()) continue; mp[p.se] = 1; ans2 -= w[w.size() - 1]; ans2 += p.fi; ans2 -= typ * typ; ans2 += (typ + 1) * (typ + 1); w.pop_back(); typ++; anst = max(anst, ans2); // cout << i << ":" << ans << " " << typ << endl; } cout << max(ans, anst) << endl; }
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, n) FOR(i, 0, n) #define RFOR(i, a, b) for (int i = (a)-1; i >= (b); i--) #define rrep(i, n) RFOR(i, n, 0) #define fi first #define se second using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll> pll; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, K; cin >> N >> K; ll t[N], d[N]; map<ll, ll> mp1; rep(i, N) { cin >> t[i] >> d[i]; } vector<pll> v; rep(i, N) { v.push_back((pll){d[i], t[i]}); }; sort(v.begin(), v.end()); reverse(v.begin(), v.end()); map<ll, ll> mp; ll ans = 0; ll typ = 0; vector<ll> w; for (ll i = 0; i < K; i++) { pll p = v[i]; auto it = mp.find(p.se); if (it == mp.end()) { mp[p.se] = 0; typ++; } mp[p.se]++; if (mp[p.se] >= 2) w.push_back(p.fi); ans += p.fi; } ans += typ * typ; // cout << "first:" << ans << endl; ll ans2 = ans; ll anst = ans; for (int i = K; i < N; i++) { pll p = v[i]; // cout << i << " " << p.se << endl; auto it = mp.find(p.se); if (it != mp.end()) continue; mp[p.se] = 1; if (w.size() == 0) continue; ans2 -= w[w.size() - 1]; ans2 += p.fi; ans2 -= typ * typ; ans2 += (typ + 1) * (typ + 1); w.pop_back(); typ++; anst = max(anst, ans2); // cout << i << ":" << ans << " " << typ << endl; } cout << max(ans, anst) << endl; }
insert
66
66
66
68
0
p03148
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <map> #include <queue> #include <vector> using namespace std; int n, k; map<int, vector<int>> m; vector<vector<int> *> v; priority_queue<int> p; int main() { scanf("%d %d", &n, &k); for (int i = 0; i < n; i++) { int t, d; scanf("%d %d", &t, &d); m[t].push_back(d); } for (map<int, vector<int>>::iterator i = m.begin(), e = m.end(); i != e; i++) { sort(i->second.begin(), i->second.end()); v.push_back(&i->second); } sort(v.begin(), v.end(), [](const vector<int> *v1, const vector<int> *v2) -> bool { return v1->back() > v2->back(); }); int vs = (k <= v.size()) ? k : v.size(); int ans[k]; for (int i = 0; i < vs; i++) { ans[i] = v[i]->back(); v[i]->pop_back(); } for (int i = 0; i < vs; i++) { for (vector<int>::iterator j = v[i]->begin(), e = v[i]->end(); j != e; j++) { p.emplace(*j); } } for (int i = vs; i < k; i++) { ans[i] = p.top(); p.pop(); } int x = vs; while (true) { if (ans[x - 1] + 2 * x - 1 >= p.top()) break; ans[--x] = p.top(); p.pop(); } long sum = 0; for (int i = 0; i < k; i++) sum += ans[i]; sum += static_cast<long>(x) * x; printf("%ld\n", sum); return 0; }
#include <algorithm> #include <cstdio> #include <map> #include <queue> #include <vector> using namespace std; int n, k; map<int, vector<int>> m; vector<vector<int> *> v; priority_queue<int> p; int main() { scanf("%d %d", &n, &k); for (int i = 0; i < n; i++) { int t, d; scanf("%d %d", &t, &d); m[t].push_back(d); } for (map<int, vector<int>>::iterator i = m.begin(), e = m.end(); i != e; i++) { sort(i->second.begin(), i->second.end()); v.push_back(&i->second); } sort(v.begin(), v.end(), [](const vector<int> *v1, const vector<int> *v2) -> bool { return v1->back() > v2->back(); }); int vs = (k <= v.size()) ? k : v.size(); int ans[k]; for (int i = 0; i < vs; i++) { ans[i] = v[i]->back(); v[i]->pop_back(); } for (int i = 0; i < vs; i++) { for (vector<int>::iterator j = v[i]->begin(), e = v[i]->end(); j != e; j++) { p.emplace(*j); } } for (int i = vs; i < k; i++) { ans[i] = p.top(); p.pop(); } int x = vs; while (true) { if (p.empty() || ans[x - 1] + 2 * x - 1 >= p.top()) break; ans[--x] = p.top(); p.pop(); } long sum = 0; for (int i = 0; i < k; i++) sum += ans[i]; sum += static_cast<long>(x) * x; printf("%ld\n", sum); return 0; }
replace
46
47
46
47
0
p03148
C++
Runtime Error
#include <algorithm> #include <iostream> #include <sstream> #include <string> #include <tuple> #include <vector> using namespace std; #define REP(n) for (int i = 0; i < n; i++) int flowers[101] = {0}; bool pairCompare(const pair<int, long long> &firstElof, const pair<int, long long> &secondElof) { return firstElof.second > secondElof.second; } int type_cnt[100001] = {0}; int main() { long long N, K; // vector < pair<int,long long> > all_sushi; vector<long long> y0_sushi; vector<long long> y1_sushi; cin >> N >> K; vector<vector<long long>> type_vector(N + 1); int type_cnt_ofs = 0; REP(N) { long long t, d; cin >> t >> d; type_vector[t].push_back(d); } REP(N) { if (type_vector[i].size() == 0) { continue; } sort(type_vector[i].begin(), type_vector[i].end()); y1_sushi.push_back(type_vector[i].back()); type_vector[i].pop_back(); y0_sushi.insert(y0_sushi.end(), type_vector[i].begin(), type_vector[i].end()); } sort(y1_sushi.rbegin(), y1_sushi.rend()); sort(y0_sushi.rbegin(), y0_sushi.rend()); /* REP(N + 1) { if (i > 0) { type_cnt[i] += type_cnt[i - 1]; if (type_cnt[i] == 0) { type_cnt_ofs = i; } } } */ long long ans = 0; long long X = 0; long long Y = max(0, (int)(K - y0_sushi.size())); REP(Y) { X += y1_sushi[i]; } REP(K - Y) { X += y0_sushi[i]; } while (true) { long long tmp = X + Y * Y; if (tmp > ans) { ans = tmp; } if (Y >= K || Y >= y1_sushi.size()) break; X += y1_sushi[Y]; X -= y0_sushi[K - Y - 1]; Y++; } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <sstream> #include <string> #include <tuple> #include <vector> using namespace std; #define REP(n) for (int i = 0; i < n; i++) int flowers[101] = {0}; bool pairCompare(const pair<int, long long> &firstElof, const pair<int, long long> &secondElof) { return firstElof.second > secondElof.second; } int type_cnt[100001] = {0}; int main() { long long N, K; // vector < pair<int,long long> > all_sushi; vector<long long> y0_sushi; vector<long long> y1_sushi; cin >> N >> K; vector<vector<long long>> type_vector(N + 1); int type_cnt_ofs = 0; REP(N) { long long t, d; cin >> t >> d; type_vector[t].push_back(d); } REP(N + 1) { if (type_vector[i].size() == 0) { continue; } sort(type_vector[i].begin(), type_vector[i].end()); y1_sushi.push_back(type_vector[i].back()); type_vector[i].pop_back(); y0_sushi.insert(y0_sushi.end(), type_vector[i].begin(), type_vector[i].end()); } sort(y1_sushi.rbegin(), y1_sushi.rend()); sort(y0_sushi.rbegin(), y0_sushi.rend()); /* REP(N + 1) { if (i > 0) { type_cnt[i] += type_cnt[i - 1]; if (type_cnt[i] == 0) { type_cnt_ofs = i; } } } */ long long ans = 0; long long X = 0; long long Y = max(0, (int)(K - y0_sushi.size())); REP(Y) { X += y1_sushi[i]; } REP(K - Y) { X += y0_sushi[i]; } while (true) { long long tmp = X + Y * Y; if (tmp > ans) { ans = tmp; } if (Y >= K || Y >= y1_sushi.size()) break; X += y1_sushi[Y]; X -= y0_sushi[K - Y - 1]; Y++; } cout << ans << endl; return 0; }
replace
32
33
32
33
0
p03149
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int using namespace std; #define mod 1000000007 #define pb push_back #define ff first #define ss second #define mp make_pair #define f(p, n) for (ll i = p; i < n; i++) ll exp(ll a, ll b, ll m); int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif ll a, b, c, d; cin >> a >> b >> c >> d; ll a1[10] = {0}; a1[a] = 1, a1[b] = 1; a1[c] = 1, a1[d] = 1; if (a1[1] == 1 && a1[9] == 1 && a1[7] == 1 && a1[4] == 1) cout << "YES" << endl; else cout << "NO" << endl; return 0; } ll exp(ll a, ll b, ll m) { if (b == 0) { return 1; } ll temp = exp(a, b / 2, m); temp = (temp * temp) % m; if (b & 1) { return (temp * (a % m)) % m; } return temp; }
#include <bits/stdc++.h> #define ll long long int using namespace std; #define mod 1000000007 #define pb push_back #define ff first #define ss second #define mp make_pair #define f(p, n) for (ll i = p; i < n; i++) ll exp(ll a, ll b, ll m); int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); ll a, b, c, d; cin >> a >> b >> c >> d; ll a1[10] = {0}; a1[a] = 1, a1[b] = 1; a1[c] = 1, a1[d] = 1; if (a1[1] == 1 && a1[9] == 1 && a1[7] == 1 && a1[4] == 1) cout << "YES" << endl; else cout << "NO" << endl; return 0; } ll exp(ll a, ll b, ll m) { if (b == 0) { return 1; } ll temp = exp(a, b / 2, m); temp = (temp * temp) % m; if (b & 1) { return (temp * (a % m)) % m; } return temp; }
delete
16
20
16
16
-7
p03149
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string s; for (int i = 0; i < 4; i++) { cin >> s.at(i); } sort(s.begin(), s.end()); string k = "NO"; if (s == "1479") { k = "YES"; } cout << k << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s = " "; for (int i = 0; i < 4; i++) { cin >> s.at(i); } sort(s.begin(), s.end()); string k = "NO"; if (s == "1479") { k = "YES"; } cout << k << endl; return 0; }
replace
4
5
4
5
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::at: __n (which is 0) >= this->size() (which is 0)
p03149
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main(void) { int a; string s = ""; for (int i = 0; i < 4; i++) { cin >> a; s.at(i) = '0' + a; } sort(s.begin(), s.end()); if (s == "1479") { cout << "YES"; } else { cout << "NO"; } }
#include <bits/stdc++.h> using namespace std; int main(void) { int a; string s = "9999"; for (int i = 0; i < 4; i++) { cin >> a; s.at(i) = '0' + a; } sort(s.begin(), s.end()); if (s == "1479") { cout << "YES"; } else { cout << "NO"; } }
replace
4
5
4
5
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::at: __n (which is 0) >= this->size() (which is 0)
p03149
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s.at(0) >> s.at(1) >> s.at(2) >> s.at(3); sort(s.begin(), s.end()); if (s == "1479") cout << "YES" << endl; else cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { string s = "0000"; cin >> s.at(0) >> s.at(1) >> s.at(2) >> s.at(3); sort(s.begin(), s.end()); if (s == "1479") cout << "YES" << endl; else cout << "NO" << endl; return 0; }
replace
4
5
4
5
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::at: __n (which is 0) >= this->size() (which is 0)
p03149
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> #include <unordered_map> #include <vector> using namespace std; int main() { vector<int> N(4); vector<int> hash_table(4, -1); hash_table[1] = 1; hash_table[9] = 1; hash_table[7] = 1; hash_table[4] = 1; int cnt = 4; for (int i = 0; i < 4; i++) { cin >> N[i]; if (hash_table[N[i]] > 0) { hash_table[N[i]]--; cnt--; } } if (cnt == 0) cout << "YES"; else cout << "NO"; return 0; }
#include <algorithm> #include <iostream> #include <string> #include <unordered_map> #include <vector> using namespace std; int main() { vector<int> N(4); vector<int> hash_table(10, -1); hash_table[1] = 1; hash_table[9] = 1; hash_table[7] = 1; hash_table[4] = 1; int cnt = 4; for (int i = 0; i < 4; i++) { cin >> N[i]; if (hash_table[N[i]] > 0) { hash_table[N[i]]--; cnt--; } } if (cnt == 0) cout << "YES"; else cout << "NO"; return 0; }
replace
9
10
9
10
-6
malloc(): corrupted top size
p03149
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { vector<int> cnt(10); for (int i = 0; 4; i++) { int n; cin >> n; cnt.at(n)++; } if (cnt.at(1) == 1 && cnt.at(9) == 1 && cnt.at(7) == 1 && cnt.at(4)) cout << "YES" << endl; else cout << "NO" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { vector<int> cnt(10); for (int i = 0; i < 4; i++) { int n; cin >> n; cnt.at(n)++; } if (cnt.at(1) == 1 && cnt.at(9) == 1 && cnt.at(7) == 1 && cnt.at(4)) cout << "YES" << endl; else cout << "NO" << endl; }
replace
5
6
5
6
TLE
p03149
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; typedef gp_hash_table<long long, long long> umap; #define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++) #define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--) #define rep(i, n) for (long long i = 0, _n = (n); i < _n; i++) #define repr(i, n) for (long long i = (n)-1; i >= 0; i--) #define foreach(it, ar) \ for (typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++) #define fill(ar, val) memset(ar, val, sizeof(ar)) #define fill0(ar) fill((ar), 0) #define fillinf(ar, n) fr(i, 0, (n)) ar[i] = INF #define debug(x) cout << #x << ": " << x << endl #define arr1d(a, n) \ cout << #a << " : "; \ fr(_, 1, n) cout << a[_] << ' '; \ cout << endl; #define arr1d0(a, n) \ cout << #a << " : "; \ rep(_, n) cout << a[_] << ' '; \ cout << endl; #define arr2d(a, n, m) \ cout << #a << " :" << endl; \ fr(_, 1, n) { \ fr(__, 1, m) cout << a[_][__] << ' '; \ cout << endl; \ } #define arr2d0(a, n, m) \ cout << #a << " :" << endl; \ rep(_, n) { \ rep(__, m) cout << a[_][__] << ' '; \ cout << endl; \ } /*Author Ritick Goenka || ritick(codechef) ||ritick(codeforces) */ /*IIT Roorkee = <3 */ #define ull unsigned long long #define ll long long #define ld double #define ui unsigned int #define all(ar) ar.begin(), ar.end() #define pb push_back #define mp make_pair #define ff first #define ss second #define y0 yyyyyy0 #define y1 yyyyyy1 #define sot(bello) bello.begin(), bello.end() #define BIT(n) (1 << (n)) #define SQR(x) ((x) * (x)) #define CUBE(x) ((x) * (x) * (x)) #define LSOne(S) (S) & (-S) inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } typedef pair<int, int> ii; typedef pair<int, ii> iii; typedef vector<ii> vii; typedef vector<int> vi; typedef vector<string> vs; template <typename T> inline T gcd(T a, T b) { if (b == 0) return a; else return gcd(b, a % b); } template <typename T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); } template <typename T> string toStr(T x) { stringstream st; st << x; string s; st >> s; return s; } template <class T> void splitStr(const string &s, vector<T> &out) { istringstream in(s); out.clear(); copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out)); } inline int two(int n) { return 1 << n; } inline int isOnBit(int n, int b) { return (n >> b) & 1; } inline void onBit(int &n, int b) { n |= two(b); } inline void offBit(int &n, int b) { n &= ~two(b); } inline int lastBit(int n) { return n & (-n); } inline int cntBit(int n) { int res = 0; while (n && ++res) n -= n & (-n); return res; } const int dx4[] = {-1, 0, 1, 0}; const int dy4[] = {0, 1, 0, -1}; const int dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1}; const int dy8[] = {0, 1, 0, -1, -1, 1, -1, 1}; #define INP "test.inp" #define OUT "test.out" #define PI 3.1415926535897932385 #define INF 1000000000000000 #define EPS 1e-7 #define MAXN 100000 #define MOD 998244353 #define dec decr // END OF COMPETITVE PROGRAMMING TEMPLATE ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } ll modexp(ll x, ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << setprecision(11); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll a, b, c, d; cin >> a >> b >> c >> d; ll m = min(a, min(b, min(c, d))); ll m1 = max(a, max(b, max(c, d))); if ((a == 4 || b == 4 || c == 4 || d == 4) && (a == 7 || b == 7 || c == 7 || d == 7) && m == 1 && m1 == 9) cout << "YES"; else cout << "NO"; return 0; }
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; typedef gp_hash_table<long long, long long> umap; #define fr(i, a, b) for (int i = (a), _b = (b); i <= _b; i++) #define frr(i, a, b) for (int i = (a), _b = (b); i >= _b; i--) #define rep(i, n) for (long long i = 0, _n = (n); i < _n; i++) #define repr(i, n) for (long long i = (n)-1; i >= 0; i--) #define foreach(it, ar) \ for (typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++) #define fill(ar, val) memset(ar, val, sizeof(ar)) #define fill0(ar) fill((ar), 0) #define fillinf(ar, n) fr(i, 0, (n)) ar[i] = INF #define debug(x) cout << #x << ": " << x << endl #define arr1d(a, n) \ cout << #a << " : "; \ fr(_, 1, n) cout << a[_] << ' '; \ cout << endl; #define arr1d0(a, n) \ cout << #a << " : "; \ rep(_, n) cout << a[_] << ' '; \ cout << endl; #define arr2d(a, n, m) \ cout << #a << " :" << endl; \ fr(_, 1, n) { \ fr(__, 1, m) cout << a[_][__] << ' '; \ cout << endl; \ } #define arr2d0(a, n, m) \ cout << #a << " :" << endl; \ rep(_, n) { \ rep(__, m) cout << a[_][__] << ' '; \ cout << endl; \ } /*Author Ritick Goenka || ritick(codechef) ||ritick(codeforces) */ /*IIT Roorkee = <3 */ #define ull unsigned long long #define ll long long #define ld double #define ui unsigned int #define all(ar) ar.begin(), ar.end() #define pb push_back #define mp make_pair #define ff first #define ss second #define y0 yyyyyy0 #define y1 yyyyyy1 #define sot(bello) bello.begin(), bello.end() #define BIT(n) (1 << (n)) #define SQR(x) ((x) * (x)) #define CUBE(x) ((x) * (x) * (x)) #define LSOne(S) (S) & (-S) inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } typedef pair<int, int> ii; typedef pair<int, ii> iii; typedef vector<ii> vii; typedef vector<int> vi; typedef vector<string> vs; template <typename T> inline T gcd(T a, T b) { if (b == 0) return a; else return gcd(b, a % b); } template <typename T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); } template <typename T> string toStr(T x) { stringstream st; st << x; string s; st >> s; return s; } template <class T> void splitStr(const string &s, vector<T> &out) { istringstream in(s); out.clear(); copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out)); } inline int two(int n) { return 1 << n; } inline int isOnBit(int n, int b) { return (n >> b) & 1; } inline void onBit(int &n, int b) { n |= two(b); } inline void offBit(int &n, int b) { n &= ~two(b); } inline int lastBit(int n) { return n & (-n); } inline int cntBit(int n) { int res = 0; while (n && ++res) n -= n & (-n); return res; } const int dx4[] = {-1, 0, 1, 0}; const int dy4[] = {0, 1, 0, -1}; const int dx8[] = {-1, 0, 1, 0, -1, -1, 1, 1}; const int dy8[] = {0, 1, 0, -1, -1, 1, -1, 1}; #define INP "test.inp" #define OUT "test.out" #define PI 3.1415926535897932385 #define INF 1000000000000000 #define EPS 1e-7 #define MAXN 100000 #define MOD 998244353 #define dec decr // END OF COMPETITVE PROGRAMMING TEMPLATE ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a); } ll modexp(ll x, ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout << setprecision(11); ll a, b, c, d; cin >> a >> b >> c >> d; ll m = min(a, min(b, min(c, d))); ll m1 = max(a, max(b, max(c, d))); if ((a == 4 || b == 4 || c == 4 || d == 4) && (a == 7 || b == 7 || c == 7 || d == 7) && m == 1 && m1 == 9) cout << "YES"; else cout << "NO"; return 0; }
delete
131
135
131
131
0
p03149
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> int main() { std::vector<int> v; std::vector<int> ans{1, 4, 7, 9}; for (int i = 0; i < 3; i++) std::cin >> v[i]; std::sort(v.begin(), v.end()); if (v == ans) { std::cout << "YES" << std::endl; } else { std::cout << "NO" << std::endl; } return 0; }
#include <algorithm> #include <iostream> #include <vector> int main() { std::vector<int> v(4, 0); int org[] = {1, 4, 7, 9}; std::vector<int> ans(org, org + 4); for (int i = 0; i < 4; i++) std::cin >> v[i]; std::sort(v.begin(), v.end()); if (v == ans) { std::cout << "YES" << std::endl; } else { std::cout << "NO" << std::endl; } return 0; }
replace
5
8
5
9
-11
p03149
Python
Runtime Error
print("YES" if set(map(int, input().split())) == set(1, 9, 7, 4) else "NO")
print("YES" if set(list(map(int, input().split()))) == set([1, 9, 7, 4]) else "NO")
replace
0
1
0
1
TypeError: set expected at most 1 argument, got 4
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03149/Python/s697792206.py", line 1, in <module> print('YES' if set(map(int, input().split())) == set(1, 9, 7, 4) else 'NO') TypeError: set expected at most 1 argument, got 4
p03149
C++
Runtime Error
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (n); i++) using namespace std; int main() { cin.tie(0)->sync_with_stdio(false); vector<int> n(4); REP(i, 4) cin >> n[i]; sort(n.begin(), n.end()); string s; REP(i, 4) s.push_back(n[i]); if (stoi(s) == 1479) cout << "YES" << '\n'; else cout << "NO" << '\n'; return 0; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (n); i++) using namespace std; int main() { cin.tie(0)->sync_with_stdio(false); vector<char> n(4); REP(i, 4) cin >> n[i]; sort(n.begin(), n.end()); string s; REP(i, 4) s.push_back(n[i]); if (stoi(s) == 1479) cout << "YES" << '\n'; else cout << "NO" << '\n'; return 0; }
replace
7
8
7
8
-6
terminate called after throwing an instance of 'std::invalid_argument' what(): stoi
p03149
Python
Runtime Error
import sys input = sys.stdin.readline N = list(map(int, input().split())).sorted() if N[0] == 1 and N[1] == 4 and N[2] == 7 and N[3] == 9: print("YES") else: print("NO")
import sys input = sys.stdin.readline N = sorted(list(map(int, input().split()))) if N[0] == 1 and N[1] == 4 and N[2] == 7 and N[3] == 9: print("YES") else: print("NO")
replace
4
5
4
5
AttributeError: 'list' object has no attribute 'sorted'. Did you mean: 'sort'?
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03149/Python/s741249337.py", line 4, in <module> N = list(map(int, input().split())).sorted() AttributeError: 'list' object has no attribute 'sorted'. Did you mean: 'sort'?
p03149
C++
Runtime Error
#include <bits/stdc++.h> #define mk make_pair using namespace std; typedef long long ll; const int N = 2e5 + 5; const int mod = 1e9 + 7; int n, a[N], b[N]; int main() { for (int i = 0; i < 4; ++i) cin >> a[i]; for (int i = 0; i < 4; ++i) b[i] = i; do { if (a[b[0]] == 1 && a[b[1]] == 9 && a[b[2]] == 7 && a[b[3]] == 4) return puts("YES"); } while (next_permutation(b, b + 4)); puts("NO"); }
#include <bits/stdc++.h> #define mk make_pair using namespace std; typedef long long ll; const int N = 2e5 + 5; const int mod = 1e9 + 7; int n, a[N], b[N]; int main() { for (int i = 0; i < 4; ++i) cin >> a[i]; for (int i = 0; i < 4; ++i) b[i] = i; do { if (a[b[0]] == 1 && a[b[1]] == 9 && a[b[2]] == 7 && a[b[3]] == 4) { puts("YES"); return 0; } } while (next_permutation(b, b + 4)); puts("NO"); }
replace
13
15
13
17
4
p03150
C++
Runtime Error
#include <algorithm> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long int ll; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) int main() { string s; cin >> s; string answer = "keyence"; int size, i; size = s.size(); if (s == answer) { cout << "YES" << endl; return 0; } if (size < 8) { cout << "NO" << endl; return 0; } for (i = 0; i < size; i++) { string tmp; tmp = s; tmp.erase(tmp.begin() + i, tmp.begin() + i + size - 7); // cout <<tmp <<endl; if (tmp == answer) { cout << "YES" << endl; return 0; } } cout << "NO" << endl; return 0; }
#include <algorithm> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef long long int ll; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) int main() { string s; cin >> s; string answer = "keyence"; int size, i; size = s.size(); if (s == answer) { cout << "YES" << endl; return 0; } if (size < 8) { cout << "NO" << endl; return 0; } for (i = 0; i < 8; i++) { string tmp; tmp = s; tmp.erase(tmp.begin() + i, tmp.begin() + i + size - 7); // cout <<tmp <<endl; if (tmp == answer) { cout << "YES" << endl; return 0; } } cout << "NO" << endl; return 0; }
replace
39
40
39
40
0
p03150
C++
Runtime Error
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; // typedef //------------------------------------------ typedef long long LL; typedef vector<int> VI; typedef vector<bool> VB; typedef vector<char> VC; typedef vector<double> VD; typedef vector<string> VS; typedef vector<LL> VLL; typedef vector<VI> VVI; typedef vector<VB> VVB; typedef vector<VS> VVS; typedef vector<VLL> VVLL; typedef vector<VVI> VVVI; typedef vector<VVLL> VVVLL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef pair<int, string> PIS; typedef pair<string, int> PSI; typedef pair<string, string> PSS; typedef vector<PII> VPII; typedef vector<PLL> VPLL; typedef vector<VPII> VVPII; typedef vector<VPLL> VVPLL; typedef vector<VS> VVS; // 数値・文字列 //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } inline LL toLongLong(string s) { LL v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } inline VC toVC(string s) { VC data(s.begin(), s.end()); return data; } template <typename List> void SPRIT(const std::string &s, const std::string &delim, List &result) { result.clear(); string::size_type pos = 0; while (pos != string::npos) { string::size_type p = s.find(delim, pos); if (p == string::npos) { result.push_back(s.substr(pos)); break; } else { result.push_back(s.substr(pos, p - pos)); } pos = p + delim.size(); } } string TRIM(const string &str, const char *trimCharacterList = " \t\v\r\n") { string result; string::size_type left = str.find_first_not_of(trimCharacterList); if (left != string::npos) { string::size_type right = str.find_last_not_of(trimCharacterList); result = str.substr(left, right - left + 1); } return result; } string REPLACE_STRING(const string source, const string find, const string alt) { string result = source; string::size_type pos = 0; while (pos = result.find(find, pos), pos != string::npos) { result.replace(pos, find.length(), alt); pos += alt.length(); } return result; } template <typename T> bool VECTOR_EXISTS(vector<T> vec, T data) { auto itr = std::find(vec.begin(), vec.end(), data); size_t index = distance(vec.begin(), itr); if (index != vec.size()) return true; else return false; } template <typename T> vector<T> VECTOR_UNIQUE_ERASE(vector<T> vec) { sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec; } template <typename T> void VECTOR_REMOVE_VALUE_ALL(vector<T> &vec, T data) { vec.erase(remove(vec.begin(), vec.end(), data), vec.end()); } template <typename T> vector<T> VECTOR_REMOVE_VALUE_ALL_FAST(vector<T> vec, T data) { vector<T> vec2; for (auto &x : vec) if (x != data) vec2.push_back(x); return vec2; } bool REG_MATCH(string const &text, regex const &re) { bool result = regex_match(text, re); return result; } bool REG_MATCH(string const &text, smatch &match, regex const &re) { bool result = regex_match(text, match, re); return result; } smatch REG_SEARCH(string const &text, regex const &re) { smatch m; regex_search(text, m, re); return m; } vector<smatch> REG_ALL_SEARCH(string const &text, regex const &re) { vector<smatch> matchs; sregex_iterator iter(text.cbegin(), text.cend(), re); sregex_iterator end; for (; iter != end; iter++) matchs.push_back(*iter); return matchs; } string REG_REPLACE(string const &text, regex const &re, string const &replace) { string result = regex_replace(text, re, replace, regex_constants::format_first_only); return result; } string REG_ALL_REPLACE(string const &text, regex const &re, string const &replace) { string result = regex_replace(text, re, replace); return result; } template <typename T, typename U, typename V, typename W> auto operator+(const std::pair<T, U> &l, const std::pair<V, W> &r) -> std::pair<decltype(l.first + r.first), decltype(l.second + r.second)> { return {l.first + r.first, l.second + r.second}; } template <typename T, typename U, typename V, typename W> auto operator-(const std::pair<T, U> &l, const std::pair<V, W> &r) -> std::pair<decltype(l.first - r.first), decltype(l.second - r.second)> { return {l.first - r.first, l.second - r.second}; } #define UPPER(s) transform((s).begin(), (s).end(), (s).begin(), ::toupper) #define LOWER(s) transform((s).begin(), (s).end(), (s).begin(), ::tolower) // 四捨五入 nLen=小数点第n位にする //------------------------------------------ // 切り上げ double ceil_n(double dIn, int nLen) { double dOut; dOut = dIn * pow(10.0, nLen); dOut = (double)(int)(dOut + 0.9); return dOut * pow(10.0, -nLen); } // 切り捨て double floor_n(double dIn, int nLen) { double dOut; dOut = dIn * pow(10.0, nLen); dOut = (double)(int)(dOut); return dOut * pow(10.0, -nLen); } // 四捨五入 double round_n(double dIn, int nLen) { double dOut; dOut = dIn * pow(10.0, nLen); dOut = (double)(int)(dOut + 0.5); return dOut * pow(10.0, -nLen); } // n桁目の数の取得 int take_a_n(LL num, int n) { string str = toString(num); return str[str.length() - n] - '0'; } // 進数 //------------------------------------------ //"1111011" → 123 int strbase_2to10(const std::string &s) { int out = 0; for (int i = 0, size = s.size(); i < size; ++i) { out *= 2; out += ((int)s[i] == 49) ? 1 : 0; } return out; } //"123" → 1111011 int strbase_10to2(const std::string &s) { int binary = toInt(s); int out = 0; for (int i = 0; binary > 0; i++) { out = out + (binary % 2) * pow(static_cast<int>(10), i); binary = binary / 2; } return out; } //"ABC" 2748 int strbase_16to10(const std::string &s) { int out = stoi(s, 0, 16); return out; } // 1111011 → 123 int intbase_2to10(int in) { string str = toString(in); return strbase_2to10(str); } // 123 → 1111011 int intbase_10to2(int in) { string str = toString(in); return strbase_10to2(str); } int intbase_16to10(int in) { string str = toString(in); return strbase_16to10(str); } // 123→ "7B" string intbase_10to16(unsigned int val, bool lower = true) { if (!val) return std::string("0"); std::string str; const char hc = lower ? 'a' : 'A'; // 小文字 or 大文字表記 while (val != 0) { int d = val & 15; // 16進数一桁を取得 if (d < 10) str.insert(str.begin(), d + '0'); // 10未満の場合 else // 10以上の場合 str.insert(str.begin(), d - 10 + hc); val >>= 4; } return str; } // 整数を2進数表記したときの1の個数を返す LL bitcount64(LL bits) { bits = (bits & 0x5555555555555555) + (bits >> 1 & 0x5555555555555555); bits = (bits & 0x3333333333333333) + (bits >> 2 & 0x3333333333333333); bits = (bits & 0x0f0f0f0f0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f0f0f0f0f); bits = (bits & 0x00ff00ff00ff00ff) + (bits >> 8 & 0x00ff00ff00ff00ff); bits = (bits & 0x0000ffff0000ffff) + (bits >> 16 & 0x0000ffff0000ffff); return (bits & 0x00000000ffffffff) + (bits >> 32 & 0x00000000ffffffff); } // comparison //------------------------------------------ #define C_MAX(a, b) ((a) > (b) ? (a) : (b)) #define C_MIN(a, b) ((a) < (b) ? (a) : (b)) #define C_ABS(a, b) ((a) < (b) ? (b) - (a) : (a) - (b)) template <typename T1, typename T2> inline void S_MAX(T1 &a, T2 b) { a = C_MAX(a, b); }; template <typename T1, typename T2> inline void S_MIN(T1 &a, T2 b) { a = C_MIN(a, b); }; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define SZ(a) int((a).size()) #define EACH(i, arr) \ for (typeof((arr).begin()) i = (arr).begin(); i != (arr).end(); ++i) #define EXIST(str, e) ((str).find(e) != (str).end()) #define COUNT(arr, v) count((arr).begin(), (arr).end(), v) #define SEARCH(v, w) search((v).begin(), (v).end(), (w).begin(), (w).end()) #define B_SEARCH(arr, v) binary_search((arr).begin(), (arr).end(), v) #define SORT(c) sort((c).begin(), (c).end()) #define RSORT(c) sort((c).rbegin(), (c).rend()) #define REVERSE(c) reverse((c).begin(), (c).end()) #define ROTATE_LEFT(arr, c) \ rotate((arr).begin(), (arr).begin() + (c), (arr).end()) #define ROTATE_RIGHT(arr, c) \ rotate((arr).rbegin(), (arr).rbegin() + (c), (arr).rend()) #define SUMI(arr) accumulate((arr).begin(), (arr).end(), 0) #define SUMD(arr) accumulate((arr).begin(), (arr).end(), 0.) #define SUMLL(arr) accumulate((arr).begin(), (arr).end(), 0LL) #define SUMS(arr) accumulate((arr).begin(), (arr).end(), string()) #define UB(arr, n) upper_bound((arr).begin(), (arr).end(), n) #define LB(arr, n) lower_bound((arr).begin(), (arr).end(), n) #define OF_ALL(arr, func) all_of((arr).begin(), (arr).end(), (func)) #define OF_NONE(arr, func) none_of((arr).begin(), (arr).end(), (func)) #define OF_ANY(arr, func) any_of((arr).begin(), (arr).end(), (func)) #define PB push_back #define MP make_pair // input output //------------------------------------------ #define GL(s) getline(cin, (s)) #define INIT() \ std::ios::sync_with_stdio(false); \ std::cin.tie(0); #define OUT(d) std::cout << (d) #define OUT_L(d) std::cout << (d) << endl #define FOUT(n, data) std::cout << std::fixed << std::setprecision(n) << (data) #define FOUT_L(n, data) \ std::cout << std::fixed << std::setprecision(n) << (data) << "\n" #define EL() printf("\n") #define SHOW_VECTOR(v) \ { \ std::cerr << #v << "\t:"; \ for (const auto &xxx : v) { \ std::cerr << xxx << " "; \ } \ std::cerr << "\n"; \ } #define SHOW_MAP(v) \ { \ std::cerr << #v << endl; \ for (const auto &xxx : v) { \ std::cerr << xxx.first << " " << xxx.second << "\n"; \ } \ } #define Yes() printf("Yes\n") #define No() printf("No\n") #define YES() printf("YES\n") #define NO() printf("NO\n") template <typename T1, typename T2> istream &operator>>(istream &in, pair<T1, T2> &p) { in >> p.first >> p.second; return in; } template <typename T> istream &operator>>(istream &in, vector<T> &v) { for (auto &x : v) in >> x; return in; } // repetition //------------------------------------------ #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) for (int i = n - 1; i >= 0; i--) #define FORLL(i, a, b) for (LL i = LL(a); i < LL(b); ++i) #define RFORLL(i, a, b) for (LL i = LL(b) - 1; i >= LL(a); --i) #define REPLL(i, n) for (LL i = 0; i < LL(n); ++i) #define RREPLL(i, n) for (LL i = LL(n) - 1; i >= 0; --i) #define FOREACH(x, arr) for (auto &(x) : (arr)) #define FORITER(x, arr) for (auto(x) = (arr).begin(); (x) != (arr).end(); ++(x)) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, 1, 0, -1}; // math //-------------------------------------------- // min <= aim <= max template <typename T> inline bool BETWEEN(const T aim, const T min, const T max) { if (min <= aim && aim <= max) { return true; } else { return false; } } template <class T> inline T SQR(const T x) { return x * x; } template <class T1, class T2> inline T1 POW(const T1 x, const T2 y) { if (!y) return 1; else if ((y & 1) == 0) { return SQR(POW(x, y >> 1)); } else return POW(x, y ^ 1) * x; } template <typename T> constexpr T ABS(T x) { return x < 0 ? -x : x; } // partial_permutation nPr 順列 // first・・最初の数 // middle・・r(取り出す数) // last・・n(全体数) template <class Iter> bool next_partial_permutation(Iter first, Iter middle, Iter last) { reverse(middle, last); return next_permutation(first, last); } // combination nCr 組み合わせ // first1・・最初の数 // last1==first2・・r(取り出す数) // last2・・n(全体数) template <class Iter> bool next_combination(Iter first1, Iter last1, Iter first2, Iter last2) { if ((first1 == last1) || (first2 == last2)) { return false; } Iter m1 = last1; Iter m2 = last2; --m2; while (--m1 != first1 && !(*m1 < *m2)) { } bool result = (m1 == first1) && !(*first1 < *m2); if (!result) { while (first2 != m2 && !(*m1 < *first2)) { ++first2; } first1 = m1; std::iter_swap(first1, first2); ++first1; ++first2; } if ((first1 != last1) && (first2 != last2)) { m1 = last1; m2 = first2; while ((m1 != first1) && (m2 != last2)) { std::iter_swap(--m1, m2); ++m2; } std::reverse(first1, m1); std::reverse(first1, last1); std::reverse(m2, last2); std::reverse(first2, last2); } return !result; } // numeric_law //-------------------------------------------- template <typename T> constexpr bool ODD(T x) { return x % 2 != 0; } template <typename T> constexpr bool EVEN(T x) { return x % 2 == 0; } // 最大公約数 template <class T> inline T GCD(const T x, const T y) { if (x < 0) return GCD(-x, y); if (y < 0) return GCD(x, -y); return (!y) ? x : GCD(y, x % y); } // 最小公倍数 template <class T> inline T LCM(const T x, const T y) { if (x < 0) return LCM(-x, y); if (y < 0) return LCM(x, -y); return x * (y / GCD(x, y)); } // ax + by = 1 // x,yが変数に格納される template <class T> inline T EXTGCD(const T a, const T b, T &x, T &y) { if (a < 0) { T d = EXTGCD(-a, b, x, y); x = -x; return d; } if (b < 0) { T d = EXTGCD(a, -b, x, y); y = -y; return d; } if (!b) { x = 1; y = 0; return a; } else { T d = EXTGCD(b, a % b, x, y); T t = x; x = y; y = t - (a / b) * y; return d; } } // 素数 template <class T> inline bool ISPRIME(const T x) { if (x <= 1) return false; for (T i = 2; SQR(i) <= x; i++) if (x % i == 0) return false; return true; } // 素数をtrueとして返す template <class T> VB ERATOSTHENES(const T n) { VB arr(n, true); for (int i = 2; SQR(i) < n; i++) { if (arr[i]) { for (int j = 0; i * (j + 2) < n; j++) { arr[i * (j + 2)] = false; } } } return arr; } // a <= x < b の素数を返す template <typename T> VB ERATOSTHENES(const T a, const T b) { VB small = ERATOSTHENES(b); VB prime(b - a, true); for (int i = 2; (T)(SQR(i)) < b; i++) { if (small[i]) { for (T j = max(2, (a + i - 1) / i) * i; j < b; j += i) { prime[j - a] = false; } } } return prime; } // nの約数 template <typename T> vector<T> DIVISOR(T n) { vector<T> v; for (LL i = 1; i * i <= n; ++i) { if (n % i == 0) { v.push_back(i); if (i != n / i) { v.push_back(n / i); } } } sort(v.begin(), v.end()); return v; } // nまでのすべての約数 template <typename T> vector<vector<T>> DIVISOR_ALL(T n) { vector<vector<T>> res(n + 1); for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j += i) { res[j].push_back(i); } } return res; } // 素因数分解 template <typename T> vector<pair<T, LL>> FACTORIZATION(T x) { vector<pair<T, LL>> ans; for (T i = 2; i * i <= x; i++) { if (x % i == 0) { LL count = 0; while (x % i == 0) { count++; x /= i; } ans.push_back(MP(i, count)); } } if (x != 1) ans.push_back(MP(x, 1)); return ans; } // N^P (mod M) LL POW_MOD(LL N, LL P, LL M) { if (P == 0) return 1LL; if (P % 2 == 0) { LL ret = POW_MOD(N, P / 2, M); return ret * ret % M; } return N * POW_MOD(N, P - 1, M) % M; } // 組み合わせ個数 template <typename T> inline T NCR(T n, T r) { T ans = 1; REPLL(i, r) { ans = ans * (n - i) / (i + 1); } return ans; } // 組み合わせ個数 (mod M) LL NCR_MOD(LL n, LL r, LL M) { if (r > n - r) return NCR_MOD(n, n - r, M); LL numerator = 1LL; // 分子 LL denominator = 1LL; // 分母 for (LL i = 0; i < r; i++) { numerator *= (n - i); numerator %= M; denominator *= (i + 1); denominator %= M; } return numerator * POW_MOD(denominator, M - 2, M) % M; } // confirmation //-------------------------------------------- // clear memory #define CLR(arr, d) memset((arr), (d), sizeof(arr)) // debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; /* * * * ~~~~Below My Answer~~~~ * * */ int main() { string S; cin >> S; bool good = false; if (S == "keyence") good = true; for (int i = 1; i < S.size(); i++) { for (int j = 0; j < S.size(); j++) { string t = S; t.erase(t.begin() + j, t.begin() + j + i); if (t == "keyence") good = true; } } if (good) YES(); else NO(); return 0; }
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <cctype> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; // typedef //------------------------------------------ typedef long long LL; typedef vector<int> VI; typedef vector<bool> VB; typedef vector<char> VC; typedef vector<double> VD; typedef vector<string> VS; typedef vector<LL> VLL; typedef vector<VI> VVI; typedef vector<VB> VVB; typedef vector<VS> VVS; typedef vector<VLL> VVLL; typedef vector<VVI> VVVI; typedef vector<VVLL> VVVLL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef pair<int, string> PIS; typedef pair<string, int> PSI; typedef pair<string, string> PSS; typedef vector<PII> VPII; typedef vector<PLL> VPLL; typedef vector<VPII> VVPII; typedef vector<VPLL> VVPLL; typedef vector<VS> VVS; // 数値・文字列 //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } inline LL toLongLong(string s) { LL v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } inline VC toVC(string s) { VC data(s.begin(), s.end()); return data; } template <typename List> void SPRIT(const std::string &s, const std::string &delim, List &result) { result.clear(); string::size_type pos = 0; while (pos != string::npos) { string::size_type p = s.find(delim, pos); if (p == string::npos) { result.push_back(s.substr(pos)); break; } else { result.push_back(s.substr(pos, p - pos)); } pos = p + delim.size(); } } string TRIM(const string &str, const char *trimCharacterList = " \t\v\r\n") { string result; string::size_type left = str.find_first_not_of(trimCharacterList); if (left != string::npos) { string::size_type right = str.find_last_not_of(trimCharacterList); result = str.substr(left, right - left + 1); } return result; } string REPLACE_STRING(const string source, const string find, const string alt) { string result = source; string::size_type pos = 0; while (pos = result.find(find, pos), pos != string::npos) { result.replace(pos, find.length(), alt); pos += alt.length(); } return result; } template <typename T> bool VECTOR_EXISTS(vector<T> vec, T data) { auto itr = std::find(vec.begin(), vec.end(), data); size_t index = distance(vec.begin(), itr); if (index != vec.size()) return true; else return false; } template <typename T> vector<T> VECTOR_UNIQUE_ERASE(vector<T> vec) { sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec; } template <typename T> void VECTOR_REMOVE_VALUE_ALL(vector<T> &vec, T data) { vec.erase(remove(vec.begin(), vec.end(), data), vec.end()); } template <typename T> vector<T> VECTOR_REMOVE_VALUE_ALL_FAST(vector<T> vec, T data) { vector<T> vec2; for (auto &x : vec) if (x != data) vec2.push_back(x); return vec2; } bool REG_MATCH(string const &text, regex const &re) { bool result = regex_match(text, re); return result; } bool REG_MATCH(string const &text, smatch &match, regex const &re) { bool result = regex_match(text, match, re); return result; } smatch REG_SEARCH(string const &text, regex const &re) { smatch m; regex_search(text, m, re); return m; } vector<smatch> REG_ALL_SEARCH(string const &text, regex const &re) { vector<smatch> matchs; sregex_iterator iter(text.cbegin(), text.cend(), re); sregex_iterator end; for (; iter != end; iter++) matchs.push_back(*iter); return matchs; } string REG_REPLACE(string const &text, regex const &re, string const &replace) { string result = regex_replace(text, re, replace, regex_constants::format_first_only); return result; } string REG_ALL_REPLACE(string const &text, regex const &re, string const &replace) { string result = regex_replace(text, re, replace); return result; } template <typename T, typename U, typename V, typename W> auto operator+(const std::pair<T, U> &l, const std::pair<V, W> &r) -> std::pair<decltype(l.first + r.first), decltype(l.second + r.second)> { return {l.first + r.first, l.second + r.second}; } template <typename T, typename U, typename V, typename W> auto operator-(const std::pair<T, U> &l, const std::pair<V, W> &r) -> std::pair<decltype(l.first - r.first), decltype(l.second - r.second)> { return {l.first - r.first, l.second - r.second}; } #define UPPER(s) transform((s).begin(), (s).end(), (s).begin(), ::toupper) #define LOWER(s) transform((s).begin(), (s).end(), (s).begin(), ::tolower) // 四捨五入 nLen=小数点第n位にする //------------------------------------------ // 切り上げ double ceil_n(double dIn, int nLen) { double dOut; dOut = dIn * pow(10.0, nLen); dOut = (double)(int)(dOut + 0.9); return dOut * pow(10.0, -nLen); } // 切り捨て double floor_n(double dIn, int nLen) { double dOut; dOut = dIn * pow(10.0, nLen); dOut = (double)(int)(dOut); return dOut * pow(10.0, -nLen); } // 四捨五入 double round_n(double dIn, int nLen) { double dOut; dOut = dIn * pow(10.0, nLen); dOut = (double)(int)(dOut + 0.5); return dOut * pow(10.0, -nLen); } // n桁目の数の取得 int take_a_n(LL num, int n) { string str = toString(num); return str[str.length() - n] - '0'; } // 進数 //------------------------------------------ //"1111011" → 123 int strbase_2to10(const std::string &s) { int out = 0; for (int i = 0, size = s.size(); i < size; ++i) { out *= 2; out += ((int)s[i] == 49) ? 1 : 0; } return out; } //"123" → 1111011 int strbase_10to2(const std::string &s) { int binary = toInt(s); int out = 0; for (int i = 0; binary > 0; i++) { out = out + (binary % 2) * pow(static_cast<int>(10), i); binary = binary / 2; } return out; } //"ABC" 2748 int strbase_16to10(const std::string &s) { int out = stoi(s, 0, 16); return out; } // 1111011 → 123 int intbase_2to10(int in) { string str = toString(in); return strbase_2to10(str); } // 123 → 1111011 int intbase_10to2(int in) { string str = toString(in); return strbase_10to2(str); } int intbase_16to10(int in) { string str = toString(in); return strbase_16to10(str); } // 123→ "7B" string intbase_10to16(unsigned int val, bool lower = true) { if (!val) return std::string("0"); std::string str; const char hc = lower ? 'a' : 'A'; // 小文字 or 大文字表記 while (val != 0) { int d = val & 15; // 16進数一桁を取得 if (d < 10) str.insert(str.begin(), d + '0'); // 10未満の場合 else // 10以上の場合 str.insert(str.begin(), d - 10 + hc); val >>= 4; } return str; } // 整数を2進数表記したときの1の個数を返す LL bitcount64(LL bits) { bits = (bits & 0x5555555555555555) + (bits >> 1 & 0x5555555555555555); bits = (bits & 0x3333333333333333) + (bits >> 2 & 0x3333333333333333); bits = (bits & 0x0f0f0f0f0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f0f0f0f0f); bits = (bits & 0x00ff00ff00ff00ff) + (bits >> 8 & 0x00ff00ff00ff00ff); bits = (bits & 0x0000ffff0000ffff) + (bits >> 16 & 0x0000ffff0000ffff); return (bits & 0x00000000ffffffff) + (bits >> 32 & 0x00000000ffffffff); } // comparison //------------------------------------------ #define C_MAX(a, b) ((a) > (b) ? (a) : (b)) #define C_MIN(a, b) ((a) < (b) ? (a) : (b)) #define C_ABS(a, b) ((a) < (b) ? (b) - (a) : (a) - (b)) template <typename T1, typename T2> inline void S_MAX(T1 &a, T2 b) { a = C_MAX(a, b); }; template <typename T1, typename T2> inline void S_MIN(T1 &a, T2 b) { a = C_MIN(a, b); }; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define SZ(a) int((a).size()) #define EACH(i, arr) \ for (typeof((arr).begin()) i = (arr).begin(); i != (arr).end(); ++i) #define EXIST(str, e) ((str).find(e) != (str).end()) #define COUNT(arr, v) count((arr).begin(), (arr).end(), v) #define SEARCH(v, w) search((v).begin(), (v).end(), (w).begin(), (w).end()) #define B_SEARCH(arr, v) binary_search((arr).begin(), (arr).end(), v) #define SORT(c) sort((c).begin(), (c).end()) #define RSORT(c) sort((c).rbegin(), (c).rend()) #define REVERSE(c) reverse((c).begin(), (c).end()) #define ROTATE_LEFT(arr, c) \ rotate((arr).begin(), (arr).begin() + (c), (arr).end()) #define ROTATE_RIGHT(arr, c) \ rotate((arr).rbegin(), (arr).rbegin() + (c), (arr).rend()) #define SUMI(arr) accumulate((arr).begin(), (arr).end(), 0) #define SUMD(arr) accumulate((arr).begin(), (arr).end(), 0.) #define SUMLL(arr) accumulate((arr).begin(), (arr).end(), 0LL) #define SUMS(arr) accumulate((arr).begin(), (arr).end(), string()) #define UB(arr, n) upper_bound((arr).begin(), (arr).end(), n) #define LB(arr, n) lower_bound((arr).begin(), (arr).end(), n) #define OF_ALL(arr, func) all_of((arr).begin(), (arr).end(), (func)) #define OF_NONE(arr, func) none_of((arr).begin(), (arr).end(), (func)) #define OF_ANY(arr, func) any_of((arr).begin(), (arr).end(), (func)) #define PB push_back #define MP make_pair // input output //------------------------------------------ #define GL(s) getline(cin, (s)) #define INIT() \ std::ios::sync_with_stdio(false); \ std::cin.tie(0); #define OUT(d) std::cout << (d) #define OUT_L(d) std::cout << (d) << endl #define FOUT(n, data) std::cout << std::fixed << std::setprecision(n) << (data) #define FOUT_L(n, data) \ std::cout << std::fixed << std::setprecision(n) << (data) << "\n" #define EL() printf("\n") #define SHOW_VECTOR(v) \ { \ std::cerr << #v << "\t:"; \ for (const auto &xxx : v) { \ std::cerr << xxx << " "; \ } \ std::cerr << "\n"; \ } #define SHOW_MAP(v) \ { \ std::cerr << #v << endl; \ for (const auto &xxx : v) { \ std::cerr << xxx.first << " " << xxx.second << "\n"; \ } \ } #define Yes() printf("Yes\n") #define No() printf("No\n") #define YES() printf("YES\n") #define NO() printf("NO\n") template <typename T1, typename T2> istream &operator>>(istream &in, pair<T1, T2> &p) { in >> p.first >> p.second; return in; } template <typename T> istream &operator>>(istream &in, vector<T> &v) { for (auto &x : v) in >> x; return in; } // repetition //------------------------------------------ #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) for (int i = n - 1; i >= 0; i--) #define FORLL(i, a, b) for (LL i = LL(a); i < LL(b); ++i) #define RFORLL(i, a, b) for (LL i = LL(b) - 1; i >= LL(a); --i) #define REPLL(i, n) for (LL i = 0; i < LL(n); ++i) #define RREPLL(i, n) for (LL i = LL(n) - 1; i >= 0; --i) #define FOREACH(x, arr) for (auto &(x) : (arr)) #define FORITER(x, arr) for (auto(x) = (arr).begin(); (x) != (arr).end(); ++(x)) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, 1, 0, -1}; // math //-------------------------------------------- // min <= aim <= max template <typename T> inline bool BETWEEN(const T aim, const T min, const T max) { if (min <= aim && aim <= max) { return true; } else { return false; } } template <class T> inline T SQR(const T x) { return x * x; } template <class T1, class T2> inline T1 POW(const T1 x, const T2 y) { if (!y) return 1; else if ((y & 1) == 0) { return SQR(POW(x, y >> 1)); } else return POW(x, y ^ 1) * x; } template <typename T> constexpr T ABS(T x) { return x < 0 ? -x : x; } // partial_permutation nPr 順列 // first・・最初の数 // middle・・r(取り出す数) // last・・n(全体数) template <class Iter> bool next_partial_permutation(Iter first, Iter middle, Iter last) { reverse(middle, last); return next_permutation(first, last); } // combination nCr 組み合わせ // first1・・最初の数 // last1==first2・・r(取り出す数) // last2・・n(全体数) template <class Iter> bool next_combination(Iter first1, Iter last1, Iter first2, Iter last2) { if ((first1 == last1) || (first2 == last2)) { return false; } Iter m1 = last1; Iter m2 = last2; --m2; while (--m1 != first1 && !(*m1 < *m2)) { } bool result = (m1 == first1) && !(*first1 < *m2); if (!result) { while (first2 != m2 && !(*m1 < *first2)) { ++first2; } first1 = m1; std::iter_swap(first1, first2); ++first1; ++first2; } if ((first1 != last1) && (first2 != last2)) { m1 = last1; m2 = first2; while ((m1 != first1) && (m2 != last2)) { std::iter_swap(--m1, m2); ++m2; } std::reverse(first1, m1); std::reverse(first1, last1); std::reverse(m2, last2); std::reverse(first2, last2); } return !result; } // numeric_law //-------------------------------------------- template <typename T> constexpr bool ODD(T x) { return x % 2 != 0; } template <typename T> constexpr bool EVEN(T x) { return x % 2 == 0; } // 最大公約数 template <class T> inline T GCD(const T x, const T y) { if (x < 0) return GCD(-x, y); if (y < 0) return GCD(x, -y); return (!y) ? x : GCD(y, x % y); } // 最小公倍数 template <class T> inline T LCM(const T x, const T y) { if (x < 0) return LCM(-x, y); if (y < 0) return LCM(x, -y); return x * (y / GCD(x, y)); } // ax + by = 1 // x,yが変数に格納される template <class T> inline T EXTGCD(const T a, const T b, T &x, T &y) { if (a < 0) { T d = EXTGCD(-a, b, x, y); x = -x; return d; } if (b < 0) { T d = EXTGCD(a, -b, x, y); y = -y; return d; } if (!b) { x = 1; y = 0; return a; } else { T d = EXTGCD(b, a % b, x, y); T t = x; x = y; y = t - (a / b) * y; return d; } } // 素数 template <class T> inline bool ISPRIME(const T x) { if (x <= 1) return false; for (T i = 2; SQR(i) <= x; i++) if (x % i == 0) return false; return true; } // 素数をtrueとして返す template <class T> VB ERATOSTHENES(const T n) { VB arr(n, true); for (int i = 2; SQR(i) < n; i++) { if (arr[i]) { for (int j = 0; i * (j + 2) < n; j++) { arr[i * (j + 2)] = false; } } } return arr; } // a <= x < b の素数を返す template <typename T> VB ERATOSTHENES(const T a, const T b) { VB small = ERATOSTHENES(b); VB prime(b - a, true); for (int i = 2; (T)(SQR(i)) < b; i++) { if (small[i]) { for (T j = max(2, (a + i - 1) / i) * i; j < b; j += i) { prime[j - a] = false; } } } return prime; } // nの約数 template <typename T> vector<T> DIVISOR(T n) { vector<T> v; for (LL i = 1; i * i <= n; ++i) { if (n % i == 0) { v.push_back(i); if (i != n / i) { v.push_back(n / i); } } } sort(v.begin(), v.end()); return v; } // nまでのすべての約数 template <typename T> vector<vector<T>> DIVISOR_ALL(T n) { vector<vector<T>> res(n + 1); for (int i = 1; i <= n; i++) { for (int j = i; j <= n; j += i) { res[j].push_back(i); } } return res; } // 素因数分解 template <typename T> vector<pair<T, LL>> FACTORIZATION(T x) { vector<pair<T, LL>> ans; for (T i = 2; i * i <= x; i++) { if (x % i == 0) { LL count = 0; while (x % i == 0) { count++; x /= i; } ans.push_back(MP(i, count)); } } if (x != 1) ans.push_back(MP(x, 1)); return ans; } // N^P (mod M) LL POW_MOD(LL N, LL P, LL M) { if (P == 0) return 1LL; if (P % 2 == 0) { LL ret = POW_MOD(N, P / 2, M); return ret * ret % M; } return N * POW_MOD(N, P - 1, M) % M; } // 組み合わせ個数 template <typename T> inline T NCR(T n, T r) { T ans = 1; REPLL(i, r) { ans = ans * (n - i) / (i + 1); } return ans; } // 組み合わせ個数 (mod M) LL NCR_MOD(LL n, LL r, LL M) { if (r > n - r) return NCR_MOD(n, n - r, M); LL numerator = 1LL; // 分子 LL denominator = 1LL; // 分母 for (LL i = 0; i < r; i++) { numerator *= (n - i); numerator %= M; denominator *= (i + 1); denominator %= M; } return numerator * POW_MOD(denominator, M - 2, M) % M; } // confirmation //-------------------------------------------- // clear memory #define CLR(arr, d) memset((arr), (d), sizeof(arr)) // debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; /* * * * ~~~~Below My Answer~~~~ * * */ int main() { string S; cin >> S; bool good = false; if (S == "keyence") good = true; for (int i = 1; i < S.size(); i++) { for (int j = 0; j < S.size() - i + 1; j++) { string t = S; t.erase(t.begin() + j, t.begin() + j + i); if (t == "keyence") good = true; } } if (good) YES(); else NO(); return 0; }
replace
690
691
690
691
-11
p03150
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { regex re[8]; re[0] = "keyence.*"; re[1] = "keyenc.*e"; re[2] = "keyen.*ce"; re[3] = "keye.*nce"; re[4] = "key.*ence"; re[5] = "ke.*yence"; re[6] = "k.*eyence"; re[7] = ".*keyence"; string s; cin >> s; bool ret = false; for (int i = 0; i < s.size(); i++) { ret = ret || regex_match(s, re[i]); } cout << (ret ? "YES" : "NO") << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { regex re[8]; re[0] = "keyence.*"; re[1] = "keyenc.*e"; re[2] = "keyen.*ce"; re[3] = "keye.*nce"; re[4] = "key.*ence"; re[5] = "ke.*yence"; re[6] = "k.*eyence"; re[7] = ".*keyence"; string s; cin >> s; bool ret = false; for (int i = 0; i < 8; i++) { ret = ret || regex_match(s, re[i]); } cout << (ret ? "YES" : "NO") << endl; return 0; }
replace
16
17
16
17
0
p03150
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #include <iterator> #include <map> #include <queue> #include <string> #include <vector> using namespace std; char s[110]; int szS; string target; int main() { scanf("%s", s); szS = strlen(s); string ss = s; int delDepth = szS - 7; if (delDepth == 0) { if (ss == "keyence") printf("YES\n"); else printf("NO\n"); return 0; } for (int i = 0; i < szS - 7; i++) { target = ss.substr(0, i) + ss.substr(i + delDepth); if (target == "keyence") { printf("YES\n"); return 0; } } printf("NO\n"); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iterator> #include <map> #include <queue> #include <string> #include <vector> using namespace std; char s[110]; int szS; string target; int main() { scanf("%s", s); szS = strlen(s); string ss = s; int delDepth = szS - 7; if (delDepth == 0) { if (ss == "keyence") printf("YES\n"); else printf("NO\n"); return 0; } for (int i = 0; i < szS - delDepth; i++) { target = ss.substr(0, i) + ss.substr(i + delDepth); if (target == "keyence") { printf("YES\n"); return 0; } } printf("NO\n"); return 0; }
replace
30
31
30
31
0
p03150
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.size(), a = 0; if (n == 7) cout << "YES" << endl; else { for (int i = 0; i < n - 7 + 1; i++) { string t = s.substr(0, i) + s.substr(n + i - 7, 7 - i); if (t == "keyence") { a++; cout << "YES" << endl; break; } } if (a == 0) cout << "NO" << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; int n = s.size(), a = 0; if (n == 7) cout << "YES" << endl; else { for (int i = 0; i < 7; i++) { string t = s.substr(0, i) + s.substr(n + i - 7, 7 - i); if (t == "keyence") { a++; cout << "YES" << endl; break; } } if (a == 0) cout << "NO" << endl; } }
replace
9
10
9
10
0
p03150
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { const string keyword = "keyence"; string S; cin >> S; bool is_satisfied = false; for (size_t len_head = 0; len_head <= keyword.size(); len_head++) { size_t len_tail = keyword.size() - len_head; if (S.substr(0, len_head) == keyword.substr(0, len_head) && S.substr(S.size() - len_tail) == keyword.substr(S.size() - len_tail)) { is_satisfied = true; break; } } string ans = is_satisfied ? "YES" : "NO"; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { const string keyword = "keyence"; string S; cin >> S; bool is_satisfied = false; for (size_t len_head = 0; len_head <= keyword.size(); len_head++) { size_t len_tail = keyword.size() - len_head; if (S.substr(0, len_head) == keyword.substr(0, len_head) && S.substr(S.size() - len_tail) == keyword.substr(keyword.size() - len_tail)) { is_satisfied = true; break; } } string ans = is_satisfied ? "YES" : "NO"; cout << ans << endl; }
replace
12
13
12
14
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr: __pos (which is 8) > this->size() (which is 7)
p03150
C++
Runtime Error
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author aryssoncf */ // Taken from: // https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ull> vul; typedef vector<ll> vl; typedef vector<pii> vpii; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define F0R(i, a) FOR(i, 0, a) #define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i) #define R0F(i, a) ROF(i, 0, a) #define trav(a, x) for (auto &a : x) #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define rsz resize #define mp make_pair #define pb push_back #define f first #define s second const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1 const int MX = 2e5 + 5; template <class T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); // // Created by aryssoncf on 28/10/2019. // #include <type_traits> #include <iterator> #include <utility> template <typename T> constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) { return true; } constexpr bool hasBegin(...) { return false; } template <typename T> using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>; #ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP #define JHELPER_EXAMPLE_PROJECT_IO_HPP #endif // JHELPER_EXAMPLE_PROJECT_IO_HPP template <typename T> std::istream &operator>>(std::istream &is, std::vector<T> &vec) { for (T &element : vec) { is >> element; } return is; } template <typename T, typename U> std::istream &operator>>(std::istream &is, std::pair<T, U> &p) { is >> p.first; is >> p.second; return is; } template <class X, class Y> std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) { return os << p.first << " " << p.second; } template <class Ch, class Tr, class Container> std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) { bool first = true; for (auto &y : x) { if (first) { first = false; } else { os << " "; } os << y; } return os; } using namespace std; class BKEYENCEString { const string KEYENCE = "keyence"; public: void solve(std::istream &in, std::ostream &out) { string str; in >> str; bool res = false; int n = sz(str); FOR(i, 0, n - 6) { int j = n - 7 + i; if (str.substr(0, i) + str.substr(j) == KEYENCE) { res = true; } } out << (res ? "YES" : "NO") << '\n'; } void setup() {} }; int main() { std::ios_base::sync_with_stdio(false); BKEYENCEString solver; solver.setup(); std::istream &in(std::cin); std::ostream &out(std::cout); in.tie(nullptr); out << std::fixed; out.precision(20); solver.solve(in, out); return 0; }
/** * code generated by JHelper * More info: https://github.com/AlexeyDmitriev/JHelper * @author aryssoncf */ // Taken from: // https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<ull> vul; typedef vector<ll> vl; typedef vector<pii> vpii; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define F0R(i, a) FOR(i, 0, a) #define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i) #define R0F(i, a) ROF(i, 0, a) #define trav(a, x) for (auto &a : x) #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define rsz resize #define mp make_pair #define pb push_back #define f first #define s second const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1 const int MX = 2e5 + 5; template <class T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); // // Created by aryssoncf on 28/10/2019. // #include <type_traits> #include <iterator> #include <utility> template <typename T> constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) { return true; } constexpr bool hasBegin(...) { return false; } template <typename T> using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>; #ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP #define JHELPER_EXAMPLE_PROJECT_IO_HPP #endif // JHELPER_EXAMPLE_PROJECT_IO_HPP template <typename T> std::istream &operator>>(std::istream &is, std::vector<T> &vec) { for (T &element : vec) { is >> element; } return is; } template <typename T, typename U> std::istream &operator>>(std::istream &is, std::pair<T, U> &p) { is >> p.first; is >> p.second; return is; } template <class X, class Y> std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) { return os << p.first << " " << p.second; } template <class Ch, class Tr, class Container> std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) { bool first = true; for (auto &y : x) { if (first) { first = false; } else { os << " "; } os << y; } return os; } using namespace std; class BKEYENCEString { const string KEYENCE = "keyence"; public: void solve(std::istream &in, std::ostream &out) { string str; in >> str; bool res = false; int n = sz(str); FOR(i, 0, 7) { int j = n - 7 + i; if (str.substr(0, i) + str.substr(j) == KEYENCE) { res = true; } } out << (res ? "YES" : "NO") << '\n'; } void setup() {} }; int main() { std::ios_base::sync_with_stdio(false); BKEYENCEString solver; solver.setup(); std::istream &in(std::cin); std::ostream &out(std::cout); in.tie(nullptr); out << std::fixed; out.precision(20); solver.solve(in, out); return 0; }
replace
116
117
116
117
0
p03150
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main(void) { string s; cin >> s; int n = s.length(); bool flag = false; for (int i = 0; i <= n; ++i) { if (s.substr(0, i) + s.substr(n - (7 - i)) == string("keyence")) flag = true; } cout << (flag ? "YES" : "NO") << endl; return 0; }
#include <iostream> #include <string> using namespace std; int main(void) { string s; cin >> s; int n = s.length(); bool flag = false; for (int i = 0; i <= 7; ++i) { if (s.substr(0, i) + s.substr(n - (7 - i)) == string("keyence")) flag = true; } cout << (flag ? "YES" : "NO") << endl; return 0; }
replace
10
11
10
11
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr: __pos (which is 13) > this->size() (which is 12)
p03150
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string s, f, b, x; cin >> s; for (int i = 0; i < s.size() - 6; i++) { f = s.substr(0, i - 0); b = s.substr(f.size() + (s.size() - 7), s.size() - (s.size() - 7 + f.size())); x = f + b; // cout<<f<<" "<<b<<endl; if (x == "keyence") { cout << "YES" << endl; return 0; } } cout << "NO" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string s, f, b, x; cin >> s; for (int i = 0; i < 8; i++) { f = s.substr(0, i - 0); b = s.substr(f.size() + (s.size() - 7), s.size() - (s.size() - 7 + f.size())); x = f + b; // cout<<f<<" "<<b<<endl; if (x == "keyence") { cout << "YES" << endl; return 0; } } cout << "NO" << endl; }
replace
6
7
6
7
0
p03150
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; bool f() { string s; cin >> s; string a = "keyence"; int l = s.size(); if (l < 7) return false; for (int i = 0; i < 8; i++) { if (s.substr(0, i) != a.substr(0, i)) continue; int j = 7 - i; if (s.substr(l - 1 - j, j) == a.substr(6 - j, j)) return true; } return false; } int main() { if (f()) cout << "YES" << endl; else cout << "NO" << endl; }
#include <bits/stdc++.h> using namespace std; bool f() { string s; cin >> s; string a = "keyence"; int l = s.size(); if (l < 7) return false; for (int i = 0; i < 8; i++) { if (s.substr(0, i) != a.substr(0, i)) continue; int j = 7 - i; if (s.substr(l - j, j) == a.substr(7 - j, j)) return true; } return false; } int main() { if (f()) cout << "YES" << endl; else cout << "NO" << endl; }
replace
14
15
14
15
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr: __pos (which is 18446744073709551615) > this->size() (which is 7)
p03150
C++
Runtime Error
#include <algorithm> #include <cmath> #include <ctype.h> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; #define dump(a) cout << (a) << '\n'; typedef long long Int; Int mod = 1e9 + 7; Int MOD = 998244353; int main() { ios::sync_with_stdio(false); string s; cin >> s; Int n = (Int)s.size(); bool res; for (Int i = 0; i < (Int)s.size() - 7; i++) { string t = s.substr(0, i); t = t + s.substr(n - (7 - i)); // dump(t); if (t == "keyence") { res = true; } } if (s == "keyence") res = true; dump(res ? "YES" : "NO"); return 0; }
#include <algorithm> #include <cmath> #include <ctype.h> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; #define dump(a) cout << (a) << '\n'; typedef long long Int; Int mod = 1e9 + 7; Int MOD = 998244353; int main() { ios::sync_with_stdio(false); string s; cin >> s; Int n = (Int)s.size(); bool res = false; for (Int i = 0; i <= 7; i++) { string t = s.substr(0, i); t = t + s.substr(n - (7 - i)); // dump(t); if (t == "keyence") { res = true; } } if (s == "keyence") res = true; dump(res ? "YES" : "NO"); return 0; }
replace
22
24
22
24
0
p03150
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define pb push_back #define sort(s) sort(s.begin(), s.end()) #define reverse(s) reverse(s.begin(), s.end()) #define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++) const ll mod = 1e9 + 7; // 最大公約数 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; } // 素数判定 bool isPrime(ll x) { ll i; if (x < 2) return 0; else if (x == 2) return 1; if (x % 2 == 0) return 0; for (i = 3; i * i <= x; i += 2) if (x % i == 0) return 0; return 1; } // 桁和 int digsum(ll n) { int res = 0; while (n > 0) { res += n % 10; n /= 10; } return res; } // 桁数 int dignum(ll n) { int res = 0; while (n > 0) { res++; n /= 10; } return res; } // 文字列中の特定の文字カウント ll stringcount(string s, char c) { return count(s.cbegin(), s.cend(), c); } // 階乗 ll ka(ll i) { ll res = 1; while (i > 0) { res = res * i; i--; } return res; } // ncr ll ncr(ll x, ll y) { ll a = x; ll b = 1; if (y > (x / 2)) { y = x - y; } for (ll i = 1; i < y; i++) { a *= x - i; b *= i + 1; } return a / b; } int main() { string s; cin >> s; string key = "keyence"; bool ok = false; if (key == s) ok = true; int x = s.size() - key.size(); for (int i = 0; i < x - 1; i++) { string t = s; t.erase(t.begin() + i, t.begin() + i + x); if (t == key) ok = true; } if (ok) cout << "YES" << endl; else cout << "NO" << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define pb push_back #define sort(s) sort(s.begin(), s.end()) #define reverse(s) reverse(s.begin(), s.end()) #define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++) const ll mod = 1e9 + 7; // 最大公約数 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; } // 素数判定 bool isPrime(ll x) { ll i; if (x < 2) return 0; else if (x == 2) return 1; if (x % 2 == 0) return 0; for (i = 3; i * i <= x; i += 2) if (x % i == 0) return 0; return 1; } // 桁和 int digsum(ll n) { int res = 0; while (n > 0) { res += n % 10; n /= 10; } return res; } // 桁数 int dignum(ll n) { int res = 0; while (n > 0) { res++; n /= 10; } return res; } // 文字列中の特定の文字カウント ll stringcount(string s, char c) { return count(s.cbegin(), s.cend(), c); } // 階乗 ll ka(ll i) { ll res = 1; while (i > 0) { res = res * i; i--; } return res; } // ncr ll ncr(ll x, ll y) { ll a = x; ll b = 1; if (y > (x / 2)) { y = x - y; } for (ll i = 1; i < y; i++) { a *= x - i; b *= i + 1; } return a / b; } int main() { string s; cin >> s; string key = "keyence"; bool ok = false; for (int i = 0; i < s.size(); i++) { for (int j = 0; j < s.size() - i; j++) { string t = s; t.erase(i, j); if (t == key) ok = true; } } if (ok) cout << "YES" << endl; else cout << "NO" << endl; }
replace
87
97
87
94
0
p03150
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { string s; bool f = 0; cin >> s; if (s == "keyence") f = 1; else if (s.size() > 7) { for (int i = 0; i < s.size() - 7; i++) { string t = s.substr(0, i) + s.substr(i + s.size() - 7, s.size()); if (t == "keyence") { f = 1; break; } } } if (f) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
#include <iostream> #include <string> using namespace std; int main() { string s; bool f = 0; cin >> s; if (s == "keyence") f = 1; else if (s.size() > 7) { for (int i = 0; i < 7; i++) { string t = s.substr(0, i) + s.substr(i + s.size() - 7, s.size()); if (t == "keyence") { f = 1; break; } } } if (f) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
replace
13
14
13
14
0
p03150
C++
Runtime Error
#include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <functional> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define FOR(x, xs) for (auto &x : xs) using namespace std; typedef long long ll; typedef pair<int, int> PI; typedef pair<ll, ll> PL; typedef vector<int> VI; typedef vector<ll> VL; template <class T, template <class, class> class C, class charT = char> void vdump(const C<T, allocator<T>> &v, const charT *delimiter = ", ", ostream &stream = cout) { copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter)); stream << endl; } int main() { ios::sync_with_stdio(false); string target = "keyence"; string s; cin >> s; int n = s.size(); REP(i, 0, n - 7) { if (s.substr(0, i) + s.substr(n - 7 + i) == target) { cout << "YES" << endl; return 0; } } cout << "NO" << endl; return 0; }
#include <algorithm> #include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <functional> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> #define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define FOR(x, xs) for (auto &x : xs) using namespace std; typedef long long ll; typedef pair<int, int> PI; typedef pair<ll, ll> PL; typedef vector<int> VI; typedef vector<ll> VL; template <class T, template <class, class> class C, class charT = char> void vdump(const C<T, allocator<T>> &v, const charT *delimiter = ", ", ostream &stream = cout) { copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter)); stream << endl; } int main() { ios::sync_with_stdio(false); string target = "keyence"; string s; cin >> s; int n = s.size(); REP(i, 0, 8) { if (s.substr(0, i) + s.substr(n - 7 + i) == target) { cout << "YES" << endl; return 0; } } cout << "NO" << endl; return 0; }
replace
42
43
42
43
0
p03150
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef vector<ll> vl; typedef vector<string> vs; typedef vector<char> vc; typedef queue<ll> ql; typedef deque<ll> dql; typedef priority_queue<ll, vl /*, greater<ll>*/> pql; // 降順(/*昇順*/) typedef set<ll> sl; typedef pair<ll, ll> pl; typedef vector<vl> vvl; typedef vector<pl> vpl; #define rep(i, n) for (ll i = 0; i < ll(n); ++i) #define rep2(i, n) for (ll i = 1; i <= ll(n); ++i) // #define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i) // #define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i) #define all(v) (v).begin(), (v).end() bool chmin(ll &a, ll b) { if (b < a) { a = b; return 1; } return 0; } bool chmax(ll &a, ll b) { if (b > a) { a = b; return 1; } return 0; } const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; const ll MAX = 1e9; const char newl = '\n'; int main() { ios::sync_with_stdio(false); cin.tie(0); string S; cin >> S; if (S.size() >= 7) { rep(i, 8) { if (S.substr(0, i) + S.substr(S.size() - 8 + i) == "keyence") goto ABLE; } } cout << "NO" << newl; return 0; ABLE: cout << "YES" << newl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef vector<ll> vl; typedef vector<string> vs; typedef vector<char> vc; typedef queue<ll> ql; typedef deque<ll> dql; typedef priority_queue<ll, vl /*, greater<ll>*/> pql; // 降順(/*昇順*/) typedef set<ll> sl; typedef pair<ll, ll> pl; typedef vector<vl> vvl; typedef vector<pl> vpl; #define rep(i, n) for (ll i = 0; i < ll(n); ++i) #define rep2(i, n) for (ll i = 1; i <= ll(n); ++i) // #define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i) // #define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i) #define all(v) (v).begin(), (v).end() bool chmin(ll &a, ll b) { if (b < a) { a = b; return 1; } return 0; } bool chmax(ll &a, ll b) { if (b > a) { a = b; return 1; } return 0; } const ll INF = 1LL << 60; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; const ll MAX = 1e9; const char newl = '\n'; int main() { ios::sync_with_stdio(false); cin.tie(0); string S; cin >> S; rep(i, 8) { if (S.substr(0, i) + S.substr(S.size() - 7 + i) == "keyence") goto ABLE; } cout << "NO" << newl; return 0; ABLE: cout << "YES" << newl; return 0; }
replace
45
50
45
48
0
p03150
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using pa = pair<ll, ll>; using vl = vector<ll>; using vvl = vector<vector<ll>>; const ll MOD = 1e9 + 7; const ll INF = 1e14; const long double EPS = 1e-11; #define eb emplace_back #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (n); i++) #define repr(i, n) for (int i = (n)-1; i >= 0; i--) #define repe(i, l, r) for (int i = (l); i < (r); i++) #define reper(i, l, r) for (int i = (r)-1; i >= (l); i--) void init() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } //--------------------------------------------------------------------------------// int main() { init(); string s, k = "keyence"; cin >> s; int N = s.size(); bool isok = false; rep(i, N - 7) { string t = s.substr(0, i) + s.substr(N - 7 + i, 7 - i); // cout << s.substr(0, i) << " " << s.substr(N - 7 + i, 7 - i) << endl; if (t == k) { isok = true; break; } } cout << (isok ? "YES" : "NO") << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pa = pair<ll, ll>; using vl = vector<ll>; using vvl = vector<vector<ll>>; const ll MOD = 1e9 + 7; const ll INF = 1e14; const long double EPS = 1e-11; #define eb emplace_back #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (n); i++) #define repr(i, n) for (int i = (n)-1; i >= 0; i--) #define repe(i, l, r) for (int i = (l); i < (r); i++) #define reper(i, l, r) for (int i = (r)-1; i >= (l); i--) void init() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } //--------------------------------------------------------------------------------// int main() { init(); string s, k = "keyence"; cin >> s; int N = s.size(); bool isok = false; rep(i, 8) { string t = s.substr(0, i) + s.substr(N - 7 + i, 7 - i); // cout << s.substr(0, i) << " " << s.substr(N - 7 + i, 7 - i) << endl; if (t == k) { isok = true; break; } } cout << (isok ? "YES" : "NO") << endl; return 0; }
replace
30
31
30
31
0
p03150
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { string S; cin >> S; int N = S.size(); int subN = N - 7; if (subN < 0) { cout << "NO" << endl; return 0; } for (int i = 0; i < N; i++) { string first = S.substr(0, i); string middle = S.substr(i, subN); string last = S.substr(i + subN); string ans = first + last; // cout << ans << endl; if (ans == "keyence") { cout << "YES" << endl; return 0; } } cout << "NO" << endl; return 0; }
#include <iostream> #include <string> using namespace std; int main() { string S; cin >> S; int N = S.size(); int subN = N - 7; if (subN < 0) { cout << "NO" << endl; return 0; } for (int i = 0; i < N - subN + 1; i++) { string first = S.substr(0, i); string middle = S.substr(i, subN); string last = S.substr(i + subN); string ans = first + last; // cout << ans << endl; if (ans == "keyence") { cout << "YES" << endl; return 0; } } cout << "NO" << endl; return 0; }
replace
12
13
12
13
0
p03150
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long int ll; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) int main() { string s; cin >> s; // string key = "keyence"; int slen = s.size(); bool ans = false; if (s == "keyence") { cout << "YES" << endl; return 0; } for (int i = 1; i <= slen; i++) { for (int j = 0; j <= slen - i; j++) { if (s.erase(j, i) == "keyence") ans = true; } } if (ans) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long int ll; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) int main() { string s; cin >> s; // string key = "keyence"; int slen = s.size(); bool ans = false; if (s == "keyence") { cout << "YES" << endl; return 0; } for (int i = 1; i <= slen; i++) { for (int j = 0; j <= slen - i; j++) { string t = s; if (t.erase(j, i) == "keyence") ans = true; } } if (ans) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
replace
25
26
25
27
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::erase: __pos (which is 7) > this->size() (which is 6)
p03150
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { string s; cin >> s; int n = s.size(); for (int i = 0; i <= n - 7; i++) { string t = s.substr(0, i) + s.substr(n - 7 + i, n); if (t == "keyence") { cout << "YES" << endl; return 0; } } cout << "NO" << endl; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { string s; cin >> s; int n = s.size(); for (int i = 0; i <= 7; i++) { string t = s.substr(0, i) + s.substr(n - 7 + i); if (t == "keyence") { cout << "YES" << endl; return 0; } } cout << "NO" << endl; return 0; }
replace
8
10
8
10
0
p03150
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair int main() { string k = "keyence"; string t; cin >> t; if (t.size() < k.size()) return 0 * printf("NO\n"); for (int i = 0; i < t.size() - k.size() + 1; i++) { string s = t.substr(0, i) + t.substr(t.size() - k.size() + i, k.size() - i); if (s == k) return 0 * printf("YES\n"); } printf("NO\n"); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mp make_pair int main() { string k = "keyence"; string t; cin >> t; if (t.size() < k.size()) return 0 * printf("NO\n"); for (int i = 0; i < k.size() + 1; i++) { string s = t.substr(0, i) + t.substr(t.size() - k.size() + i, k.size() - i); if (s == k) return 0 * printf("YES\n"); } printf("NO\n"); return 0; }
replace
12
13
12
13
0
p03150
Python
Runtime Error
from re import fullmatch S = input() _s = "keyence" flag = False for i in range(len(_s)): if fullmatch(f".*{_s[:i]}.*{_s[i:]}.*", S): flag = True print("YES") if flag else print("NO")
from re import fullmatch S = input() _s = "keyence" flag = False for i in range(len(_s)): tmp = fullmatch("(.*)" + _s[:i] + "(.*)" + _s[i:] + "(.*)", S) if tmp and sum([1 for j in range(1, 4) if tmp.group(j)]) <= 1: flag = True print("YES") if flag else print("NO")
replace
6
7
6
8
0
p03150
Python
Runtime Error
S = str(input()) s = input() for i in range(len(s)): for j in range(i, len(s)): a = s[:i] + s[j:] if a == "keyence": print("YES") exit() print("NO")
s = str(input()) for i in range(len(s)): for j in range(i, len(s)): a = s[:i] + s[j:] if a == "keyence": print("YES") exit() print("NO")
replace
0
2
0
1
EOFError: EOF when reading a line
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03150/Python/s743625929.py", line 2, in <module> s = input() EOFError: EOF when reading a line
p03150
Python
Runtime Error
N = input() S = "keyence" index = 0 for item in N: if S[index] == item: index += 1 print("YES" if index == len(S) else "NO")
N = input() S = "keyence" if S == N[: len(S)]: print("YES") elif S == N[-len(S) :]: print("YES") else: for index in range(len(S)): if S[:index] == N[:index] and S[-(len(S) - index) :] == N[-(len(S) - index) :]: print("YES") break else: print("NO")
replace
3
9
3
14
0
p03150
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int len = (int)(S.size()); bool ans = false; if (S.substr(0, 7) == "keyence" || S.substr(len - 7) == "keyence") ans = true; for (int i = 1; i < len - 1; i++) { string a = S.substr(0, i); string b = S.substr(len - 7 + i); if (a + b == "keyence") ans = true; } if (ans) cout << "YES" << endl; else cout << "NO" << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string S; cin >> S; int len = (int)(S.size()); bool ans = false; if (S.substr(0, 7) == "keyence" || S.substr(len - 7) == "keyence") ans = true; for (int i = 1; i < 7; i++) { string a = S.substr(0, i); string b = S.substr(len - 7 + i); if (a + b == "keyence") ans = true; } if (ans) cout << "YES" << endl; else cout << "NO" << endl; }
replace
11
12
11
12
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::substr: __pos (which is 13) > this->size() (which is 12)
p03150
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> p_int; typedef pair<ll, ll> p_ll; typedef tuple<ll, ll, ll> t3_ll; int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}; const ll inf = 1e9 + 7; int main() { string s; cin >> s; bool ok = false; for (int i = 0; i < 9; i++) { string x = s; x.erase(i, s.size() - 7); if (x == "keyence") { ok = true; } } if (ok) cout << "YES"; else cout << "NO"; cout << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> p_int; typedef pair<ll, ll> p_ll; typedef tuple<ll, ll, ll> t3_ll; int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; int prime[] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97}; const ll inf = 1e9 + 7; int main() { string s; cin >> s; bool ok = false; for (int i = 0; i < 7; i++) { string x = s; x.erase(i, s.size() - 7); if (x == "keyence") { ok = true; } } if (ok) cout << "YES"; else cout << "NO"; cout << endl; }
replace
16
17
16
17
0
p03150
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const char *key = "keyence"; const int keylen = 7; int main() { string str; cin >> str; int f, b; for (f = 0; key[f] == str.at(f); f++) ; for (b = 0; key[keylen - b - 1] == str.at(str.length() - b - 1); b++) ; cout << ((f + b) >= keylen ? "YES" : "NO") << endl; }
#include <bits/stdc++.h> using namespace std; const char *key = "keyence"; const int keylen = 7; int main() { string str; cin >> str; int f, b; for (f = 0; f < keylen; f++) { if (key[f] != str.at(f)) break; } for (b = 0; b < keylen; b++) { if (key[keylen - b - 1] != str.at(str.length() - b - 1)) break; } cout << ((f + b) >= keylen ? "YES" : "NO") << endl; }
replace
10
14
10
18
0
p03151
C++
Runtime Error
/* * じょえチャンネル * 高評価・チャンネル登録よろしくおねがいします! * https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ */ #include <bits/stdc++.h> // #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #define f(i, n) for (int i = 0; i < (n); i++) #define inf (int)(3e18) // here!!! // define int long long !!!!! #define int long long // define int long long !!!!! #define mod (int)((1e9) + 7) // constexpr int mod = 998244353ll; #define intt long long #define itn long long #define P pair<int, int> #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, n) for (int i = 1; i <= n; i++) #define ALL(v) v.begin(), v.end() using namespace std; // Library // モッドパウ inline int modpow(int x, int y, int m = mod) { int res = 1; while (y) { if (y % 2) { res *= x; res %= m; } x = x * x % m; y /= 2; } return res; } int mypow(int x, int y) { int res = 1; while (y) { if (y % 2) { res *= x; } x = x * x; y /= 2; } return res; } // is the number (x) a prime number? bool prime(int x) { for (int i = 2; i * i <= x; i++) { if (!(x % i)) { return false; } } return true; } // saidai-kouyakusuu inline int gcd(int x, int y) { if (!y) { return x; } return gcd(y, x % y); } // number of keta int keta(int x) { int ans = 0; while (x) { x /= 10; ans++; } return ans; } // sum of keta int ketasum(int x) { int ans = 0; while (x) { ans += x % 10; x /= 10; } return ans; } inline int lcm(int x, int y) { int ans = x / gcd(x, y) * y; return ans; } int twobeki(int x) { int ans = 0; while (1) { if (!(x & 1)) { ans++; x /= 2; } else { break; } } return ans; } template <class T, class U> inline bool chmax(T &lhs, const U &rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; } template <class T, class U> inline bool chmin(T &lhs, const U &rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; } void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } #define fin(i) scanf("%lld", &i) #define fout(i) printf("%lld", i) #define fendl printf("\n") int kai(int x, int y) { int res = 1; for (int i = x - y + 1; i <= x; i++) { res *= i; res %= mod; } return res; } int comb(int x, int y) { if (y > x) return 0; // cout<<kai(x, y)<<' '<<modpow(kai(y, y), mod - 2)<<endl; return kai(x, y) * modpow(kai(y, y), mod - 2) % mod; } // Library-End #define vecin(v) \ for (int i = 0; i < v.size(); i++) \ scanf("%lld", &v[i]); #define vecout(v) \ { \ for (int i = 0; i < (int)v.size(); i++) \ printf("%lld ", v[i]); \ printf("\n"); \ } // SegTree template <class T> class SegTree { int n; // 葉の数 vector<T> data; // データを格納するvector T def; // 初期値かつ単位元 function<T(T, T)> operation; // 区間クエリで使う処理 function<T(T, T)> update; // 点更新で使う処理 // 区間[a,b)の総和。ノードk=[l,r)に着目している。 T _query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return def; // 交差しない if (a <= l && r <= b) return data[k]; // a,l,r,bの順で完全に含まれる else { T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子 T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子 return operation(c1, c2); } } public: // _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数, // _update:更新関数 SegTree(size_t _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update) : def(_def), operation(_operation), update(_update) { n = 1; while (n < _n) { n *= 2; } data = vector<T>(2 * n - 1, def); } // 場所i(0-indexed)の値をxで更新 void change(int i, T x) { i += n - 1; data[i] = update(data[i], x); while (i > 0) { i = (i - 1) / 2; data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]); } } // [a, b)の区間クエリを実行 T query(int a, int b) { return _query(a, b, 0, 0, n); } // 添字でアクセス T operator[](int i) { return data[i + n - 1]; } }; #define R_MIN ([](long long a, long long b) { return min(a, b); }) #define R_MAX ([](long long a, long long b) { return max(a, b); }) #define R_SUM ([](long long a, long long b) { return a + b; }) #define NORMAL_UPDATE ([](long long a, long long b) { return b; }) #define ADD_UPDATE ([](long long a, long long b) { return a + b; }) #define MINUS_UPDATE ([](long long a, long long b) { return a - b; } class Union_Find { vector<int> par; vector<int> rankmy; vector<int> ookisa; public: Union_Find(int size) { par = vector<int>(size); rankmy = vector<int>(size); ookisa = vector<int>(size); for (int i = 0; i < size; i++) { par[i] = i; ookisa[i] = 1; } } int find(int x) { if (par[x] == x) { return x; } return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) { return; } if (rankmy[x] < rankmy[y]) { par[x] = y; ookisa[y] += ookisa[x]; ookisa[x] = 0; } else { par[y] = x; ookisa[x] += ookisa[y]; ookisa[y] = 0; if (rankmy[x] == rankmy[y]) { rankmy[x]++; } } } int size(int i) { i = find(i); return ookisa[i]; } bool same(int x, int y) { return find(x) == find(y); } }; // Union-Find-End int perm[1000005]; void init_perm() { perm[0] = 1; REP(i, 1000000) { perm[i] = perm[i - 1] * i % mod; } } int nCk(int x, int y) { return perm[x] * modpow(perm[x - y], mod - 2) % mod * modpow(perm[y], mod - 2) % mod; } double kyori(pair<int, int> f, pair<int, int> s) { double ans = 0; double t = fabs(f.first - s.first); double y = fabs(f.second - s.second); ans = sqrt(t * t + y * y); return ans; } inline string stringmax(string &x, string &y) { if (x.size() > y.size()) { return x; } if (x.size() < y.size()) { return y; } rep(i, x.size()) { if (x[i] > y[i]) { return x; } if (x[i] < y[i]) { return y; } } return x; } #define endl "\n" // interactive の時に注意!!! int n, a[100004], b[100004], ans, gou, p, h; vector<int> yo; signed main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cin >> n; rep(i, n) { cin >> a[i]; gou += a[i]; } rep(i, n) { cin >> b[i]; p += b[i]; } if (p > gou) { cout << -1 << endl; return 0; } rep(i, n) { if (a[i] < b[i]) { yo.emplace_back(b[i] - a[i]); } else { h += a[i] - b[i]; } } sort(ALL(yo)); while (h) { ans++; int s = min(h, yo.back()); h -= s; yo.back() -= s; yo.pop_back(); } cout << ans << endl; }
/* * じょえチャンネル * 高評価・チャンネル登録よろしくおねがいします! * https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ */ #include <bits/stdc++.h> // #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #define f(i, n) for (int i = 0; i < (n); i++) #define inf (int)(3e18) // here!!! // define int long long !!!!! #define int long long // define int long long !!!!! #define mod (int)((1e9) + 7) // constexpr int mod = 998244353ll; #define intt long long #define itn long long #define P pair<int, int> #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, n) for (int i = 1; i <= n; i++) #define ALL(v) v.begin(), v.end() using namespace std; // Library // モッドパウ inline int modpow(int x, int y, int m = mod) { int res = 1; while (y) { if (y % 2) { res *= x; res %= m; } x = x * x % m; y /= 2; } return res; } int mypow(int x, int y) { int res = 1; while (y) { if (y % 2) { res *= x; } x = x * x; y /= 2; } return res; } // is the number (x) a prime number? bool prime(int x) { for (int i = 2; i * i <= x; i++) { if (!(x % i)) { return false; } } return true; } // saidai-kouyakusuu inline int gcd(int x, int y) { if (!y) { return x; } return gcd(y, x % y); } // number of keta int keta(int x) { int ans = 0; while (x) { x /= 10; ans++; } return ans; } // sum of keta int ketasum(int x) { int ans = 0; while (x) { ans += x % 10; x /= 10; } return ans; } inline int lcm(int x, int y) { int ans = x / gcd(x, y) * y; return ans; } int twobeki(int x) { int ans = 0; while (1) { if (!(x & 1)) { ans++; x /= 2; } else { break; } } return ans; } template <class T, class U> inline bool chmax(T &lhs, const U &rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; } template <class T, class U> inline bool chmin(T &lhs, const U &rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; } void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } #define fin(i) scanf("%lld", &i) #define fout(i) printf("%lld", i) #define fendl printf("\n") int kai(int x, int y) { int res = 1; for (int i = x - y + 1; i <= x; i++) { res *= i; res %= mod; } return res; } int comb(int x, int y) { if (y > x) return 0; // cout<<kai(x, y)<<' '<<modpow(kai(y, y), mod - 2)<<endl; return kai(x, y) * modpow(kai(y, y), mod - 2) % mod; } // Library-End #define vecin(v) \ for (int i = 0; i < v.size(); i++) \ scanf("%lld", &v[i]); #define vecout(v) \ { \ for (int i = 0; i < (int)v.size(); i++) \ printf("%lld ", v[i]); \ printf("\n"); \ } // SegTree template <class T> class SegTree { int n; // 葉の数 vector<T> data; // データを格納するvector T def; // 初期値かつ単位元 function<T(T, T)> operation; // 区間クエリで使う処理 function<T(T, T)> update; // 点更新で使う処理 // 区間[a,b)の総和。ノードk=[l,r)に着目している。 T _query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) return def; // 交差しない if (a <= l && r <= b) return data[k]; // a,l,r,bの順で完全に含まれる else { T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子 T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子 return operation(c1, c2); } } public: // _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数, // _update:更新関数 SegTree(size_t _n, T _def, function<T(T, T)> _operation, function<T(T, T)> _update) : def(_def), operation(_operation), update(_update) { n = 1; while (n < _n) { n *= 2; } data = vector<T>(2 * n - 1, def); } // 場所i(0-indexed)の値をxで更新 void change(int i, T x) { i += n - 1; data[i] = update(data[i], x); while (i > 0) { i = (i - 1) / 2; data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]); } } // [a, b)の区間クエリを実行 T query(int a, int b) { return _query(a, b, 0, 0, n); } // 添字でアクセス T operator[](int i) { return data[i + n - 1]; } }; #define R_MIN ([](long long a, long long b) { return min(a, b); }) #define R_MAX ([](long long a, long long b) { return max(a, b); }) #define R_SUM ([](long long a, long long b) { return a + b; }) #define NORMAL_UPDATE ([](long long a, long long b) { return b; }) #define ADD_UPDATE ([](long long a, long long b) { return a + b; }) #define MINUS_UPDATE ([](long long a, long long b) { return a - b; } class Union_Find { vector<int> par; vector<int> rankmy; vector<int> ookisa; public: Union_Find(int size) { par = vector<int>(size); rankmy = vector<int>(size); ookisa = vector<int>(size); for (int i = 0; i < size; i++) { par[i] = i; ookisa[i] = 1; } } int find(int x) { if (par[x] == x) { return x; } return par[x] = find(par[x]); } void unite(int x, int y) { x = find(x); y = find(y); if (x == y) { return; } if (rankmy[x] < rankmy[y]) { par[x] = y; ookisa[y] += ookisa[x]; ookisa[x] = 0; } else { par[y] = x; ookisa[x] += ookisa[y]; ookisa[y] = 0; if (rankmy[x] == rankmy[y]) { rankmy[x]++; } } } int size(int i) { i = find(i); return ookisa[i]; } bool same(int x, int y) { return find(x) == find(y); } }; // Union-Find-End int perm[1000005]; void init_perm() { perm[0] = 1; REP(i, 1000000) { perm[i] = perm[i - 1] * i % mod; } } int nCk(int x, int y) { return perm[x] * modpow(perm[x - y], mod - 2) % mod * modpow(perm[y], mod - 2) % mod; } double kyori(pair<int, int> f, pair<int, int> s) { double ans = 0; double t = fabs(f.first - s.first); double y = fabs(f.second - s.second); ans = sqrt(t * t + y * y); return ans; } inline string stringmax(string &x, string &y) { if (x.size() > y.size()) { return x; } if (x.size() < y.size()) { return y; } rep(i, x.size()) { if (x[i] > y[i]) { return x; } if (x[i] < y[i]) { return y; } } return x; } #define endl "\n" // interactive の時に注意!!! int n, a[100004], b[100004], ans, gou, p, h; vector<int> yo; signed main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cin >> n; rep(i, n) { cin >> a[i]; gou += a[i]; } rep(i, n) { cin >> b[i]; p += b[i]; } if (p > gou) { cout << -1 << endl; return 0; } rep(i, n) { if (a[i] > b[i]) { yo.emplace_back(abs(a[i] - b[i])); } else if (a[i] != b[i]) { h += abs(b[i] - a[i]); ans++; } } sort(ALL(yo)); while (h) { ans++; int s = min(h, yo.back()); h -= s; yo.back() -= s; yo.pop_back(); } cout << ans << endl; }
replace
336
340
336
341
-6
munmap_chunk(): invalid pointer
p03151
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define uint unsigned int #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, a, b) for (int i = (a); i < (b); ++i) #define FORR(i, a, b) for (int i = (a); i >= (b); --i) #define ALL(a) (a).begin(), (a).end() #define ALLR(a) (a).rbegin(), (a).rend() #define SZ(a) ((int)(a).size()) #define PB(a) push_back(a) #define EMP emplace #define EMPB(...) emplace_back(__VA_ARGS__) #define MP(a, b) make_pair(a, b) #define MT(...) make_tuple(__VA_ARGS__) #define Bit(n) (1LL << (n)) using namespace std; using pii = pair<int, int>; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } const int MOD = 1000000007; const int INF = 1LL << 30; const double EPS = 1e-10; int N; int A[100010]; int B[100010]; signed main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(10); cin >> N; int sumA = 0, sumB = 0; REP(i, N) { cin >> A[i]; sumA += A[i]; } REP(i, N) { cin >> B[i]; sumB += B[i]; } if (sumA < sumB) { cout << -1 << endl; return 0; } vector<int> v, w; REP(i, N) { int tmp = A[i] - B[i]; if (tmp < 0) v.PB(tmp); else w.PB(tmp); } if (v.size() == 0) { cout << 0 << endl; return 0; } sort(ALL(v)); sort(ALLR(w)); int p = 0, q = 0; int ans = v.size() + 1; while (p < v.size()) { if (w[q] + v[p] > 0) { w[q] += v[p]; p++; } else { v[p] -= w[q]; if (v[p] == 0) p++; q++; ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define int long long #define uint unsigned int #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, a, b) for (int i = (a); i < (b); ++i) #define FORR(i, a, b) for (int i = (a); i >= (b); --i) #define ALL(a) (a).begin(), (a).end() #define ALLR(a) (a).rbegin(), (a).rend() #define SZ(a) ((int)(a).size()) #define PB(a) push_back(a) #define EMP emplace #define EMPB(...) emplace_back(__VA_ARGS__) #define MP(a, b) make_pair(a, b) #define MT(...) make_tuple(__VA_ARGS__) #define Bit(n) (1LL << (n)) using namespace std; using pii = pair<int, int>; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } const int MOD = 1000000007; const int INF = 1LL << 30; const double EPS = 1e-10; int N; int A[100010]; int B[100010]; signed main() { cin.tie(0); ios_base::sync_with_stdio(false); cout << fixed << setprecision(10); cin >> N; int sumA = 0, sumB = 0; REP(i, N) { cin >> A[i]; sumA += A[i]; } REP(i, N) { cin >> B[i]; sumB += B[i]; } if (sumA < sumB) { cout << -1 << endl; return 0; } vector<int> v, w; REP(i, N) { int tmp = A[i] - B[i]; if (tmp < 0) v.PB(tmp); else w.PB(tmp); } if (v.size() == 0) { cout << 0 << endl; return 0; } sort(ALL(v)); sort(ALLR(w)); int s = 0; REP(i, v.size()) s += -v[i]; int ans = v.size(); int t = 0; for (int i = 0; i < w.size(); i++) { t += w[i]; ans++; if (s <= t) break; } cout << ans << endl; return 0; }
replace
73
86
73
82
0
p03151
C++
Runtime Error
/*input 12 757232153 372327760 440075441 195848680 354974235 458054863 463477172 740174259 615762794 632963102 529866931 64991604 74164189 98239366 465611891 362739947 147060907 118867039 63189252 78303147 501410831 110823640 122948912 572905212 */ #include <bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0) #define ALL(a) a.begin(), a.end() #define SZ(a) ((int)a.size()) #define F first #define S second #define REP(i, n) for (int i = 0; i < ((int)n); i++) #define pb push_back #define MP(a, b) make_pair(a, b) #define SORT_UNIQUE(c) \ (sort(c.begin(), c.end()), \ c.resize(distance(c.begin(), unique(c.begin(), c.end())))) #define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin()) template <typename T1, typename T2> ostream &operator<<(ostream &out, pair<T1, T2> P) { out << '(' << P.F << ',' << P.S << ')'; return out; } //}}} const ll maxn = 300005; const ll maxlg = __lg(maxn) + 2; const ll INF64 = 8000000000000000000LL; const int INF = 0x3f3f3f3f; const ll MOD = ll(1e9 + 7); const double PI = acos(-1); // const ll p=880301; // const ll P=31; ll mypow(ll a, ll b) { ll res = 1LL; while (b) { if (b & 1) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } vector<int> v; int a[maxn], b[maxn]; int main() { IOS; int n; cin >> n; REP(i, n) cin >> a[i]; REP(i, n) cin >> b[i]; ll sum = 0; REP(i, n) sum += a[i]; REP(i, n) sum -= b[i]; if (sum < 0) { cout << -1 << '\n'; return 0; } REP(i, n) if (a[i] >= b[i]) v.pb(a[i] - b[i]); sort(ALL(v)); int pt = 0; while (sum >= v[pt]) { sum -= v[pt]; pt++; } cout << n - pt << '\n'; return 0; }
/*input 12 757232153 372327760 440075441 195848680 354974235 458054863 463477172 740174259 615762794 632963102 529866931 64991604 74164189 98239366 465611891 362739947 147060907 118867039 63189252 78303147 501410831 110823640 122948912 572905212 */ #include <bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<double, double> pdd; #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0) #define ALL(a) a.begin(), a.end() #define SZ(a) ((int)a.size()) #define F first #define S second #define REP(i, n) for (int i = 0; i < ((int)n); i++) #define pb push_back #define MP(a, b) make_pair(a, b) #define SORT_UNIQUE(c) \ (sort(c.begin(), c.end()), \ c.resize(distance(c.begin(), unique(c.begin(), c.end())))) #define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin()) template <typename T1, typename T2> ostream &operator<<(ostream &out, pair<T1, T2> P) { out << '(' << P.F << ',' << P.S << ')'; return out; } //}}} const ll maxn = 300005; const ll maxlg = __lg(maxn) + 2; const ll INF64 = 8000000000000000000LL; const int INF = 0x3f3f3f3f; const ll MOD = ll(1e9 + 7); const double PI = acos(-1); // const ll p=880301; // const ll P=31; ll mypow(ll a, ll b) { ll res = 1LL; while (b) { if (b & 1) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } vector<int> v; int a[maxn], b[maxn]; int main() { IOS; int n; cin >> n; REP(i, n) cin >> a[i]; REP(i, n) cin >> b[i]; ll sum = 0; REP(i, n) sum += a[i]; REP(i, n) sum -= b[i]; if (sum < 0) { cout << -1 << '\n'; return 0; } REP(i, n) if (a[i] >= b[i]) v.pb(a[i] - b[i]); sort(ALL(v)); int pt = 0; while (pt < SZ(v) && sum >= v[pt]) { sum -= v[pt]; pt++; } cout << n - pt << '\n'; return 0; }
replace
80
81
80
81
0
p03151
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; typedef long long ll; #define rep(i, j, n) for (ll i = j; i < (n); i++) #define CLR(mat, f) memset(mat, f, sizeof(mat)) #define IN(a, b, x) (a <= x && x < b) #define out(ans) cout << ans << endl typedef pair<ll, ll> P; const ll mod = 1e9 + 7; const int INF = 1000000; const double PI = 3.14159265359; int main() { ifstream in("12.txt"); cin.rdbuf(in.rdbuf()); ll n; cin >> n; ll a[n], b[n]; ll asum = 0, bsum = 0; rep(i, 0, n) { cin >> a[i]; asum += a[i]; } rep(i, 0, n) { cin >> b[i]; bsum += b[i]; } if (asum < bsum) { out(-1); return 0; } ll sum = 0; multiset<ll, greater<ll>> se; ll ans = 0; rep(i, 0, n) { if (a[i] < b[i]) { sum += b[i] - a[i]; ans++; } else if (a[i] > b[i]) { se.insert(a[i] - b[i]); } } if (sum == 0) { out(0); return 0; } // out(sum); for (multiset<ll, greater<ll>>::iterator itr = se.begin(); itr != se.end(); itr++) { sum -= *itr; ans++; if (sum <= 0) { out(ans); return 0; } } return 0; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; #define rep(i, j, n) for (ll i = j; i < (n); i++) #define CLR(mat, f) memset(mat, f, sizeof(mat)) #define IN(a, b, x) (a <= x && x < b) #define out(ans) cout << ans << endl typedef pair<ll, ll> P; const ll mod = 1e9 + 7; const int INF = 1000000; const double PI = 3.14159265359; int main() { // ifstream in("12.txt"); // cin.rdbuf(in.rdbuf()); ll n; cin >> n; ll a[n], b[n]; ll asum = 0, bsum = 0; rep(i, 0, n) { cin >> a[i]; asum += a[i]; } rep(i, 0, n) { cin >> b[i]; bsum += b[i]; } if (asum < bsum) { out(-1); return 0; } ll sum = 0; multiset<ll, greater<ll>> se; ll ans = 0; rep(i, 0, n) { if (a[i] < b[i]) { sum += b[i] - a[i]; ans++; } else if (a[i] > b[i]) { se.insert(a[i] - b[i]); } } if (sum == 0) { out(0); return 0; } // out(sum); for (multiset<ll, greater<ll>>::iterator itr = se.begin(); itr != se.end(); itr++) { sum -= *itr; ans++; if (sum <= 0) { out(ans); return 0; } } return 0; }
replace
15
17
15
17
-11
p03151
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; pair<int, int> a[N]; bool cmp(pair<int, int> a, pair<int, int> b) { return a.first - a.second > b.first - b.second; } int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i].first; for (int i = 0; i < n; i++) cin >> a[i].second; long long cnt1 = 0, cnt2 = 0; for (int i = 0; i < n; i++) { cnt1 += a[i].first; cnt2 += a[i].second; } if (cnt1 < cnt2) cout << -1 << endl; else { sort(a, a + n, cmp); int st = 0, en = n - 1, ans = 0; bool flag = true, flag2 = true; while (st < en) { if (a[en].first < a[en].second) { if (flag2) { ans++; flag2 = false; } if (flag) { ans++; flag = false; } while (a[en].first < a[en].second && a[st].first > a[st].second) { a[en].first++; a[st].first--; } if (a[st].first == a[st].second) { st++; flag = true; } if (a[en].first == a[en].second) { en--; flag2 = true; } } else break; } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; pair<int, int> a[N]; bool cmp(pair<int, int> a, pair<int, int> b) { return a.first - a.second > b.first - b.second; } int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i].first; for (int i = 0; i < n; i++) cin >> a[i].second; long long cnt1 = 0, cnt2 = 0; for (int i = 0; i < n; i++) { cnt1 += a[i].first; cnt2 += a[i].second; } if (cnt1 < cnt2) cout << -1 << endl; else { sort(a, a + n, cmp); int st = 0, en = n - 1, ans = 0; bool flag = true, flag2 = true; while (st < en) { if (a[en].first < a[en].second) { if (flag2) { ans++; flag2 = false; } if (flag) { ans++; flag = false; } if (a[en].second - a[en].first < a[st].first - a[st].second) { a[st].first -= a[en].second - a[en].first; a[en].first = a[en].second; } else { a[en].first += a[st].first - a[st].second; a[st].first = a[st].second; } if (a[st].first == a[st].second) { st++; flag = true; } if (a[en].first == a[en].second) { en--; flag2 = true; } } else break; } cout << ans << endl; } }
replace
38
41
38
44
TLE
p03151
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) 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; } const long long MOD = 1000000007; typedef long long ll; ll n; string s, t; ll a[10005], b[100005], c[100005]; int main() { cin >> n; rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; ll ans = 0, sum = 0; rep(i, n) { c[i] = a[i] - b[i]; if (c[i] < 0) ans++, sum += c[i]; } sort(c, c + n, greater<ll>()); rep(i, n) if (c[i] > 0 && sum < 0) sum += c[i], ans++; cout << (sum >= 0 ? ans : -1) << endl; }
#include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) 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; } const long long MOD = 1000000007; typedef long long ll; ll n; string s, t; ll a[100005], b[100005], c[100005]; int main() { cin >> n; rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; ll ans = 0, sum = 0; rep(i, n) { c[i] = a[i] - b[i]; if (c[i] < 0) ans++, sum += c[i]; } sort(c, c + n, greater<ll>()); rep(i, n) if (c[i] > 0 && sum < 0) sum += c[i], ans++; cout << (sum >= 0 ? ans : -1) << endl; }
replace
23
24
23
24
0
p03151
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> #define llint long long using namespace std; llint n; llint a[10005], b[10005]; vector<llint> vec; int main(void) { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; llint sum = 0, ans = 0, need = 0; for (int i = 0; i < n; i++) { sum += a[i] - b[i]; if (b[i] > a[i]) { ans++; need += b[i] - a[i]; } if (b[i] < a[i]) { vec.push_back(a[i] - b[i]); } } if (sum < 0) { cout << -1 << endl; return 0; } sort(vec.rbegin(), vec.rend()); for (int i = 0; i < vec.size(); i++) { if (need <= 0) break; ans++; need -= vec[i]; } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <vector> #define llint long long using namespace std; llint n; llint a[100005], b[100005]; vector<llint> vec; int main(void) { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; llint sum = 0, ans = 0, need = 0; for (int i = 0; i < n; i++) { sum += a[i] - b[i]; if (b[i] > a[i]) { ans++; need += b[i] - a[i]; } if (b[i] < a[i]) { vec.push_back(a[i] - b[i]); } } if (sum < 0) { cout << -1 << endl; return 0; } sort(vec.rbegin(), vec.rend()); for (int i = 0; i < vec.size(); i++) { if (need <= 0) break; ans++; need -= vec[i]; } cout << ans << endl; return 0; }
replace
8
9
8
9
0
p03151
C++
Runtime Error
#pragma GCC optimize(2) #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1000; int a[N], b[N], c[N]; inline int read() { int x = 0, f = 1; char ch = getchar(); for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -1; for (; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + ch - '0'; return x * f; } bool cmp(ll p, ll q) { return p > q; } int main() { int n = read(), cnt = 0, ans = 0; ll sum = 0; for (int i = 1; i <= n; i++) a[i] = read(); for (int i = 1; i <= n; i++) b[i] = read(); for (int i = 1; i <= n; i++) { if (a[i] > b[i]) c[++cnt] = a[i] - b[i]; else if (a[i] < b[i]) { ans++; sum += (b[i] - a[i]); } } if (sum == 0) { puts("0"); return 0; } sort(c + 1, c + 1 + cnt, cmp); for (int i = 1; i <= cnt; i++) { if (sum >= c[i]) sum -= c[i]; else sum = 0; ans++; if (sum == 0) break; } if (sum) puts("-1"); else printf("%d\n", ans); return 0; }
#pragma GCC optimize(2) #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 100005; int a[N], b[N], c[N]; inline int read() { int x = 0, f = 1; char ch = getchar(); for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -1; for (; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + ch - '0'; return x * f; } bool cmp(ll p, ll q) { return p > q; } int main() { int n = read(), cnt = 0, ans = 0; ll sum = 0; for (int i = 1; i <= n; i++) a[i] = read(); for (int i = 1; i <= n; i++) b[i] = read(); for (int i = 1; i <= n; i++) { if (a[i] > b[i]) c[++cnt] = a[i] - b[i]; else if (a[i] < b[i]) { ans++; sum += (b[i] - a[i]); } } if (sum == 0) { puts("0"); return 0; } sort(c + 1, c + 1 + cnt, cmp); for (int i = 1; i <= cnt; i++) { if (sum >= c[i]) sum -= c[i]; else sum = 0; ans++; if (sum == 0) break; } if (sum) puts("-1"); else printf("%d\n", ans); return 0; }
replace
4
5
4
5
0
p03151
C++
Runtime Error
#include <algorithm> #include <iostream> int main() { long long N, A[100], B[100], SumA = 0, SumB = 0, C[100], rest = 0, result = 0; std::cin >> N; for (int i = 0; i < N; i++) { std::cin >> A[i]; SumA += A[i]; } for (int i = 0; i < N; i++) { std::cin >> B[i]; SumB += B[i]; C[i] = A[i] - B[i]; } if (SumA < SumB) { std::cout << -1; return 0; } std::sort(C, C + N); int i = 0, j = N - 1; while (C[i] < 0) { rest += C[j]; result++; while (rest > 0 && C[i] < 0) { rest += C[i]; result++; i++; } j--; } if (rest < 0) std::cout << result + 1; else std::cout << result; return 0; }
#include <algorithm> #include <iostream> int main() { long long N, A[100000], B[100000], SumA = 0, SumB = 0, C[100000], rest = 0, result = 0; std::cin >> N; for (int i = 0; i < N; i++) { std::cin >> A[i]; SumA += A[i]; } for (int i = 0; i < N; i++) { std::cin >> B[i]; SumB += B[i]; C[i] = A[i] - B[i]; } if (SumA < SumB) { std::cout << -1; return 0; } std::sort(C, C + N); int i = 0, j = N - 1; while (C[i] < 0) { rest += C[j]; result++; while (rest > 0 && C[i] < 0) { rest += C[i]; result++; i++; } j--; } if (rest < 0) std::cout << result + 1; else std::cout << result; return 0; }
replace
3
4
3
5
0
p03151
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long A[20000]; long B[20000]; long d[20000]; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; for (int n = 0; n < N; n++) cin >> A[n]; for (int n = 0; n < N; n++) cin >> B[n]; for (int n = 0; n < N; n++) d[n] = A[n] - B[n]; int num = 0, m = N, sp = 0; sort(d, d + N); for (int n = 0; n < N; n++) { if (d[n] >= 0) { num = n + (N - m); break; } sp += d[n]; while (sp < 0) { m--; if (d[m] < 0 || m <= n) { num = -1; break; } sp += d[m]; } if (num == -1) break; } cout << num << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; long A[200000]; long B[200000]; long d[200000]; int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; for (int n = 0; n < N; n++) cin >> A[n]; for (int n = 0; n < N; n++) cin >> B[n]; for (int n = 0; n < N; n++) d[n] = A[n] - B[n]; int num = 0, m = N, sp = 0; sort(d, d + N); for (int n = 0; n < N; n++) { if (d[n] >= 0) { num = n + (N - m); break; } sp += d[n]; while (sp < 0) { m--; if (d[m] < 0 || m <= n) { num = -1; break; } sp += d[m]; } if (num == -1) break; } cout << num << "\n"; return 0; }
replace
3
6
3
6
0
p03151
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (n); i++) #define mp(x, y) make_pair(x, y) #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; using vin = vector<int>; using P = pair<int, int>; const int inf = 1e9 + 7; const ll INF = 1e18; int main() { int n; cin >> n; vin a(n), b(n); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; ////////総和 少ない数をカウント ll aSum = 0, bSum = 0; bool ok = true; rep(i, n) { aSum += a[i]; bSum += b[i]; } if (aSum < bSum) ok = false; ll cnt = 0; ll husoku = 0; priority_queue<int, vector<int>, less<int>> q; rep(i, n) { if (a[i] < b[i]) { cnt++; husoku += (b[i] - a[i]); } else { q.push(a[i] - b[i]); } } while (husoku > 0) { cnt++; husoku -= q.top(); q.pop(); } if (ok) cout << cnt << endl; else cout << -1 << endl; }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG #define rep(i, n) for (int i = 0; i < (n); i++) #define mp(x, y) make_pair(x, y) #define all(x) (x).begin(), (x).end() using namespace std; using ll = long long; using vin = vector<int>; using P = pair<int, int>; const int inf = 1e9 + 7; const ll INF = 1e18; int main() { int n; cin >> n; vin a(n), b(n); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; ////////総和 少ない数をカウント ll aSum = 0, bSum = 0; bool ok = true; rep(i, n) { aSum += a[i]; bSum += b[i]; } if (aSum < bSum) ok = false; ll cnt = 0; ll husoku = 0; priority_queue<int, vector<int>, less<int>> q; rep(i, n) { if (a[i] < b[i]) { cnt++; husoku += (b[i] - a[i]); } else { q.push(a[i] - b[i]); } } if (ok) { while (husoku > 0) { cnt++; husoku -= q.top(); q.pop(); } } if (ok) cout << cnt << endl; else cout << -1 << endl; }
replace
38
42
38
44
TLE
p03151
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <tuple> #include <utility> #include <vector> #define int long long int #define rep(i, n) for (int i = 0; i < (n); ++i) #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) using namespace std; typedef pair<int, int> P; const int INF = 1e15; const int MOD = 1e9 + 7; bool compare(P a, P b) { return a.first - a.second < b.first - b.first; } signed main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n), b(n); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; vector<P> x(n); rep(i, n) x[i] = {a[i], b[i]}; sort(ALL(x), compare); int sum = 0; int s = -1; rep(i, n) { if (x[i].first >= x[i].second) { break; } sum += x[i].second - x[i].first; s = i; } int t = -1; for (int i = n - 1; i >= 0; i--) { if (x[i].first <= x[i].second) { break; } if (sum <= 0) { break; } sum -= x[i].first - x[i].second; t = i; } if (sum > 0) { cout << -1 << endl; return 0; } if (s == -1 || t == -1) { cout << 0 << endl; } else { cout << s + 1 + n - t << endl; } return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <tuple> #include <utility> #include <vector> #define int long long int #define rep(i, n) for (int i = 0; i < (n); ++i) #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) using namespace std; typedef pair<int, int> P; const int INF = 1e15; const int MOD = 1e9 + 7; bool compare(P a, P b) { return a.first - a.second < b.first - b.second; } signed main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<int> a(n), b(n); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; vector<P> x(n); rep(i, n) x[i] = {a[i], b[i]}; sort(ALL(x), compare); int sum = 0; int s = -1; rep(i, n) { if (x[i].first >= x[i].second) { break; } sum += x[i].second - x[i].first; s = i; } int t = -1; for (int i = n - 1; i >= 0; i--) { if (x[i].first <= x[i].second) { break; } if (sum <= 0) { break; } sum -= x[i].first - x[i].second; t = i; } if (sum > 0) { cout << -1 << endl; return 0; } if (s == -1 || t == -1) { cout << 0 << endl; } else { cout << s + 1 + n - t << endl; } return 0; }
replace
28
29
28
29
TLE
p03151
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ll long long #define f(i, x, n) for (int i = x; i < (int)(n); ++i) int const N = 100000; int a[N + 1], b[N]; int main() { int n; scanf("%d", &n); f(i, 0, n) scanf("%d", a + i); f(i, 0, n) scanf("%d", b + i); ll c = 0; f(i, 0, n) c += b[i] - a[i]; if (c > 1) { printf("-1\n"); return 0; } f(i, 0, n) a[i] -= b[i]; sort(a, a + n); int j = n, an = 0; f(i, 0, n) if (a[i] < 0) { ++an; while (a[i] < 0) { if (a[j] == 0) --j; int z = min(-a[i], a[j]); a[i] += z; a[j] -= z; } } printf("%d\n", an + n - j); }
#include <bits/stdc++.h> using namespace std; #define ll long long #define f(i, x, n) for (int i = x; i < (int)(n); ++i) int const N = 100000; int a[N + 1], b[N]; int main() { int n; scanf("%d", &n); f(i, 0, n) scanf("%d", a + i); f(i, 0, n) scanf("%d", b + i); ll c = 0; f(i, 0, n) c += b[i] - a[i]; if (c > 0) { printf("-1\n"); return 0; } f(i, 0, n) a[i] -= b[i]; sort(a, a + n); int j = n, an = 0; f(i, 0, n) if (a[i] < 0) { ++an; while (a[i] < 0) { if (a[j] == 0) --j; int z = min(-a[i], a[j]); a[i] += z; a[j] -= z; } } printf("%d\n", an + n - j); }
replace
15
16
15
16
TLE
p03151
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int> a(n), b(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } vector<int64_t> plus; int64_t sumOfMinus = 0; int ans = 0; for (int i = 0; i < n; i++) { int64_t diff = a[i] - b[i]; if (diff < (int64_t)0) { sumOfMinus -= diff; ans++; } else if (diff > (int64_t)0) { plus.push_back(diff); } } sort(plus.rbegin(), plus.rend()); for (int i = 0; i < n && sumOfMinus > (int64_t)0; i++) { sumOfMinus -= plus[i]; ans++; } if (sumOfMinus > (int64_t)0) ans = -1; cout << ans << endl; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { int n; cin >> n; vector<int> a(n), b(n); for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n; i++) { cin >> b[i]; } vector<int64_t> plus; int64_t sumOfMinus = 0; int ans = 0; for (int i = 0; i < n; i++) { int64_t diff = a[i] - b[i]; if (diff < (int64_t)0) { sumOfMinus -= diff; ans++; } else if (diff > (int64_t)0) { plus.push_back(diff); } } sort(plus.rbegin(), plus.rend()); for (int i = 0; i < plus.size() && sumOfMinus > (int64_t)0; i++) { sumOfMinus -= plus[i]; ans++; } if (sumOfMinus > (int64_t)0) ans = -1; cout << ans << endl; }
replace
29
30
29
30
0
p03151
C++
Runtime Error
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> // #include<bits/extc++.h> using namespace std; // using namespace __gnu_pbds; // typedef // tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> // set_t; #define mp(a, b) make_pair((a), (b)) #define pii pair<int, int> #define pll pair<LL, LL> #define pdd pair<double, double> #define pb push_back #define x first #define y second #define sqr(x) ((x) * (x)) #define EPS 1e-6 #define MEM(x) memset(x, 0, sizeof(x)) #define MEMS(x) memset(x, -1, sizeof(x)) #define pi acos(-1) #define index Index #define Line pll typedef long long LL; int main() { int n; scanf("%d", &n); int a[105]; int b[105]; LL sum = 0; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); sum += a[i]; } for (int i = 0; i < n; i++) { scanf("%d", &b[i]); a[i] -= b[i]; sum -= b[i]; } if (sum < 0) { printf("-1\n"); return 0; } sort(a, a + n); int ori = a[n - 1]; int r = n - 1; for (int i = 0; i < n; i++) { if (a[i] >= 0) { if (a[r] == ori) printf("%d\n", n - (r - i + 1)); else printf("%d\n", n - (r - i)); break; } while (a[i] < 0) { a[i] += a[r]; if (a[i] < 0) { r--; ori = a[r]; } else { a[r] = a[i]; } } } }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> // #include<bits/extc++.h> using namespace std; // using namespace __gnu_pbds; // typedef // tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> // set_t; #define mp(a, b) make_pair((a), (b)) #define pii pair<int, int> #define pll pair<LL, LL> #define pdd pair<double, double> #define pb push_back #define x first #define y second #define sqr(x) ((x) * (x)) #define EPS 1e-6 #define MEM(x) memset(x, 0, sizeof(x)) #define MEMS(x) memset(x, -1, sizeof(x)) #define pi acos(-1) #define index Index #define Line pll typedef long long LL; int main() { int n; scanf("%d", &n); int a[100005]; int b[100005]; LL sum = 0; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); sum += a[i]; } for (int i = 0; i < n; i++) { scanf("%d", &b[i]); a[i] -= b[i]; sum -= b[i]; } if (sum < 0) { printf("-1\n"); return 0; } sort(a, a + n); int ori = a[n - 1]; int r = n - 1; for (int i = 0; i < n; i++) { if (a[i] >= 0) { if (a[r] == ori) printf("%d\n", n - (r - i + 1)); else printf("%d\n", n - (r - i)); break; } while (a[i] < 0) { a[i] += a[r]; if (a[i] < 0) { r--; ori = a[r]; } else { a[r] = a[i]; } } } }
replace
26
28
26
28
0
p03151
C++
Runtime Error
#include <bits/stdc++.h> #define rep2(x, fr, to) for (int(x) = (fr); (x) < (to); (x)++) #define rep(x, to) for (int(x) = 0; (x) < (to); (x)++) #define repr(x, fr, to) for (int(x) = (fr); (x) >= (to); (x)--) #define all(c) (c).begin(), (c).end() #define sz(v) (int)(v).size() using namespace std; typedef long long ll; typedef vector<ll> VI; typedef pair<ll, ll> pii; const int mod = (int)1e9 + 7; void dbg() { cerr << "\n"; } template <typename T, typename... T2> void dbg(const T &fst, const T2 &...rst) { cerr << fst << ": "; dbg(rst...); } template <class T> void amin(T &a, T b) { a = min(a, b); } template <class T> void amax(T &a, T b) { a = max(a, b); } int main() { // cin.tie(0); ios_base::sync_with_stdio(false); int n; cin >> n; VI a(n), b(n); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; bool ok = true; rep(i, n) if (a[i] < b[i]) ok = false; if (ok) { puts("0"); return 0; } ll sma = accumulate(all(a), 0LL); ll smb = accumulate(all(b), 0LL); if (smb > sma) { puts("-1"); return 0; } VI odf(n), pdf, mdf; rep(i, n) odf[i] = a[i] - b[i]; sort(all(odf)); reverse(all(odf)); rep(i, n)(odf[i] >= 0 ? pdf : mdf).push_back(odf[i]); int ans = 0; rep(i, sz(pdf)) { ll zf = pdf[i]; repr(j, sz(mdf) - 1, 0) { if (mdf[j] >= 0 || zf <= 0) break; if (mdf[j] + zf >= 0) { zf += mdf[j]; mdf[j] = 0; ans++; } else { mdf[j] += zf; zf = 0; } } if (zf != pdf[i]) { pdf[i] = 0; ans++; } while (mdf.back() >= 0) mdf.pop_back(); if (sz(mdf) == 0) break; } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> #define rep2(x, fr, to) for (int(x) = (fr); (x) < (to); (x)++) #define rep(x, to) for (int(x) = 0; (x) < (to); (x)++) #define repr(x, fr, to) for (int(x) = (fr); (x) >= (to); (x)--) #define all(c) (c).begin(), (c).end() #define sz(v) (int)(v).size() using namespace std; typedef long long ll; typedef vector<ll> VI; typedef pair<ll, ll> pii; const int mod = (int)1e9 + 7; void dbg() { cerr << "\n"; } template <typename T, typename... T2> void dbg(const T &fst, const T2 &...rst) { cerr << fst << ": "; dbg(rst...); } template <class T> void amin(T &a, T b) { a = min(a, b); } template <class T> void amax(T &a, T b) { a = max(a, b); } int main() { // cin.tie(0); ios_base::sync_with_stdio(false); int n; cin >> n; VI a(n), b(n); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; bool ok = true; rep(i, n) if (a[i] < b[i]) ok = false; if (ok) { puts("0"); return 0; } ll sma = accumulate(all(a), 0LL); ll smb = accumulate(all(b), 0LL); if (smb > sma) { puts("-1"); return 0; } VI odf(n), pdf, mdf; rep(i, n) odf[i] = a[i] - b[i]; sort(all(odf)); reverse(all(odf)); rep(i, n)(odf[i] >= 0 ? pdf : mdf).push_back(odf[i]); int ans = 0; rep(i, sz(pdf)) { ll zf = pdf[i]; repr(j, sz(mdf) - 1, 0) { if (mdf[j] >= 0 || zf <= 0) break; if (mdf[j] + zf >= 0) { zf += mdf[j]; mdf[j] = 0; ans++; } else { mdf[j] += zf; zf = 0; } } if (zf != pdf[i]) { pdf[i] = 0; ans++; } while (sz(mdf) && mdf.back() >= 0) mdf.pop_back(); if (sz(mdf) == 0) break; } cout << ans << "\n"; return 0; }
replace
71
72
71
72
0
p03151
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)n; i++) #define all(c) (c).begin(), (c).end() #define pb push_back #define dbg(...) \ do { \ cerr << __LINE__ << ": "; \ dbgprint(#__VA_ARGS__, __VA_ARGS__); \ } while (0); using namespace std; namespace std { template <class S, class T> struct hash<pair<S, T>> { size_t operator()(const pair<S, T> &p) const { return ((size_t)1e9 + 7) * hash<S>()(p.first) + hash<T>()(p.second); } }; template <class T> struct hash<vector<T>> { size_t operator()(const vector<T> &v) const { size_t h = 0; for (auto i : v) h = h * ((size_t)1e9 + 7) + hash<T>()(i) + 1; return h; } }; } // namespace std template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "[ "; rep(i, v.size()) os << v[i] << (i == v.size() - 1 ? " ]" : ", "); return os; } template <class T> ostream &operator<<(ostream &os, const set<T> &v) { os << "{ "; for (const auto &i : v) os << i << ", "; return os << "}"; } template <class T, class U> ostream &operator<<(ostream &os, const map<T, U> &v) { os << "{"; for (const auto &i : v) os << " " << i.first << ": " << i.second << ","; return os << "}"; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << "(" << p.first << ", " << p.second << ")"; } void dbgprint(const string &fmt) { cerr << endl; } template <class H, class... T> void dbgprint(const string &fmt, const H &h, const T &...r) { cerr << fmt.substr(0, fmt.find(",")) << "= " << h << " "; dbgprint(fmt.substr(fmt.find(",") + 1), r...); } typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pi; const int inf = (int)1e9; const double INF = 1e12, EPS = 1e-9; int main() { cin.tie(0); cin.sync_with_stdio(0); int n; cin >> n; vi a(n), b(n), v; ; rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; rep(i, n) v.pb(a[i] - b[i]); sort(all(v)); dbg(v); int ans = 0; ll rem = 0; for (int i = 0, j = n - 1; i <= j; i++) { if (v[i] >= 0) { cout << ans << endl; return 0; } while (i < j && rem + v[i] < 0) { ans++; rem += v[j--]; } ans++; rem += v[i]; if (rem < 0) { cout << -1 << endl; return 0; } } assert(0); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)n; i++) #define all(c) (c).begin(), (c).end() #define pb push_back #define dbg(...) \ do { \ cerr << __LINE__ << ": "; \ dbgprint(#__VA_ARGS__, __VA_ARGS__); \ } while (0); using namespace std; namespace std { template <class S, class T> struct hash<pair<S, T>> { size_t operator()(const pair<S, T> &p) const { return ((size_t)1e9 + 7) * hash<S>()(p.first) + hash<T>()(p.second); } }; template <class T> struct hash<vector<T>> { size_t operator()(const vector<T> &v) const { size_t h = 0; for (auto i : v) h = h * ((size_t)1e9 + 7) + hash<T>()(i) + 1; return h; } }; } // namespace std template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "[ "; rep(i, v.size()) os << v[i] << (i == v.size() - 1 ? " ]" : ", "); return os; } template <class T> ostream &operator<<(ostream &os, const set<T> &v) { os << "{ "; for (const auto &i : v) os << i << ", "; return os << "}"; } template <class T, class U> ostream &operator<<(ostream &os, const map<T, U> &v) { os << "{"; for (const auto &i : v) os << " " << i.first << ": " << i.second << ","; return os << "}"; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << "(" << p.first << ", " << p.second << ")"; } void dbgprint(const string &fmt) { cerr << endl; } template <class H, class... T> void dbgprint(const string &fmt, const H &h, const T &...r) { cerr << fmt.substr(0, fmt.find(",")) << "= " << h << " "; dbgprint(fmt.substr(fmt.find(",") + 1), r...); } typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pi; const int inf = (int)1e9; const double INF = 1e12, EPS = 1e-9; int main() { cin.tie(0); cin.sync_with_stdio(0); int n; cin >> n; vi a(n), b(n), v; ; rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; rep(i, n) v.pb(a[i] - b[i]); sort(all(v)); dbg(v); int ans = 0; ll rem = 0; for (int i = 0, j = n - 1; i <= j; i++) { if (v[i] >= 0) { cout << ans << endl; return 0; } while (i < j && rem + v[i] < 0) { ans++; rem += v[j--]; } ans++; rem += v[i]; if (rem < 0) { cout << -1 << endl; return 0; } } cout << ans << endl; return 0; }
replace
93
94
93
94
-6
24: v= [ -1, -1, 4 ] 264752b6-3d12-49fd-8f2a-5aba49c9b292.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03151/C++/s557492168.cpp:44: int main(): Assertion `0' failed.
p03152
C++
Runtime Error
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define SIZE 1005 #define MOD 1000000007 using namespace std; typedef long long int ll; typedef pair<int, int> P; int A[SIZE], B[SIZE]; int px[SIZE], py[SIZE]; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", &A[i]), A[i]--; for (int i = 0; i < m; i++) scanf("%d", &B[i]), B[i]--; memset(px, -1, sizeof(px)); memset(py, -1, sizeof(py)); ll ret = 1; for (int i = 0; i < n; i++) { if (px[A[i]] != -1) { puts("0"); return 0; } px[A[i]] = i; } for (int i = 0; i < m; i++) { if (py[B[i]] != -1) { puts("0"); return 0; } py[B[i]] = i; } ll zx = 0, zy = 0; for (int i = n * m - 1; i >= 0; i--) { if (px[i] != -1) { if (py[i] == -1) { ret = ret * zy % MOD; zx++; } else zx++, zy++; } else { if (py[i] != -1) { ret = ret * zx % MOD; zy++; } else { ll zan = zx * zy - (n * m - i - 1); ret = ret * zan % MOD; } } } printf("%lld\n", ret); return 0; }
#include <algorithm> #include <cassert> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <map> #include <queue> #include <set> #include <string> #include <vector> #define SIZE 1000005 #define MOD 1000000007 using namespace std; typedef long long int ll; typedef pair<int, int> P; int A[SIZE], B[SIZE]; int px[SIZE], py[SIZE]; int main() { int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) scanf("%d", &A[i]), A[i]--; for (int i = 0; i < m; i++) scanf("%d", &B[i]), B[i]--; memset(px, -1, sizeof(px)); memset(py, -1, sizeof(py)); ll ret = 1; for (int i = 0; i < n; i++) { if (px[A[i]] != -1) { puts("0"); return 0; } px[A[i]] = i; } for (int i = 0; i < m; i++) { if (py[B[i]] != -1) { puts("0"); return 0; } py[B[i]] = i; } ll zx = 0, zy = 0; for (int i = n * m - 1; i >= 0; i--) { if (px[i] != -1) { if (py[i] == -1) { ret = ret * zy % MOD; zx++; } else zx++, zy++; } else { if (py[i] != -1) { ret = ret * zx % MOD; zy++; } else { ll zan = zx * zy - (n * m - i - 1); ret = ret * zan % MOD; } } } printf("%lld\n", ret); return 0; }
replace
12
13
12
13
0
p03152
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <time.h> #include <unordered_map> #include <vector> using namespace std; using ll = long long; using ld = long double; using pint = pair<int, int>; using pll = pair<ll, ll>; #define MOD 1000000007LL #define INF 1000000000LL #define EPS 1e-10 #define FOR(i, n, m) for (ll i = n; i < (ll)m; i++) #define REP(i, n) FOR(i, 0, n) #define DUMP(a) \ REP(d, a.size()) { \ cout << a[d]; \ if (d != a.size() - 1) \ cout << " "; \ else \ cout << endl; \ } #define ALL(v) v.begin(), v.end() #define UNIQUE(v) \ sort(ALL(v)); \ v.erase(unique(ALL(v)), v.end()); #define pb push_back #define MAX_N 2020 long long extgcd(long long a, long long b, long long &x, long long &y) { long long d = a; if (b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } long long mod_inverse(long long a, long long m) { long long x, y; if (extgcd(a, m, x, y) == 1) return (m + x % m) % m; else return -1; } vector<long long> fact(MAX_N + 1, INF); long long mod_fact(long long n, long long &e) { if (fact[0] == INF) { fact[0] = 1; if (MAX_N != 0) fact[1] = 1; for (ll i = 2; i <= MAX_N; ++i) { fact[i] = (fact[i - 1] * i) % MOD; } } e = 0; if (n == 0) return 1; long long res = mod_fact(n / MOD, e); e += n / MOD; if ((n / MOD) % 2 != 0) return (res * (MOD - fact[n % MOD])) % MOD; return (res * fact[n % MOD]) % MOD; } // return nCk long long mod_comb(long long n, long long k) { if (n < 0 || k < 0 || n < k) return 0; long long e1, e2, e3; long long a1 = mod_fact(n, e1), a2 = mod_fact(k, e2), a3 = mod_fact(n - k, e3); if (e1 > e2 + e3) return 0; return (a1 * mod_inverse((a2 * a3) % MOD, MOD)) % MOD; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, m; cin >> n >> m; vector<ll> modpow(2020, 0); modpow[0] = modpow[1] = 1; FOR(i, 2, 2020) { modpow[i] = i * modpow[i - 1]; modpow[i] %= MOD; } vector<ll> a(n); vector<ll> b(m); REP(i, n) cin >> a[i]; REP(i, m) cin >> b[i]; REP(i, n) FOR(j, i + 1, n) { if (a[i] == a[j]) { cout << 0 << endl; return 0; } } REP(i, m) FOR(j, i + 1, m) { if (b[i] == b[j]) { cout << 0 << endl; return 0; } } vector<pll> v; REP(i, n) v.pb(pll(a[i], 0)); REP(i, m) v.pb(pll(b[i], 1)); sort(ALL(v)); ll ans = 1; ll rem1 = n, rem2 = m; ll used = 0; REP(i, v.size()) { if (i < (ll)v.size() - 1 && v[i].first == v[i + 1].first) { if (v[i].first - used < rem1 + rem2 - 1) { cout << 0 << endl; return 0; } ans *= (modpow[rem1 + rem2 - 2] * mod_comb(v[i].first - used - 1, rem1 + rem2 - 2)) % MOD; ans %= MOD; used += rem1 + rem2 - 1; rem1--; rem2--; i++; } else { if (v[i].second == 0) { if (v[i].first - used < rem2) { cout << 0 << endl; return 0; } ans *= (modpow[rem2] * mod_comb(v[i].first - used - 1, rem2 - 1)) % MOD; ans %= MOD; used += rem2; rem1--; } else { if (v[i].first - used < rem1) { cout << 0 << endl; return 0; } ans *= (modpow[rem1] * mod_comb(v[i].first - used - 1, rem1 - 1)) % MOD; ans %= MOD; used += rem1; rem2--; } } } cout << ans << endl; return 0; } /* --------------------------------------- */
#include <algorithm> #include <bitset> #include <cassert> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <time.h> #include <unordered_map> #include <vector> using namespace std; using ll = long long; using ld = long double; using pint = pair<int, int>; using pll = pair<ll, ll>; #define MOD 1000000007LL #define INF 1000000000LL #define EPS 1e-10 #define FOR(i, n, m) for (ll i = n; i < (ll)m; i++) #define REP(i, n) FOR(i, 0, n) #define DUMP(a) \ REP(d, a.size()) { \ cout << a[d]; \ if (d != a.size() - 1) \ cout << " "; \ else \ cout << endl; \ } #define ALL(v) v.begin(), v.end() #define UNIQUE(v) \ sort(ALL(v)); \ v.erase(unique(ALL(v)), v.end()); #define pb push_back #define MAX_N 1000100 long long extgcd(long long a, long long b, long long &x, long long &y) { long long d = a; if (b != 0) { d = extgcd(b, a % b, y, x); y -= (a / b) * x; } else { x = 1; y = 0; } return d; } long long mod_inverse(long long a, long long m) { long long x, y; if (extgcd(a, m, x, y) == 1) return (m + x % m) % m; else return -1; } vector<long long> fact(MAX_N + 1, INF); long long mod_fact(long long n, long long &e) { if (fact[0] == INF) { fact[0] = 1; if (MAX_N != 0) fact[1] = 1; for (ll i = 2; i <= MAX_N; ++i) { fact[i] = (fact[i - 1] * i) % MOD; } } e = 0; if (n == 0) return 1; long long res = mod_fact(n / MOD, e); e += n / MOD; if ((n / MOD) % 2 != 0) return (res * (MOD - fact[n % MOD])) % MOD; return (res * fact[n % MOD]) % MOD; } // return nCk long long mod_comb(long long n, long long k) { if (n < 0 || k < 0 || n < k) return 0; long long e1, e2, e3; long long a1 = mod_fact(n, e1), a2 = mod_fact(k, e2), a3 = mod_fact(n - k, e3); if (e1 > e2 + e3) return 0; return (a1 * mod_inverse((a2 * a3) % MOD, MOD)) % MOD; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, m; cin >> n >> m; vector<ll> modpow(2020, 0); modpow[0] = modpow[1] = 1; FOR(i, 2, 2020) { modpow[i] = i * modpow[i - 1]; modpow[i] %= MOD; } vector<ll> a(n); vector<ll> b(m); REP(i, n) cin >> a[i]; REP(i, m) cin >> b[i]; REP(i, n) FOR(j, i + 1, n) { if (a[i] == a[j]) { cout << 0 << endl; return 0; } } REP(i, m) FOR(j, i + 1, m) { if (b[i] == b[j]) { cout << 0 << endl; return 0; } } vector<pll> v; REP(i, n) v.pb(pll(a[i], 0)); REP(i, m) v.pb(pll(b[i], 1)); sort(ALL(v)); ll ans = 1; ll rem1 = n, rem2 = m; ll used = 0; REP(i, v.size()) { if (i < (ll)v.size() - 1 && v[i].first == v[i + 1].first) { if (v[i].first - used < rem1 + rem2 - 1) { cout << 0 << endl; return 0; } ans *= (modpow[rem1 + rem2 - 2] * mod_comb(v[i].first - used - 1, rem1 + rem2 - 2)) % MOD; ans %= MOD; used += rem1 + rem2 - 1; rem1--; rem2--; i++; } else { if (v[i].second == 0) { if (v[i].first - used < rem2) { cout << 0 << endl; return 0; } ans *= (modpow[rem2] * mod_comb(v[i].first - used - 1, rem2 - 1)) % MOD; ans %= MOD; used += rem2; rem1--; } else { if (v[i].first - used < rem1) { cout << 0 << endl; return 0; } ans *= (modpow[rem1] * mod_comb(v[i].first - used - 1, rem1 - 1)) % MOD; ans %= MOD; used += rem1; rem2--; } } } cout << ans << endl; return 0; } /* --------------------------------------- */
replace
39
40
39
40
0
p03152
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define eprintf(...) 42 #endif using ll = long long; using vll = std::vector<ll>; using vvll = std::vector<vll>; using vvvll = std::vector<vvll>; #define reps(i, S, E) for (ll i = (S); i <= (E); i++) #define rep(i, N) reps(i, 0, N - 1) #define deps(i, E, S) for (ll i = (E); i >= (S); i--) #define dep(i, N) deps(i, N - 1, 0) const ll INF = 1LL << 60; const int INF_INT = 1 << 30; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } struct mll { static ll MOD; ll val; mll(ll v = 0) : val(v % MOD) { if (val < 0) val += MOD; } mll operator-() const { return -val; } mll operator+(const mll &b) const { return val + b.val; } mll operator-(const mll &b) const { return val - b.val; } mll operator*(const mll &b) const { return val * b.val; } mll operator/(const mll &b) const { return mll(*this) /= b; } mll operator+(ll b) const { return *this + mll(b); } mll operator-(ll b) const { return *this - mll(b); } mll operator*(ll b) const { return *this * mll(b); } friend mll operator+(ll a, const mll &b) { return b + a; } friend mll operator-(ll a, const mll &b) { return -b + a; } friend mll operator*(ll a, const mll &b) { return b * a; } mll &operator+=(const mll &b) { val = (val + b.val) % MOD; return *this; } mll &operator-=(const mll &b) { val = (val + MOD - b.val) % MOD; return *this; } mll &operator*=(const mll &b) { val = (val * b.val) % MOD; return *this; } mll &operator/=(const mll &b) { ll c = b.val, d = MOD, u = 1, v = 0; while (d) { ll t = c / d; c -= t * d; swap(c, d); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } mll &operator+=(ll b) { return *this += mll(b); } mll &operator-=(ll b) { return *this -= mll(b); } mll &operator*=(ll b) { return *this *= mll(b); } mll &operator/=(ll b) { return *this /= mll(b); } bool operator==(const mll &b) { return val == b.val; } bool operator!=(const mll &b) { return val != b.val; } bool operator==(ll b) { return *this == mll(b); } bool operator!=(ll b) { return *this != mll(b); } friend bool operator==(ll a, const mll &b) { return mll(a) == b.val; } friend bool operator!=(ll a, const mll &b) { return mll(a) != b.val; } friend ostream &operator<<(ostream &os, const mll &a) { return os << a.val; } friend istream &operator>>(istream &is, mll &a) { return is >> a.val; } static mll Combination(ll a, ll b) { chmin(b, a - b); if (b < 0) return mll(0); mll c = 1; rep(i, b) c *= a - i; rep(i, b) c /= i + 1; return c; } }; using vmll = std::vector<mll>; using vvmll = std::vector<vmll>; using vvvmll = std::vector<vvmll>; using vvvvmll = std::vector<vvvmll>; struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(std::numeric_limits<double>::max_digits10); } } fast; // cin,cout高速化のおまじない+桁数指定 ll mll::MOD = (ll)(1e9 + 7); // 998244353ll; //--debug-- #ifdef LOCAL void _debug_out_(string s = "") { if (s != "") { eprintf(s.c_str()); } else { eprintf("\n"); } } void _debug_out_(ll x, string s = "") { if (s != "") { eprintf(s.c_str(), x); } else { eprintf("%lld\n", x); } } void _debug_out_(mll x, string s = "") { if (s != "") { eprintf(s.c_str(), x); } else { eprintf("%lld\n", x.val); } } void _debug_out_(vvll x, string s = "") { string t = s; if (s == "") { ll maxLen = 0; rep(i, (ll)x.size()) rep(j, (ll)x[i].size()) { ll n = x[i][j] / 10, len = 1; while (n > 0) { len++; n /= 10; } chmax(maxLen, len); } t = "%" + to_string(maxLen) + "lld "; } rep(i, (ll)x.size()) { rep(j, (ll)x[i].size()) { eprintf(t.c_str(), x[i][j]); } eprintf("\n"); } eprintf("\n"); } void _debug_out_(vll x, string s = "") { rep(i, (ll)x.size()) { if (s != "") { eprintf(s.c_str(), x[i]); } else { eprintf("%lld ", x[i]); } } eprintf("\n"); } void _debug_out_(vector<bool> x) { rep(i, (ll)x.size()) { eprintf("%s", x[i] ? "o" : "x"); } eprintf("\n"); } void _debug_out_(vector<vector<bool>> x) { rep(i, (ll)x.size()) { rep(j, (ll)x[i].size()) { eprintf("%s", x[i][j] ? "o" : "x"); } eprintf("\n"); } eprintf("\n"); } void _debug_out_(map<ll, ll> x) { auto begin = x.begin(), end = x.end(); for (auto iter = begin; iter != end; iter++) { eprintf("%lld:%lld ", iter->first, iter->second); } eprintf("\n"); } void _debug_out_(map<char, ll> x) { auto begin = x.begin(), end = x.end(); for (auto iter = begin; iter != end; iter++) { eprintf("%c:%lld ", iter->first, iter->second); } eprintf("\n"); } #define debug_out(...) _debug_out_(__VA_ARGS__) #else #define debug_out(...) 42 #endif //--debug-- // ◆--↓--階乗をmodした数値を高速に求める--↓-- const ll MAX = 200000; const ll MOD = 1000000007; ll fac[MAX]; // テーブルを作る前処理 void FACinit() { fac[0] = fac[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; } } // 階乗計算 mll FAC(ll n) { return fac[n]; } //--↑--階乗をmodした数値を高速に求める--↑-- struct LLTriple { ll num = 0; ll rowFlag = 0; ll index = 0; ll fixed = 0; LLTriple() {} LLTriple(ll num, ll rowFlag, ll index, ll fixed) { this->num = num; this->rowFlag = rowFlag; this->index = index; this->fixed = fixed; } }; int main() { ll R; cin >> R; ll C; cin >> C; set<ll> sR; vector<ll> r(R); rep(i, R) { cin >> r[i]; if (sR.count(r[i]) > 0) { // 多重に入っているのでダメ cout << 0 << endl; return 0; } sR.insert(r[i]); } set<ll> sC; vector<ll> c(C); rep(i, C) { cin >> c[i]; if (sC.count(c[i]) > 0) { // 多重に入っているのでダメ cout << 0 << endl; return 0; } sC.insert(c[i]); } // 全行列の数をソートする vector<LLTriple> A; rep(i, R) { A.push_back(LLTriple(r[i], 1, i, (sC.count(r[i]) > 0 ? 1 : 0))); } rep(i, C) { A.push_back(LLTriple(c[i], 0, i, (sR.count(c[i]) > 0 ? 1 : 0))); } std::sort(A.begin(), A.end(), [](const LLTriple &a, const LLTriple &b) { return a.num < b.num; // 降順にするには > とする }); mll result = 1; ll usedCount = 0; ll rowIndex = 0; ll colIndex = 0; FACinit(); set<ll> sFixedNum; rep(i, R + C) { debug_out(); debug_out("i:"); debug_out(i); debug_out("num:"); debug_out(A[i].num); debug_out("row?:"); debug_out(A[i].rowFlag); debug_out("fixed?:"); debug_out(A[i].fixed); mll pat = 1; // 詰めることができる残りセル数 ll nCell = A[i].rowFlag ? C - colIndex : R - rowIndex; // 詰めることができる数の個数 ll nNum = A[i].num - usedCount; // 位置固定の場合 bool fix = false; if (sFixedNum.count(A[i].num) > 0) { // sFixedNumにすでに入っている場合は固定済み // 固定済みなのでセル数も詰めることができる数の個数もそのまま } else if (A[i].fixed) { nCell--; nNum--; sFixedNum.insert(A[i].num); fix = true; } else { // numがどこかに入り、残りのセルを詰める pat *= nCell; nCell--; nNum--; fix = true; } debug_out("nCell:"); debug_out(nCell); debug_out("nNum:"); debug_out(nNum); // 詰める場合の数 pat *= FAC(nNum) / FAC(nNum - nCell); result *= pat; debug_out("pat:"); debug_out(pat); debug_out("result:"); debug_out(result); // 詰めた数のカウント usedCount += nCell + (fix ? 1 : 0); // 行列index進める if (A[i].rowFlag) { rowIndex++; } else { colIndex++; } } cout << result << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define eprintf(...) 42 #endif using ll = long long; using vll = std::vector<ll>; using vvll = std::vector<vll>; using vvvll = std::vector<vvll>; #define reps(i, S, E) for (ll i = (S); i <= (E); i++) #define rep(i, N) reps(i, 0, N - 1) #define deps(i, E, S) for (ll i = (E); i >= (S); i--) #define dep(i, N) deps(i, N - 1, 0) const ll INF = 1LL << 60; const int INF_INT = 1 << 30; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } struct mll { static ll MOD; ll val; mll(ll v = 0) : val(v % MOD) { if (val < 0) val += MOD; } mll operator-() const { return -val; } mll operator+(const mll &b) const { return val + b.val; } mll operator-(const mll &b) const { return val - b.val; } mll operator*(const mll &b) const { return val * b.val; } mll operator/(const mll &b) const { return mll(*this) /= b; } mll operator+(ll b) const { return *this + mll(b); } mll operator-(ll b) const { return *this - mll(b); } mll operator*(ll b) const { return *this * mll(b); } friend mll operator+(ll a, const mll &b) { return b + a; } friend mll operator-(ll a, const mll &b) { return -b + a; } friend mll operator*(ll a, const mll &b) { return b * a; } mll &operator+=(const mll &b) { val = (val + b.val) % MOD; return *this; } mll &operator-=(const mll &b) { val = (val + MOD - b.val) % MOD; return *this; } mll &operator*=(const mll &b) { val = (val * b.val) % MOD; return *this; } mll &operator/=(const mll &b) { ll c = b.val, d = MOD, u = 1, v = 0; while (d) { ll t = c / d; c -= t * d; swap(c, d); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } mll &operator+=(ll b) { return *this += mll(b); } mll &operator-=(ll b) { return *this -= mll(b); } mll &operator*=(ll b) { return *this *= mll(b); } mll &operator/=(ll b) { return *this /= mll(b); } bool operator==(const mll &b) { return val == b.val; } bool operator!=(const mll &b) { return val != b.val; } bool operator==(ll b) { return *this == mll(b); } bool operator!=(ll b) { return *this != mll(b); } friend bool operator==(ll a, const mll &b) { return mll(a) == b.val; } friend bool operator!=(ll a, const mll &b) { return mll(a) != b.val; } friend ostream &operator<<(ostream &os, const mll &a) { return os << a.val; } friend istream &operator>>(istream &is, mll &a) { return is >> a.val; } static mll Combination(ll a, ll b) { chmin(b, a - b); if (b < 0) return mll(0); mll c = 1; rep(i, b) c *= a - i; rep(i, b) c /= i + 1; return c; } }; using vmll = std::vector<mll>; using vvmll = std::vector<vmll>; using vvvmll = std::vector<vvmll>; using vvvvmll = std::vector<vvvmll>; struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(std::numeric_limits<double>::max_digits10); } } fast; // cin,cout高速化のおまじない+桁数指定 ll mll::MOD = (ll)(1e9 + 7); // 998244353ll; //--debug-- #ifdef LOCAL void _debug_out_(string s = "") { if (s != "") { eprintf(s.c_str()); } else { eprintf("\n"); } } void _debug_out_(ll x, string s = "") { if (s != "") { eprintf(s.c_str(), x); } else { eprintf("%lld\n", x); } } void _debug_out_(mll x, string s = "") { if (s != "") { eprintf(s.c_str(), x); } else { eprintf("%lld\n", x.val); } } void _debug_out_(vvll x, string s = "") { string t = s; if (s == "") { ll maxLen = 0; rep(i, (ll)x.size()) rep(j, (ll)x[i].size()) { ll n = x[i][j] / 10, len = 1; while (n > 0) { len++; n /= 10; } chmax(maxLen, len); } t = "%" + to_string(maxLen) + "lld "; } rep(i, (ll)x.size()) { rep(j, (ll)x[i].size()) { eprintf(t.c_str(), x[i][j]); } eprintf("\n"); } eprintf("\n"); } void _debug_out_(vll x, string s = "") { rep(i, (ll)x.size()) { if (s != "") { eprintf(s.c_str(), x[i]); } else { eprintf("%lld ", x[i]); } } eprintf("\n"); } void _debug_out_(vector<bool> x) { rep(i, (ll)x.size()) { eprintf("%s", x[i] ? "o" : "x"); } eprintf("\n"); } void _debug_out_(vector<vector<bool>> x) { rep(i, (ll)x.size()) { rep(j, (ll)x[i].size()) { eprintf("%s", x[i][j] ? "o" : "x"); } eprintf("\n"); } eprintf("\n"); } void _debug_out_(map<ll, ll> x) { auto begin = x.begin(), end = x.end(); for (auto iter = begin; iter != end; iter++) { eprintf("%lld:%lld ", iter->first, iter->second); } eprintf("\n"); } void _debug_out_(map<char, ll> x) { auto begin = x.begin(), end = x.end(); for (auto iter = begin; iter != end; iter++) { eprintf("%c:%lld ", iter->first, iter->second); } eprintf("\n"); } #define debug_out(...) _debug_out_(__VA_ARGS__) #else #define debug_out(...) 42 #endif //--debug-- // ◆--↓--階乗をmodした数値を高速に求める--↓-- const ll MAX = 2000000; const ll MOD = 1000000007; ll fac[MAX]; // テーブルを作る前処理 void FACinit() { fac[0] = fac[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; } } // 階乗計算 mll FAC(ll n) { return fac[n]; } //--↑--階乗をmodした数値を高速に求める--↑-- struct LLTriple { ll num = 0; ll rowFlag = 0; ll index = 0; ll fixed = 0; LLTriple() {} LLTriple(ll num, ll rowFlag, ll index, ll fixed) { this->num = num; this->rowFlag = rowFlag; this->index = index; this->fixed = fixed; } }; int main() { ll R; cin >> R; ll C; cin >> C; set<ll> sR; vector<ll> r(R); rep(i, R) { cin >> r[i]; if (sR.count(r[i]) > 0) { // 多重に入っているのでダメ cout << 0 << endl; return 0; } sR.insert(r[i]); } set<ll> sC; vector<ll> c(C); rep(i, C) { cin >> c[i]; if (sC.count(c[i]) > 0) { // 多重に入っているのでダメ cout << 0 << endl; return 0; } sC.insert(c[i]); } // 全行列の数をソートする vector<LLTriple> A; rep(i, R) { A.push_back(LLTriple(r[i], 1, i, (sC.count(r[i]) > 0 ? 1 : 0))); } rep(i, C) { A.push_back(LLTriple(c[i], 0, i, (sR.count(c[i]) > 0 ? 1 : 0))); } std::sort(A.begin(), A.end(), [](const LLTriple &a, const LLTriple &b) { return a.num < b.num; // 降順にするには > とする }); mll result = 1; ll usedCount = 0; ll rowIndex = 0; ll colIndex = 0; FACinit(); set<ll> sFixedNum; rep(i, R + C) { debug_out(); debug_out("i:"); debug_out(i); debug_out("num:"); debug_out(A[i].num); debug_out("row?:"); debug_out(A[i].rowFlag); debug_out("fixed?:"); debug_out(A[i].fixed); mll pat = 1; // 詰めることができる残りセル数 ll nCell = A[i].rowFlag ? C - colIndex : R - rowIndex; // 詰めることができる数の個数 ll nNum = A[i].num - usedCount; // 位置固定の場合 bool fix = false; if (sFixedNum.count(A[i].num) > 0) { // sFixedNumにすでに入っている場合は固定済み // 固定済みなのでセル数も詰めることができる数の個数もそのまま } else if (A[i].fixed) { nCell--; nNum--; sFixedNum.insert(A[i].num); fix = true; } else { // numがどこかに入り、残りのセルを詰める pat *= nCell; nCell--; nNum--; fix = true; } debug_out("nCell:"); debug_out(nCell); debug_out("nNum:"); debug_out(nNum); // 詰める場合の数 pat *= FAC(nNum) / FAC(nNum - nCell); result *= pat; debug_out("pat:"); debug_out(pat); debug_out("result:"); debug_out(result); // 詰めた数のカウント usedCount += nCell + (fix ? 1 : 0); // 行列index進める if (A[i].rowFlag) { rowIndex++; } else { colIndex++; } } cout << result << endl; return 0; }
replace
212
213
212
213
0
p03152
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; using ll = long long; using vll = vector<ll>; using pl4 = pair<ll, ll>; using str = string; using vpl4 = vector<pair<ll, ll>>; #define sz size() #define be begin() #define en end() #define fi first #define se second #define pb push_back #define mp make_pair #define llin(x) \ ll(x); \ cin >> (x); #define stin(x) \ str(x); \ cin >> (x); #define FOR(i, a, b) for (ll i = a; i <= b; i++) #define rFOR(i, b, a) for (ll i = a; i >= b; i--) #define SORT(x) sort(x.be, x.en) #define rSORT(x) sort(x.rbegin(), x.rend()) #define say(x) cout << (x); #define sal(x) cout << (x) << endl; #define yn(a) cout << ((a) ? "yes" : "no") << endl; #define Yn(a) cout << ((a) ? "Yes" : "No") << endl; #define YN(a) cout << ((a) ? "YES" : "NO") << endl; #define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl; #define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl; ll MOD = 1000000007; signed main() { llin(n); llin(m); vll a(n + 1, 0); vll b(n + 1, 0); ll s = 0; ll x = 1; ll y = 1; ll t = 1; FOR(i, 0, n - 1) { cin >> a[i]; } FOR(i, 0, m - 1) { cin >> b[i]; } rSORT(a); rSORT(b); ll o = a[0]; while (x < m || y < n) { if (o == a[y] || o == b[x]) { t = 0; break; } if (a[y] == b[x]) { FOR(j, 1, o - a[y] - 1) { t = (t * s) % MOD; s--; } o = a[y]; s += x + y; x++; y++; } if (a[y] > b[x]) { t = (t * x) % MOD; FOR(j, 1, o - a[y] - 1) { t = (t * s) % MOD; s--; } o = a[y]; s += x - 1; y++; } if (a[y] < b[x]) { t = (t * y) % MOD; FOR(j, 1, o - b[x] - 1) { t = (t * s) % MOD; s--; } o = b[x]; s += y - 1; x++; } } rFOR(j, 1, s) { t = (t * j) % MOD; } sal(t); }
#include "bits/stdc++.h" using namespace std; using ll = long long; using vll = vector<ll>; using pl4 = pair<ll, ll>; using str = string; using vpl4 = vector<pair<ll, ll>>; #define sz size() #define be begin() #define en end() #define fi first #define se second #define pb push_back #define mp make_pair #define llin(x) \ ll(x); \ cin >> (x); #define stin(x) \ str(x); \ cin >> (x); #define FOR(i, a, b) for (ll i = a; i <= b; i++) #define rFOR(i, b, a) for (ll i = a; i >= b; i--) #define SORT(x) sort(x.be, x.en) #define rSORT(x) sort(x.rbegin(), x.rend()) #define say(x) cout << (x); #define sal(x) cout << (x) << endl; #define yn(a) cout << ((a) ? "yes" : "no") << endl; #define Yn(a) cout << ((a) ? "Yes" : "No") << endl; #define YN(a) cout << ((a) ? "YES" : "NO") << endl; #define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl; #define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl; ll MOD = 1000000007; signed main() { llin(n); llin(m); vll a(n + 1, 0); vll b(m + 1, 0); ll s = 0; ll x = 1; ll y = 1; ll t = 1; FOR(i, 0, n - 1) { cin >> a[i]; } FOR(i, 0, m - 1) { cin >> b[i]; } rSORT(a); rSORT(b); ll o = a[0]; while (x < m || y < n) { if (o == a[y] || o == b[x]) { t = 0; break; } if (a[y] == b[x]) { FOR(j, 1, o - a[y] - 1) { t = (t * s) % MOD; s--; } o = a[y]; s += x + y; x++; y++; } if (a[y] > b[x]) { t = (t * x) % MOD; FOR(j, 1, o - a[y] - 1) { t = (t * s) % MOD; s--; } o = a[y]; s += x - 1; y++; } if (a[y] < b[x]) { t = (t * y) % MOD; FOR(j, 1, o - b[x] - 1) { t = (t * s) % MOD; s--; } o = b[x]; s += y - 1; x++; } } rFOR(j, 1, s) { t = (t * j) % MOD; } sal(t); }
replace
42
43
42
43
0
p03152
C++
Runtime Error
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <type_traits> #include <typeindex> #include <unordered_map> #include <unordered_set> #endif int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } #define ll long long #define pb push_back #define ld long double #define mp make_pair #define F first #define S second #define pii pair<ll, ll> using namespace ::std; const ll maxn = 2e5 + 500; const ll mod = 1e9 + 7; ll zarb(long long a, long long b) { return (a * b) % mod; } ll jam(long long a, long long b) { return (a + b) % mod; } ll fac[maxn]; ll rfac[maxn]; ll poww(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) { ans = zarb(ans, a); } a = zarb(a, a); b >>= 1; } return ans; } ll ent(ll n, ll k) { if (k > n || k < 0) return 0; return zarb(fac[n], zarb(rfac[k], rfac[n - k])); } ll juy(ll n, ll k) { if (k > n || k < 0) return 0; return zarb(fac[n], rfac[n - k]); } ll a[maxn]; ll b[maxn]; ll n, m; ll findAns(ll x, ll y, ll c) { ll ax = a[x] - c; ll by = b[y] - c; ll tolx = n - x; ll toly = m - y; ll s = tolx * toly; if (s == 0) return 1; if (ax == by) { return zarb(findAns(x + 1, y + 1, c + tolx + toly - 1), juy(ax - 1, tolx + toly - 2)); } if (ax < by) { return zarb(zarb(findAns(x + 1, y, c + toly), juy(ax - 1, toly - 1)), toly); } if (ax > by) { return zarb(zarb(findAns(x, y + 1, c + tolx), juy(by - 1, tolx - 1)), tolx); } } int main() { fac[0] = 1; for (ll i = 1; i < maxn; i++) { fac[i] = zarb(fac[i - 1], i); } for (ll i = 0; i < maxn; i++) { rfac[i] = poww(fac[i], mod - 2); } cin >> n >> m; for (ll i = 0; i < n; i++) { cin >> a[i]; } for (ll i = 0; i < m; i++) { cin >> b[i]; } sort(a, a + n); sort(b, b + m); for (ll i = 0; i + 1 < n; i++) { if (a[i] == a[i + 1]) { cout << 0; return 0; } } for (ll i = 0; i + 1 < m; i++) { if (b[i] == b[i + 1]) { cout << 0; return 0; } } cout << findAns(0, 0, 0); }
#include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <type_traits> #include <typeindex> #include <unordered_map> #include <unordered_set> #endif int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } #define ll long long #define pb push_back #define ld long double #define mp make_pair #define F first #define S second #define pii pair<ll, ll> using namespace ::std; const ll maxn = 1e6 + 500; const ll mod = 1e9 + 7; ll zarb(long long a, long long b) { return (a * b) % mod; } ll jam(long long a, long long b) { return (a + b) % mod; } ll fac[maxn]; ll rfac[maxn]; ll poww(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) { ans = zarb(ans, a); } a = zarb(a, a); b >>= 1; } return ans; } ll ent(ll n, ll k) { if (k > n || k < 0) return 0; return zarb(fac[n], zarb(rfac[k], rfac[n - k])); } ll juy(ll n, ll k) { if (k > n || k < 0) return 0; return zarb(fac[n], rfac[n - k]); } ll a[maxn]; ll b[maxn]; ll n, m; ll findAns(ll x, ll y, ll c) { ll ax = a[x] - c; ll by = b[y] - c; ll tolx = n - x; ll toly = m - y; ll s = tolx * toly; if (s == 0) return 1; if (ax == by) { return zarb(findAns(x + 1, y + 1, c + tolx + toly - 1), juy(ax - 1, tolx + toly - 2)); } if (ax < by) { return zarb(zarb(findAns(x + 1, y, c + toly), juy(ax - 1, toly - 1)), toly); } if (ax > by) { return zarb(zarb(findAns(x, y + 1, c + tolx), juy(by - 1, tolx - 1)), tolx); } } int main() { fac[0] = 1; for (ll i = 1; i < maxn; i++) { fac[i] = zarb(fac[i - 1], i); } for (ll i = 0; i < maxn; i++) { rfac[i] = poww(fac[i], mod - 2); } cin >> n >> m; for (ll i = 0; i < n; i++) { cin >> a[i]; } for (ll i = 0; i < m; i++) { cin >> b[i]; } sort(a, a + n); sort(b, b + m); for (ll i = 0; i + 1 < n; i++) { if (a[i] == a[i + 1]) { cout << 0; return 0; } } for (ll i = 0; i + 1 < m; i++) { if (b[i] == b[i + 1]) { cout << 0; return 0; } } cout << findAns(0, 0, 0); }
replace
66
67
66
67
0
p03152
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define FOR(i, n, m) for (int i = n; i <= (int)(m); i++) #define RFOR(i, n, m) for (int i = (int)(n); i >= m; i--) #define all(x) (x).begin(), (x).end() #define sz(x) int(x.size()) typedef long long ll; const int INF = 1e9; const int MOD = 1e9 + 7; const ll LINF = 1e18; const double PI = 3.14159265358979323846; using namespace std; vector<int> dx = {1, 0, -1, 0}; vector<int> dy = {0, 1, 0, -1}; template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); } template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } int main() { int n, m; cin >> n >> m; vector<pair<int, int>> vec(100100, {-1, -1}); rep(i, n) { int a; cin >> a; vec[a].first = i; } rep(i, m) { int b; cin >> b; vec[b].second = i; } ll ans = 1; set<int> as, bs; for (int i = n * m; i > 0; i--) { int a, b; tie(a, b) = vec[i]; if (a == -1 && b == -1) { ll total = n * m - i; ll now = (ll)(sz(as) * sz(bs)) - total; ans = (ans * now) % MOD; } else if (a == -1) { ll now = sz(as); ans = (ans * now) % MOD; bs.insert(b); } else if (b == -1) { ll now = sz(bs); ans = (ans * now) % MOD; as.insert(a); } else { as.insert(a); bs.insert(b); } // cout<<ans<<endl; } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define FOR(i, n, m) for (int i = n; i <= (int)(m); i++) #define RFOR(i, n, m) for (int i = (int)(n); i >= m; i--) #define all(x) (x).begin(), (x).end() #define sz(x) int(x.size()) typedef long long ll; const int INF = 1e9; const int MOD = 1e9 + 7; const ll LINF = 1e18; const double PI = 3.14159265358979323846; using namespace std; vector<int> dx = {1, 0, -1, 0}; vector<int> dy = {0, 1, 0, -1}; template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); } template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); } int main() { int n, m; cin >> n >> m; vector<pair<int, int>> vec(1001001, {-1, -1}); rep(i, n) { int a; cin >> a; vec[a].first = i; } rep(i, m) { int b; cin >> b; vec[b].second = i; } ll ans = 1; set<int> as, bs; for (int i = n * m; i > 0; i--) { int a, b; tie(a, b) = vec[i]; if (a == -1 && b == -1) { ll total = n * m - i; ll now = (ll)(sz(as) * sz(bs)) - total; ans = (ans * now) % MOD; } else if (a == -1) { ll now = sz(as); ans = (ans * now) % MOD; bs.insert(b); } else if (b == -1) { ll now = sz(bs); ans = (ans * now) % MOD; as.insert(a); } else { as.insert(a); bs.insert(b); } // cout<<ans<<endl; } cout << ans << endl; }
replace
23
24
23
24
0
p03152
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<VI> VVI; #define MP make_pair #define PB push_back #define inf 1000000007 #define mod 1000000007 #define rep(i, n) for (int i = 0; i < (int)(n); ++i) template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } #define MAX_N 100005 #define MOD 1000000007 ll inv[MAX_N], fac[MAX_N], finv[MAX_N]; void make() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX_N; i++) { inv[i] = MOD - (long long)inv[MOD % i] * (MOD / i) % MOD; fac[i] = (long long)fac[i - 1] * i % MOD; finv[i] = (long long)finv[i - 1] * inv[i] % MOD; } } ll com(int a, int b) { // cerr << a << " " << b << endl; if (a < b) { return 0; } return fac[a] * (finv[a - b] % MOD) % MOD; } int main() { int n, m; make(); cin >> n >> m; vector<int> a(n), b(m); rep(i, n) cin >> a[i]; rep(i, m) cin >> b[i]; sort(a.begin(), a.end()); sort(b.begin(), b.end()); int x = 0; int y = 0; int c = 0; ll ans = 1; if (a[n - 1] != b[m - 1]) { cout << 0 << endl; return 0; } rep(i, n - 1) { if (a[i] == a[i + 1]) { cout << 0 << endl; return 0; } } rep(i, m - 1) { if (b[i] == b[i + 1]) { cout << 0 << endl; return 0; } } while (1) { // cerr << x << " " << y << " " << ans << endl; if (x == n && y == m) break; if (x == n) { int p = b[y]; ll tmp = com(p - c - 1, n - x - 1) * (ll)(n - x) % mod; ans *= tmp; ans %= mod; c += n - x; y++; } else if (y == m) { int p = a[x]; ll tmp = com(p - c - 1, m - y - 1) * (ll)(m - y) % mod; ans *= tmp; ans %= mod; x++; c += m - y; } else { if (a[x] == b[y]) { int p = a[x]; ll tmp = com(p - c - 1, m - 1 - y + n - 1 - x); ans *= tmp; ans %= mod; c += m - 1 - y + n - 1 - x + 1; x++; y++; } else if (a[x] > b[y]) { int p = b[y]; ll tmp = com(p - c - 1, n - x - 1) * (ll)(n - x) % mod; ans *= tmp; ans %= mod; c += n - x; y++; } else { int p = a[x]; ll tmp = com(p - c - 1, m - y - 1) * (ll)(m - y) % mod; ans *= tmp; ans %= mod; x++; c += m - y; } } if (ans == 0) break; } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<VI> VVI; #define MP make_pair #define PB push_back #define inf 1000000007 #define mod 1000000007 #define rep(i, n) for (int i = 0; i < (int)(n); ++i) template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } #define MAX_N 2000005 #define MOD 1000000007 ll inv[MAX_N], fac[MAX_N], finv[MAX_N]; void make() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX_N; i++) { inv[i] = MOD - (long long)inv[MOD % i] * (MOD / i) % MOD; fac[i] = (long long)fac[i - 1] * i % MOD; finv[i] = (long long)finv[i - 1] * inv[i] % MOD; } } ll com(int a, int b) { // cerr << a << " " << b << endl; if (a < b) { return 0; } return fac[a] * (finv[a - b] % MOD) % MOD; } int main() { int n, m; make(); cin >> n >> m; vector<int> a(n), b(m); rep(i, n) cin >> a[i]; rep(i, m) cin >> b[i]; sort(a.begin(), a.end()); sort(b.begin(), b.end()); int x = 0; int y = 0; int c = 0; ll ans = 1; if (a[n - 1] != b[m - 1]) { cout << 0 << endl; return 0; } rep(i, n - 1) { if (a[i] == a[i + 1]) { cout << 0 << endl; return 0; } } rep(i, m - 1) { if (b[i] == b[i + 1]) { cout << 0 << endl; return 0; } } while (1) { // cerr << x << " " << y << " " << ans << endl; if (x == n && y == m) break; if (x == n) { int p = b[y]; ll tmp = com(p - c - 1, n - x - 1) * (ll)(n - x) % mod; ans *= tmp; ans %= mod; c += n - x; y++; } else if (y == m) { int p = a[x]; ll tmp = com(p - c - 1, m - y - 1) * (ll)(m - y) % mod; ans *= tmp; ans %= mod; x++; c += m - y; } else { if (a[x] == b[y]) { int p = a[x]; ll tmp = com(p - c - 1, m - 1 - y + n - 1 - x); ans *= tmp; ans %= mod; c += m - 1 - y + n - 1 - x + 1; x++; y++; } else if (a[x] > b[y]) { int p = b[y]; ll tmp = com(p - c - 1, n - x - 1) * (ll)(n - x) % mod; ans *= tmp; ans %= mod; c += n - x; y++; } else { int p = a[x]; ll tmp = com(p - c - 1, m - y - 1) * (ll)(m - y) % mod; ans *= tmp; ans %= mod; x++; c += m - y; } } if (ans == 0) break; } cout << ans << endl; return 0; }
replace
30
31
30
31
0
p03152
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fi first #define se second typedef pair<int, int> ii; const int N = 1e3 + 5, mod = 1e9 + 7; int n, m, cntR[N], cntC[N], a[N], b[N], row, col, ans = 1; ii pos[N * N]; int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; ++i) { scanf("%d", a + i); ++cntR[a[i]]; pos[a[i]].fi = i; } for (int i = 1; i <= m; ++i) { scanf("%d", b + i); ++cntC[b[i]]; pos[b[i]].se = i; } for (int i = 1; i <= n * m; ++i) if (cntC[i] > 1 || cntR[i] > 1) return printf("0"), 0; for (int i = n * m; i > 0; --i) { if (pos[i].fi && pos[i].se) { } else if (pos[i].fi) { ans = 1LL * ans * col % mod; } else if (pos[i].se) { ans = 1LL * ans * row % mod; } else { ans = 1LL * ans * max(0, row * col - (n * m - i)) % mod; } row += (pos[i].fi > 0); col += (pos[i].se > 0); // cout << "ans = " << ans << '\n'; } printf("%d", ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define fi first #define se second typedef pair<int, int> ii; const int N = 1e3 + 5, mod = 1e9 + 7; int n, m, cntR[N * N], cntC[N * N], a[N], b[N], row, col, ans = 1; ii pos[N * N]; int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= n; ++i) { scanf("%d", a + i); ++cntR[a[i]]; pos[a[i]].fi = i; } for (int i = 1; i <= m; ++i) { scanf("%d", b + i); ++cntC[b[i]]; pos[b[i]].se = i; } for (int i = 1; i <= n * m; ++i) if (cntC[i] > 1 || cntR[i] > 1) return printf("0"), 0; for (int i = n * m; i > 0; --i) { if (pos[i].fi && pos[i].se) { } else if (pos[i].fi) { ans = 1LL * ans * col % mod; } else if (pos[i].se) { ans = 1LL * ans * row % mod; } else { ans = 1LL * ans * max(0, row * col - (n * m - i)) % mod; } row += (pos[i].fi > 0); col += (pos[i].se > 0); // cout << "ans = " << ans << '\n'; } printf("%d", ans); return 0; }
replace
9
10
9
10
0
p03152
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <numeric> #include <queue> #include <string> #include <vector> using namespace std; typedef long long ll; #define INF 10e17 // 4倍しても(4回足しても)long longを溢れない #define rep(i, n) for (int i = 0; i < n; i++) #define rep_r(i, n, m) for (int i = m; i < n; i++) #define END cout << endl #define MOD 1000000007 #define pb push_back #define sorti(x) sort(x.begin(), x.end()) #define sortd(x) sort(x.begin(), x.end(), std::greater<int>()) void mul(ll &a, ll &b) { a = a * b % MOD; } int main() { int n, m; cin >> n >> m; vector<ll> a(n), b(n); rep(i, n) cin >> a[i]; rep(i, m) cin >> b[i]; sortd(a); sortd(b); a.pb(-1); b.pb(-1); ll apt = 0, bpt = 0, num = n * m; ll ans = 1; while (num > 0) { if (a[apt] == num and b[bpt] == num) { apt++; bpt++; } else if (a[apt] == num) { apt++; mul(ans, bpt); } else if (b[bpt] == num) { bpt++; mul(ans, apt); } else { ll tmp = apt * bpt - (n * m - num); mul(ans, tmp); } num -= 1; } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <numeric> #include <queue> #include <string> #include <vector> using namespace std; typedef long long ll; #define INF 10e17 // 4倍しても(4回足しても)long longを溢れない #define rep(i, n) for (int i = 0; i < n; i++) #define rep_r(i, n, m) for (int i = m; i < n; i++) #define END cout << endl #define MOD 1000000007 #define pb push_back #define sorti(x) sort(x.begin(), x.end()) #define sortd(x) sort(x.begin(), x.end(), std::greater<int>()) void mul(ll &a, ll &b) { a = a * b % MOD; } int main() { int n, m; cin >> n >> m; vector<ll> a(n), b(m); rep(i, n) cin >> a[i]; rep(i, m) cin >> b[i]; sortd(a); sortd(b); a.pb(-1); b.pb(-1); ll apt = 0, bpt = 0, num = n * m; ll ans = 1; while (num > 0) { if (a[apt] == num and b[bpt] == num) { apt++; bpt++; } else if (a[apt] == num) { apt++; mul(ans, bpt); } else if (b[bpt] == num) { bpt++; mul(ans, apt); } else { ll tmp = apt * bpt - (n * m - num); mul(ans, tmp); } num -= 1; } cout << ans << endl; }
replace
29
30
29
30
0
p03152
C++
Runtime Error
#ifndef BZ #pragma GCC optimize "-O3" #endif #include <bits/stdc++.h> #define FASTIO #define ALL(v) (v).begin(), (v).end() #define rep(i, l, r) for (int i = (l); i < (r); ++i) #ifdef FASTIO #define scanf abacaba #define printf abacaba #endif typedef long long ll; typedef long double ld; typedef unsigned long long ull; using namespace std; /* ll pw(ll a, ll b) { ll ans = 1; while (b) { while (!(b & 1)) b >>= 1, a = (a * a) % MOD; ans = (ans * a) % MOD, --b; } return ans; } */ const int MAXN = 1200; int n, m; int a[MAXN]; int b[MAXN]; vector<int> gc[MAXN], gr[MAXN]; const ll MOD = 1e9 + 7; int main() { #ifdef FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); #endif cin >> n >> m; for (int i = 0; i < n; ++i) cin >> a[i], --a[i], gr[a[i]].push_back(i); for (int i = 0; i < m; ++i) cin >> b[i], --b[i], gc[b[i]].push_back(i); ll ans = 1; int r = 0; int c = 0; int cr = 0; for (int i = n * m - 1; i >= 0; --i) { if (gr[i].size() >= 2 || gc[i].size() >= 2) { cout << 0 << "\n"; return 0; } if (gr[i].empty()) { if (gc[i].empty()) { ans = (ans * cr) % MOD; --cr; } else { ans = (ans * r) % MOD; cr += r - 1; ++c; } } else { if (gc[i].empty()) { ans = (ans * c) % MOD; cr += c - 1; ++r; } else { cr += r + c; ++r, ++c; } } } cout << ans << "\n"; return 0; }
#ifndef BZ #pragma GCC optimize "-O3" #endif #include <bits/stdc++.h> #define FASTIO #define ALL(v) (v).begin(), (v).end() #define rep(i, l, r) for (int i = (l); i < (r); ++i) #ifdef FASTIO #define scanf abacaba #define printf abacaba #endif typedef long long ll; typedef long double ld; typedef unsigned long long ull; using namespace std; /* ll pw(ll a, ll b) { ll ans = 1; while (b) { while (!(b & 1)) b >>= 1, a = (a * a) % MOD; ans = (ans * a) % MOD, --b; } return ans; } */ const int MAXN = 1200 * 1200; int n, m; int a[MAXN]; int b[MAXN]; vector<int> gc[MAXN], gr[MAXN]; const ll MOD = 1e9 + 7; int main() { #ifdef FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); #endif cin >> n >> m; for (int i = 0; i < n; ++i) cin >> a[i], --a[i], gr[a[i]].push_back(i); for (int i = 0; i < m; ++i) cin >> b[i], --b[i], gc[b[i]].push_back(i); ll ans = 1; int r = 0; int c = 0; int cr = 0; for (int i = n * m - 1; i >= 0; --i) { if (gr[i].size() >= 2 || gc[i].size() >= 2) { cout << 0 << "\n"; return 0; } if (gr[i].empty()) { if (gc[i].empty()) { ans = (ans * cr) % MOD; --cr; } else { ans = (ans * r) % MOD; cr += r - 1; ++c; } } else { if (gc[i].empty()) { ans = (ans * c) % MOD; cr += c - 1; ++r; } else { cr += r + c; ++r, ++c; } } } cout << ans << "\n"; return 0; }
replace
29
30
29
30
0
p03152
C++
Runtime Error
#include <bits/stdc++.h> // #define int long long #define pii pair<int, int> #define x1 x1228 #define y1 y1228 #define left left228 #define right right228 #define pb push_back #define eb emplace_back #define mp make_pair #define ff first #define ss second #define matr vector<vector<int>> #define all(x) x.begin(), x.end() using namespace std; typedef long long ll; typedef long double ld; const int maxn = 3e5 + 7, mod = 1e9 + 7, inf = 1e9, MAXN = 1e6 + 7; const double eps = 1e-9; mt19937 rnd(time(0)); int n, m; int A[maxn]; int B[maxn]; int a[maxn], b[maxn]; void solve() { cin >> n >> m; for (int i = 0; i < n; ++i) { int x; cin >> x; a[i] = x; if (A[x]) { cout << 0; return; } A[x] = 1; } for (int i = 0; i < m; ++i) { int x; cin >> x; b[i] = x; if (B[x]) { cout << 0; return; } B[x] = 1; } ll ans = 1; int have = -1; for (int i = n * m; i > 0; --i) { have++; if (A[i] && B[i]) { continue; } if (A[i]) { int cur = 0; for (int j = 0; j < m; ++j) { if (b[j] >= i) { ++cur; } } ans *= cur; ans %= mod; continue; } if (B[i]) { int cur = 0; for (int j = 0; j < n; ++j) { if (a[j] >= i) { ++cur; } } ans *= cur; ans %= mod; continue; } int p1 = 0; int p2 = 0; for (int j = 0; j < n; ++j) { p1 += (a[j] >= i); } for (int j = 0; j < m; ++j) { p2 += (b[j] >= i); } int d = p1 * p2; d -= have; ans *= d; ans %= mod; } cout << ans; } signed main() { #ifdef LOCAL freopen("TASK.in", "r", stdin); freopen("TASK.out", "w", stdout); #else #endif // LOCAL ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(20); cout << fixed; int t = 1; for (int i = 0; i < t; ++i) solve(); return 0; }
#include <bits/stdc++.h> // #define int long long #define pii pair<int, int> #define x1 x1228 #define y1 y1228 #define left left228 #define right right228 #define pb push_back #define eb emplace_back #define mp make_pair #define ff first #define ss second #define matr vector<vector<int>> #define all(x) x.begin(), x.end() using namespace std; typedef long long ll; typedef long double ld; const int maxn = 1e6 + 7, mod = 1e9 + 7, inf = 1e9, MAXN = 1e6 + 7; const double eps = 1e-9; mt19937 rnd(time(0)); int n, m; int A[maxn]; int B[maxn]; int a[maxn], b[maxn]; void solve() { cin >> n >> m; for (int i = 0; i < n; ++i) { int x; cin >> x; a[i] = x; if (A[x]) { cout << 0; return; } A[x] = 1; } for (int i = 0; i < m; ++i) { int x; cin >> x; b[i] = x; if (B[x]) { cout << 0; return; } B[x] = 1; } ll ans = 1; int have = -1; for (int i = n * m; i > 0; --i) { have++; if (A[i] && B[i]) { continue; } if (A[i]) { int cur = 0; for (int j = 0; j < m; ++j) { if (b[j] >= i) { ++cur; } } ans *= cur; ans %= mod; continue; } if (B[i]) { int cur = 0; for (int j = 0; j < n; ++j) { if (a[j] >= i) { ++cur; } } ans *= cur; ans %= mod; continue; } int p1 = 0; int p2 = 0; for (int j = 0; j < n; ++j) { p1 += (a[j] >= i); } for (int j = 0; j < m; ++j) { p2 += (b[j] >= i); } int d = p1 * p2; d -= have; ans *= d; ans %= mod; } cout << ans; } signed main() { #ifdef LOCAL freopen("TASK.in", "r", stdin); freopen("TASK.out", "w", stdout); #else #endif // LOCAL ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(20); cout << fixed; int t = 1; for (int i = 0; i < t; ++i) solve(); return 0; }
replace
28
29
28
29
0
p03152
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 1e3 + 10, mod = 1e9 + 7; int n, m, ans = 1, ar[2][N], mark[N * N]; int32_t main() { cin >> n >> m; for (int j = 0; j < n; j++) { cin >> ar[0][j]; if (ar[0][j] > n * m || mark[ar[0][j]]) return cout << 0, 0; mark[ar[0][j]] = 1; } memset(mark, 0, sizeof mark); for (int i = 0; i < m; i++) { cin >> ar[1][i]; if (ar[1][i] > n * m || mark[ar[1][i]]) return cout << 0, 0; mark[ar[1][i]] = 1; } sort(ar[0], ar[0] + n, [&](int a, int b) { return a > b; }); sort(ar[1], ar[1] + m, [&](int a, int b) { return a > b; }); int l = 0, r = 0; for (int i = m * n; i; i--) { while (l < n && ar[0][l] >= i) l++; while (r < m && ar[1][r] >= i) r++; assert(l && r); // cout << l << ',' << r << " " << ar[0][l - 1] << ' ' << ar[1][r - 1] << //endl; if (ar[0][l - 1] == i && ar[1][r - 1] == i) ; else if (ar[0][l - 1] == i) ans = (ans * r) % mod; else if (ar[1][r - 1] == i) ans = (ans * l) % mod; else ans = (ans * (l * r - (m * n - i))) % mod; } cout << ans; }
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 1e3 + 10, mod = 1e9 + 7; int n, m, ans = 1, ar[2][N], mark[N * N]; int32_t main() { cin >> n >> m; for (int j = 0; j < n; j++) { cin >> ar[0][j]; if (ar[0][j] > n * m || mark[ar[0][j]]) return cout << 0, 0; mark[ar[0][j]] = 1; } memset(mark, 0, sizeof mark); for (int i = 0; i < m; i++) { cin >> ar[1][i]; if (ar[1][i] > n * m || mark[ar[1][i]]) return cout << 0, 0; mark[ar[1][i]] = 1; } sort(ar[0], ar[0] + n, [&](int a, int b) { return a > b; }); sort(ar[1], ar[1] + m, [&](int a, int b) { return a > b; }); int l = 0, r = 0; for (int i = m * n; i; i--) { while (l < n && ar[0][l] >= i) l++; while (r < m && ar[1][r] >= i) r++; if (!l || !r) return cout << 0, 0; // cout << l << ',' << r << " " << ar[0][l - 1] << ' ' << ar[1][r - 1] << //endl; if (ar[0][l - 1] == i && ar[1][r - 1] == i) ; else if (ar[0][l - 1] == i) ans = (ans * r) % mod; else if (ar[1][r - 1] == i) ans = (ans * l) % mod; else ans = (ans * (l * r - (m * n - i))) % mod; } cout << ans; }
replace
34
36
34
36
0