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
p02613
Python
Runtime Error
N, *s = map(open(0).read().split()) for v in ("AC", "WA", "TLE", "RE"): print("{} x {}".format(v, s.count(v)))
N = int(input()) s = [input() for i in range(N)] for v in ("AC", "WA", "TLE", "RE"): print("{} x {}".format(v, s.count(v)))
replace
0
1
0
2
TypeError: map() must have at least two arguments.
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02613/Python/s429316079.py", line 1, in <module> N, *s = map(open(0).read().split()) TypeError: map() must have at least two arguments.
p02613
C++
Runtime Error
#include <iostream> using namespace std; int main() { string s[100]; int i, n; int AC = 0, WA = 0, TLE = 0, RE = 0; cin >> n; for (i = 0; i < n; i++) { cin >> s[i]; } for (i = 0; i < n; i++) { if (s[i] == "AC") { AC += 1; } else if (s[i] == "WA") { WA += 1; } else if (s[i] == "TLE") { TLE += 1; } else if (s[i] == "RE") { RE += 1; } } cout << "AC" << " " << "x" << " " << AC << endl; cout << "WA" << " " << "x" << " " << WA << endl; cout << "TLE" << " " << "x" << " " << TLE << endl; cout << "RE" << " " << "x" << " " << RE << endl; return 0; }
#include <iostream> using namespace std; int main() { string s[100001]; int i, n; int AC = 0, WA = 0, TLE = 0, RE = 0; cin >> n; for (i = 0; i < n; i++) { cin >> s[i]; } for (i = 0; i < n; i++) { if (s[i] == "AC") { AC += 1; } else if (s[i] == "WA") { WA += 1; } else if (s[i] == "TLE") { TLE += 1; } else if (s[i] == "RE") { RE += 1; } } cout << "AC" << " " << "x" << " " << AC << endl; cout << "WA" << " " << "x" << " " << WA << endl; cout << "TLE" << " " << "x" << " " << TLE << endl; cout << "RE" << " " << "x" << " " << RE << endl; return 0; }
replace
5
6
5
6
0
p02613
C++
Runtime Error
#include <algorithm> #include <iostream> #include <math.h> #include <string> typedef long long ll; using namespace std; int main() { int N; cin >> N; int ac = 0; int wa = 0; int tle = 0; int re = 0; string s[N]; for (int i = 0; i < N; i++) { cin >> s[i]; } for (int i = 0; i < N; i++) { if (s[i] == "AC") ac++; if (s[i] == "WA") wa++; if (s[i] == "TLE") tle++; if (s[i] == "RE") re++; } cout << "AC x " + ac << endl; cout << "WA x " + wa << endl; cout << "TLE x " + tle << endl; cout << "RE x " + re << endl; }
#include <algorithm> #include <iostream> #include <math.h> #include <string> typedef long long ll; using namespace std; int main() { int N; cin >> N; int ac = 0; int wa = 0; int tle = 0; int re = 0; string s[N]; for (int i = 0; i < N; i++) { cin >> s[i]; } for (int i = 0; i < N; i++) { if (s[i] == "AC") ac++; if (s[i] == "WA") wa++; if (s[i] == "TLE") tle++; if (s[i] == "RE") re++; } cout << "AC x " << ac << endl; cout << "WA x " << wa << endl; cout << "TLE x " << tle << endl; cout << "RE x " << re << endl; }
replace
28
32
28
32
0
p02613
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; int ac, wa, tle, re; ac = wa = tle = re = 0; cin >> n; string s[10000]; for (int i = 0; i < n; i++) { cin >> s[i]; if (s[i] == "AC") { ac++; } else if (s[i] == "WA") { wa++; } else if (s[i] == "TLE") { tle++; } else if (s[i] == "RE") { re++; } } cout << "AC x " << ac << endl; cout << "WA x " << wa << endl; cout << "TLE x " << tle << endl; cout << "RE x " << re << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; int ac, wa, tle, re; ac = wa = tle = re = 0; cin >> n; string s[100000]; for (int i = 0; i < n; i++) { cin >> s[i]; if (s[i] == "AC") { ac++; } else if (s[i] == "WA") { wa++; } else if (s[i] == "TLE") { tle++; } else if (s[i] == "RE") { re++; } } cout << "AC x " << ac << endl; cout << "WA x " << wa << endl; cout << "TLE x " << tle << endl; cout << "RE x " << re << endl; }
replace
8
9
8
9
0
p02613
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int MAX = 2147483647; const double PI = 3.14159265358979323846; int main() { int n; string a; int s[4]; cin >> n; for (int i = 0; i < n; i++) { s[i] = 0; } for (int i = 0; i < n; i++) { cin >> a; if (a == "AC") s[0]++; if (a == "WA") s[1]++; if (a == "TLE") s[2]++; if (a == "RE") s[3]++; } cout << "AC x " << s[0] << endl; cout << "WA x " << s[1] << endl; cout << "TLE x " << s[2] << endl; cout << "RE x " << s[3] << endl; }
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int MAX = 2147483647; const double PI = 3.14159265358979323846; int main() { int n; string a; int s[4]; cin >> n; for (int i = 0; i < 4; i++) { s[i] = 0; } for (int i = 0; i < n; i++) { cin >> a; if (a == "AC") s[0]++; if (a == "WA") s[1]++; if (a == "TLE") s[2]++; if (a == "RE") s[3]++; } cout << "AC x " << s[0] << endl; cout << "WA x " << s[1] << endl; cout << "TLE x " << s[2] << endl; cout << "RE x " << s[3] << endl; }
replace
13
14
13
14
-11
p02613
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, AC, WA, TLE, RE; AC = WA = TLE = RE = 0; string S[10000]; cin >> N; for (int i = 0; i < N; i++) { cin >> S[i]; if (S[i] == "AC") AC++; if (S[i] == "WA") WA++; if (S[i] == "TLE") TLE++; if (S[i] == "RE") RE++; } cout << "AC x " << AC << endl; cout << "WA x " << WA << endl; cout << "TLE x " << TLE << endl; cout << "RE x " << RE << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N, AC, WA, TLE, RE; AC = WA = TLE = RE = 0; string S[100000]; cin >> N; for (int i = 0; i < N; i++) { cin >> S[i]; if (S[i] == "AC") AC++; if (S[i] == "WA") WA++; if (S[i] == "TLE") TLE++; if (S[i] == "RE") RE++; } cout << "AC x " << AC << endl; cout << "WA x " << WA << endl; cout << "TLE x " << TLE << endl; cout << "RE x " << RE << endl; return 0; }
replace
5
6
5
6
0
p02613
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define REP(i, N) for (int i = 0; i < (int)N; i++) #define FOR(i, a, b) for (int i = a; i < (int)b; i++) #define ALL(x) (x).begin(), (x).end() #define INF (1 << 30) #define LLINF (1LL << 62) #define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__) constexpr int MOD = 1000000007; using ll = long long; using Pii = pair<int, int>; using Pll = pair<ll, ll>; inline int popcount(ll x) { return __builtin_popcountll(x); } inline int div2num(ll x) { return __builtin_ctzll(x); } inline bool bit(ll x, int b) { return (x >> b) & 1; } template <class T> string to_string(T s); template <class S, class T> string to_string(pair<S, T> p); string to_string(string s) { return s; } string to_string(const char s[]) { return to_string(string(s)); } template <class T> string to_string(T v) { if (v.empty()) return "{}"; string ret = "{"; for (auto x : v) ret += to_string(x) + ","; ret.back() = '}'; return ret; } template <class S, class T> string to_string(pair<S, T> p) { return "{" + to_string(p.first) + ":" + to_string(p.second) + "}"; } void debug() { cerr << endl; } template <class Head, class... Tail> void debug(Head head, Tail... tail) { cerr << to_string(head) << " "; debug(tail...); } struct IO { static constexpr size_t buf_size = 1 << 18; char buf_in[buf_size], buf_out[buf_size]; size_t pt_in = 0, pt_out = 0, tail_in = 0; char strs[10000 * 4]; inline size_t num_digits(long long x) { if (x >= (long long)1e9) { if (x >= (long long)1e18) return 19; if (x >= (long long)1e17) return 18; if (x >= (long long)1e16) return 17; if (x >= (long long)1e15) return 16; if (x >= (long long)1e14) return 15; if (x >= (long long)1e13) return 14; if (x >= (long long)1e12) return 13; if (x >= (long long)1e11) return 12; if (x >= (long long)1e10) return 11; return 10; } else { if (x >= (long long)1e8) return 9; if (x >= (long long)1e7) return 8; if (x >= (long long)1e6) return 7; if (x >= (long long)1e5) return 6; if (x >= (long long)1e4) return 5; if (x >= (long long)1e3) return 4; if (x >= (long long)1e2) return 3; if (x >= (long long)1e1) return 2; return 1; } } IO() { load(); for (int i = 0; i < 10000; ++i) { int j = i; for (int t = 3; t >= 0; --t) { strs[i * 4 + t] = j % 10 + '0'; j /= 10; } } } ~IO() { flush(); } inline void load() { memcpy(buf_in, buf_in + pt_in, tail_in - pt_in); size_t width = tail_in - pt_in; tail_in = width + fread(buf_in + width, 1, buf_size - width, stdin); pt_in = 0; } inline void flush() { fwrite(buf_out, 1, pt_out, stdout); pt_out = 0; } inline void read(char &c) { c = buf_in[pt_in++]; } template <class T> inline void read(T &x) { if (pt_in + 32 > tail_in) load(); char c; do { read(c); } while (c < '0'); bool minus = 0; if (c == '-') { minus = 1; read(c); } x = 0; while (c >= '0') { x = x * 10 + (c & 15); read(c); } if (minus) x = -x; } inline void write(char c) { buf_out[pt_out++] = c; } template <class T> inline void write(T x) { if (pt_out > buf_size - 32) flush(); if (x < 0) { write('-'); x = -x; } size_t digits = num_digits(x); int i; for (i = pt_out + digits - 4; i > (int)pt_out; i -= 4) { memcpy(buf_out + i, strs + (x % 10000) * 4, 4); x /= 10000; } memcpy(buf_out + pt_out, strs + x * 4 + (pt_out - i), 4 + i - pt_out); pt_out += digits; } inline void write(const char *s) { if (pt_out > buf_size - 32) flush(); for (int i = 0; s[i] != 0; ++i) write(s[i]); } template <class T> inline void writeln(T x) { write(x); write('\n'); } } io; int main() { int N; io.read(N); int a = 0, b = 0, c = 0; REP(i, N) { char ch; io.read(ch); if (ch == 'A') a++; else if (ch == 'W') b++; else if (ch == 'T') c++; while (ch != '\n') io.read(ch); } io.write("AC x "); io.writeln(a); io.write("WA x "); io.writeln(b); io.write("TLE x "); io.writeln(c); io.write("RE x "); io.writeln(N - a - b - c); return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define REP(i, N) for (int i = 0; i < (int)N; i++) #define FOR(i, a, b) for (int i = a; i < (int)b; i++) #define ALL(x) (x).begin(), (x).end() #define INF (1 << 30) #define LLINF (1LL << 62) #define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__) constexpr int MOD = 1000000007; using ll = long long; using Pii = pair<int, int>; using Pll = pair<ll, ll>; inline int popcount(ll x) { return __builtin_popcountll(x); } inline int div2num(ll x) { return __builtin_ctzll(x); } inline bool bit(ll x, int b) { return (x >> b) & 1; } template <class T> string to_string(T s); template <class S, class T> string to_string(pair<S, T> p); string to_string(string s) { return s; } string to_string(const char s[]) { return to_string(string(s)); } template <class T> string to_string(T v) { if (v.empty()) return "{}"; string ret = "{"; for (auto x : v) ret += to_string(x) + ","; ret.back() = '}'; return ret; } template <class S, class T> string to_string(pair<S, T> p) { return "{" + to_string(p.first) + ":" + to_string(p.second) + "}"; } void debug() { cerr << endl; } template <class Head, class... Tail> void debug(Head head, Tail... tail) { cerr << to_string(head) << " "; debug(tail...); } struct IO { static constexpr size_t buf_size = 1 << 18; char buf_in[buf_size], buf_out[buf_size]; size_t pt_in = 0, pt_out = 0, tail_in = 0; char strs[10000 * 4]; inline size_t num_digits(long long x) { if (x >= (long long)1e9) { if (x >= (long long)1e18) return 19; if (x >= (long long)1e17) return 18; if (x >= (long long)1e16) return 17; if (x >= (long long)1e15) return 16; if (x >= (long long)1e14) return 15; if (x >= (long long)1e13) return 14; if (x >= (long long)1e12) return 13; if (x >= (long long)1e11) return 12; if (x >= (long long)1e10) return 11; return 10; } else { if (x >= (long long)1e8) return 9; if (x >= (long long)1e7) return 8; if (x >= (long long)1e6) return 7; if (x >= (long long)1e5) return 6; if (x >= (long long)1e4) return 5; if (x >= (long long)1e3) return 4; if (x >= (long long)1e2) return 3; if (x >= (long long)1e1) return 2; return 1; } } IO() { load(); for (int i = 0; i < 10000; ++i) { int j = i; for (int t = 3; t >= 0; --t) { strs[i * 4 + t] = j % 10 + '0'; j /= 10; } } } ~IO() { flush(); } inline void load() { memcpy(buf_in, buf_in + pt_in, tail_in - pt_in); size_t width = tail_in - pt_in; tail_in = width + fread(buf_in + width, 1, buf_size - width, stdin); pt_in = 0; } inline void flush() { fwrite(buf_out, 1, pt_out, stdout); pt_out = 0; } inline void read(char &c) { c = buf_in[pt_in++]; } template <class T> inline void read(T &x) { if (pt_in + 32 > tail_in) load(); char c; do { read(c); } while (c < '0'); bool minus = 0; if (c == '-') { minus = 1; read(c); } x = 0; while (c >= '0') { x = x * 10 + (c & 15); read(c); } if (minus) x = -x; } inline void write(char c) { buf_out[pt_out++] = c; } template <class T> inline void write(T x) { if (pt_out > buf_size - 32) flush(); if (x < 0) { write('-'); x = -x; } size_t digits = num_digits(x); int i; for (i = pt_out + digits - 4; i > (int)pt_out; i -= 4) { memcpy(buf_out + i, strs + (x % 10000) * 4, 4); x /= 10000; } memcpy(buf_out + pt_out, strs + x * 4 + (pt_out - i), 4 + i - pt_out); pt_out += digits; } inline void write(const char *s) { if (pt_out > buf_size - 32) flush(); for (int i = 0; s[i] != 0; ++i) write(s[i]); } template <class T> inline void writeln(T x) { write(x); write('\n'); } } io; int main() { int N; io.read(N); int a = 0, b = 0, c = 0; REP(i, N) { char ch; io.read(ch); if (ch == 'A') a++; else if (ch == 'W') b++; else if (ch == 'T') c++; while (ch != '\n') io.read(ch); if (io.pt_in + 32 > io.tail_in) io.load(); } io.write("AC x "); io.writeln(a); io.write("WA x "); io.writeln(b); io.write("TLE x "); io.writeln(c); io.write("RE x "); io.writeln(N - a - b - c); return 0; }
insert
194
194
194
196
0
p02613
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> count(N, 0); for (int i = 0; i < N; i++) { string S; cin >> S; if (S == "AC") { count.at(0)++; } else if (S == "WA") { count.at(1)++; } else if (S == "TLE") { count.at(2)++; } else if (S == "RE") { count.at(3)++; } } printf("AC x %d\n", count.at(0)); printf("WA x %d\n", count.at(1)); printf("TLE x %d\n", count.at(2)); printf("RE x %d\n", count.at(3)); }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> count(4, 0); for (int i = 0; i < N; i++) { string S; cin >> S; if (S == "AC") { count.at(0)++; } else if (S == "WA") { count.at(1)++; } else if (S == "TLE") { count.at(2)++; } else if (S == "RE") { count.at(3)++; } } printf("AC x %d\n", count.at(0)); printf("WA x %d\n", count.at(1)); printf("TLE x %d\n", count.at(2)); printf("RE x %d\n", count.at(3)); }
replace
7
8
7
8
0
p02613
C++
Runtime Error
#include <algorithm> #include <iostream> #include <math.h> #include <string.h> #include <string> using namespace std; void b_judge_status_summary(void) { int n; string s[10000]; cin >> n; for (int i = 0; i < n; i++) cin >> s[i]; int ac_cnt = 0; int wa_cnt = 0; int tle_cnt = 0; int re_cnt = 0; for (int i = 0; i < n; i++) { string ss = s[i]; if (ss[0] == 'A') ac_cnt++; else if (ss[0] == 'W') wa_cnt++; else if (ss[0] == 'T') tle_cnt++; else re_cnt++; } cout << "AC x " << ac_cnt << endl; cout << "WA x " << wa_cnt << endl; cout << "TLE x " << tle_cnt << endl; cout << "RE x " << re_cnt << endl; } int main() { b_judge_status_summary(); return 0; }
#include <algorithm> #include <iostream> #include <math.h> #include <string.h> #include <string> using namespace std; void b_judge_status_summary(void) { int n; string s[100000]; cin >> n; for (int i = 0; i < n; i++) cin >> s[i]; int ac_cnt = 0; int wa_cnt = 0; int tle_cnt = 0; int re_cnt = 0; for (int i = 0; i < n; i++) { string ss = s[i]; if (ss[0] == 'A') ac_cnt++; else if (ss[0] == 'W') wa_cnt++; else if (ss[0] == 'T') tle_cnt++; else re_cnt++; } cout << "AC x " << ac_cnt << endl; cout << "WA x " << wa_cnt << endl; cout << "TLE x " << tle_cnt << endl; cout << "RE x " << re_cnt << endl; } int main() { b_judge_status_summary(); return 0; }
replace
9
10
9
10
0
p02613
C++
Runtime Error
#include <cstdio> #include <iostream> #include <math.h> using namespace std; int main() { int n, w, a, t, r, i; t = r = a = w = 0; cin >> n; char s[10000][4]; for (i = 0; i < n; i++) { scanf("%s", s[i]); if (s[i][0] == 'A') { a++; } else if (s[i][0] == 'W') { w++; } else if (s[i][0] == 'T') { t++; } else { r++; } } printf("AC x %d\n", a); printf("WA x %d\n", w); printf("TLE x %d\n", t); printf("RE x %d\n", r); }
#include <cstdio> #include <iostream> #include <math.h> using namespace std; int main() { int n, w, a, t, r, i; t = r = a = w = 0; cin >> n; char s[n][4]; for (i = 0; i < n; i++) { scanf("%s", s[i]); if (s[i][0] == 'A') { a++; } else if (s[i][0] == 'W') { w++; } else if (s[i][0] == 'T') { t++; } else { r++; } } printf("AC x %d\n", a); printf("WA x %d\n", w); printf("TLE x %d\n", t); printf("RE x %d\n", r); }
replace
8
9
8
9
0
p02613
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pii; typedef tuple<ll, ll, ll> ti; #define REP(a, b, c) for (ll a = b; a < (c); a++) #define PER(a, b, c) for (ll a = b; a >= (c); a--) ll ii() { ll x; cin >> x; return x; } string is() { string x; cin >> x; return x; } ld id() { ld x; cin >> x; return x; } void oi(ll x) { cout << x; } void od(ld x) { cout << fixed << setprecision(10) << x; } void os(string x) { cout << x; } void oe() { cout << endl; } void oie(ll x) { oi(x); oe(); } void ode(ld x) { od(x); oe(); } void ose(string x) { os(x); oe(); } ll mod = 1000000007; int main() { vector<string> ss = {"AC", "WA", "TLE", "RE"}; vector<ll> sm(4, 0); ll N = ii(); REP(i, 0, N) { string s = is(); REP(i, 0, 4) { if (ss[i] == s) { sm[i]++; } } } REP(i, 0, N) { cout << ss[i] << " x " << sm[i] << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pii; typedef tuple<ll, ll, ll> ti; #define REP(a, b, c) for (ll a = b; a < (c); a++) #define PER(a, b, c) for (ll a = b; a >= (c); a--) ll ii() { ll x; cin >> x; return x; } string is() { string x; cin >> x; return x; } ld id() { ld x; cin >> x; return x; } void oi(ll x) { cout << x; } void od(ld x) { cout << fixed << setprecision(10) << x; } void os(string x) { cout << x; } void oe() { cout << endl; } void oie(ll x) { oi(x); oe(); } void ode(ld x) { od(x); oe(); } void ose(string x) { os(x); oe(); } ll mod = 1000000007; int main() { vector<string> ss = {"AC", "WA", "TLE", "RE"}; vector<ll> sm(4, 0); ll N = ii(); REP(i, 0, N) { string s = is(); REP(i, 0, 4) { if (ss[i] == s) { sm[i]++; } } } REP(i, 0, 4) { cout << ss[i] << " x " << sm[i] << endl; } return 0; }
replace
58
59
58
59
-11
p02613
C++
Runtime Error
#include <iostream> #include <map> int main() { int n; std::cin >> n; std::map<std::string, int> mp; for (int i = 0; i < n; ++i) { std::string s; std::cin >> s; mp[s] += 1; } std::cout << "AC x " + mp["AC"] << '\n'; std::cout << "WA x " + mp["WA"] << '\n'; std::cout << "TLE x " + mp["TLE"] << '\n'; std::cout << "RE x " + mp["RE"] << '\n'; return 0; }
#include <iostream> #include <map> int main() { int n; std::cin >> n; std::map<std::string, int> mp; for (int i = 0; i < n; ++i) { std::string s; std::cin >> s; mp[s] += 1; } std::cout << "AC x " << mp["AC"] << '\n'; std::cout << "WA x " << mp["WA"] << '\n'; std::cout << "TLE x " << mp["TLE"] << '\n'; std::cout << "RE x " << mp["RE"] << '\n'; return 0; }
replace
14
18
14
18
0
p02613
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; vector<string> vec(a); vector<int> ans(4); for (int i = 0; i < a; i++) { cin >> vec.at(i); } for (int i = 0; i < 4; i++) { if (vec.at(i) == "AC") { ans.at(0) += 1; } else if (vec.at(i) == "WA") { ans.at(1) += 1; } else if (vec.at(i) == "TLE") { ans.at(2) += 1; } else if (vec.at(i) == "RE") { ans.at(3) += 1; } } cout << "AC x " << ans.at(0) << endl; cout << "WA x " << ans.at(1) << endl; cout << "TLE x " << ans.at(2) << endl; cout << "RE x " << ans.at(3) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; vector<string> vec(a); vector<int> ans(4); for (int i = 0; i < a; i++) { cin >> vec.at(i); } for (int i = 0; i < a; i++) { if (vec.at(i) == "AC") { ans.at(0) += 1; } else if (vec.at(i) == "WA") { ans.at(1) += 1; } else if (vec.at(i) == "TLE") { ans.at(2) += 1; } else if (vec.at(i) == "RE") { ans.at(3) += 1; } } cout << "AC x " << ans.at(0) << endl; cout << "WA x " << ans.at(1) << endl; cout << "TLE x " << ans.at(2) << endl; cout << "RE x " << ans.at(3) << endl; }
replace
11
12
11
12
0
p02613
C++
Runtime Error
#pragma region kyomukyomupurin /** * author : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏 * created : 2020-07-05 22:47:33 **/ #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <chrono> #include <cmath> #include <complex> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; using int64 = long long; template <class T> inline void eraque(std::vector<T> &vec) { vec.erase(std::unique(vec.begin(), vec.end()), vec.end()); return; } template <class T> inline int lower_position(const std::vector<T> &vec, T value) { return static_cast<int>(std::distance( vec.begin(), std::lower_bound(vec.begin(), vec.end(), value))); } template <class T> inline int upper_position(const std::vector<T> &vec, T value) { return static_cast<int>(std::distance( vec.begin(), std::upper_bound(vec.begin(), vec.end(), value))); } template <class T> std::string to_binary(T n) { assert(n > 0); std::string ret = ""; while (n) ret += (n & 1) ? '1' : '0', n >>= 1; std::reverse(ret.begin(), ret.end()); return ret; } template <class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>; template <class T, class U> std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template <class Tuple, std::size_t... Is> void tuple_out(std::ostream &os, const Tuple &tp, std::index_sequence<Is...>) { ((os << (Is ? ", " : "(") << std::get<Is>(tp)), ...) << ")"; } template <class... Args> std::ostream &operator<<(std::ostream &os, const std::tuple<Args...> &tp) { tuple_out(os, tp, std::index_sequence_for<Args...>{}); return os; } template <class T> std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec) { int n = 0; for (auto e : vec) os << (n++ ? ", " : "{") << e; return os << (n ? "}" : "{}"); } template <class T, class Compare> std::ostream &operator<<(std::ostream &os, const std::set<T, Compare> &st) { int n = 0; for (auto e : st) os << (n++ ? ", " : "{") << e; return os << (n ? "}" : "{}"); } template <class T, class U, class Compare> std::ostream &operator<<(std::ostream &os, const std::map<T, U, Compare> &mp) { int n = 0; for (auto e : mp) os << (n++ ? ", " : "{") << e; return os << (n ? "}" : "{}"); } template <class T> std::istream &operator>>(std::istream &is, std::vector<T> &vec) { for (T &e : vec) is >> e; return is; } template <class T, class U> std::istream &operator>>(std::istream &is, std::pair<T, U> &p) { return is >> p.first >> p.second; } template <class Tuple, std::size_t... Is> void tuple_in(std::istream &is, Tuple &tp, std::index_sequence<Is...>) { ((is >> std::get<Is>(tp)), ...); } template <class... Args> std::istream &operator>>(std::istream &is, std::tuple<Args...> &tp) { tuple_in(is, tp, std::index_sequence_for<Args...>{}); return is; } #define all(_) begin(_), end(_) #define rall(_) rbegin(_), rend(_) #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__) #else #define debug(...) #endif void debug_out() { std::cerr << '\n'; } template <class Head, class... Tail> void debug_out(Head &&head, Tail &&...tail) { std::cerr << head; if (sizeof...(Tail) != 0) std::cerr << ", "; debug_out(std::forward<Tail>(tail)...); } #pragma endregion kyomukyomupurin namespace FastIO { class Scanner { static constexpr int buf_size = (1 << 18); static constexpr int integer_size = 20; char buf[buf_size] = {}; char *cur = buf, *ed = buf; public: Scanner() {} template <class T> inline Scanner &operator>>(T &val) { read(val); return *this; } private: inline void reload() { size_t len = ed - cur; memmove(buf, cur, len); char *tmp = buf + len; ed = tmp + fread(tmp, 1, buf_size - len, stdin); *ed = 0; cur = buf; } inline void skip_space() { while (true) { if (cur == ed) reload(); while (*cur == ' ' || *cur == '\n') ++cur; if (__builtin_expect(cur != ed, 1)) return; } } template <class T, std::enable_if_t<std::is_same<T, int>::value, int> = 0> inline void read(T &num) { skip_space(); if (cur + integer_size >= ed) reload(); bool neg = false; num = 0; if (*cur == '-') neg = true, ++cur; while (*cur >= '0') num = num * 10 + (*cur ^ 48), ++cur; if (neg) num = -num; } template <class T, std::enable_if_t<std::is_same<T, int64>::value, int> = 0> inline void read(T &num) { skip_space(); if (cur + integer_size >= ed) reload(); bool neg = false; num = 0; if (*cur == '-') neg = true, ++cur; while (*cur >= '0') num = num * 10 + (*cur ^ 48), ++cur; if (neg) num = -num; } template <class T, std::enable_if_t<std::is_same<T, std::string>::value, int> = 0> inline void read(T &str) { skip_space(); if (cur + str.size() >= ed) reload(); auto it = cur; while (!(*cur == ' ' || *cur == '\n')) ++cur; str = std::string(it, cur); } template <class T, std::enable_if_t<std::is_same<T, char>::value, int> = 0> inline void read(T &c) { skip_space(); if (cur + 1 >= ed) reload(); c = *cur, ++cur; } template <class T, std::enable_if_t<std::is_same<T, double>::value, int> = 0> inline void read(T &num) { skip_space(); if (cur + integer_size >= ed) reload(); bool neg = false; num = 0; if (*cur == '-') neg = true, ++cur; while (*cur >= '0' && *cur <= '9') num = num * 10 + (*cur - '0'), ++cur; if (*cur != '.') return; ++cur; T base = 0.1; while (*cur >= '0' && *cur <= '9') { num += base * (*cur - '0'); ++cur; base *= 0.1; } if (neg) num = -num; } template <class T, std::enable_if_t<std::is_same<T, long double>::value, int> = 0> inline void read(T &num) { skip_space(); if (cur + integer_size >= ed) reload(); bool neg = false; num = 0; if (*cur == '-') neg = true, ++cur; while (*cur >= '0' && *cur <= '9') num = num * 10 + (*cur - '0'), ++cur; if (*cur != '.') return; ++cur; T base = 0.1; while (*cur >= '0' && *cur <= '9') { num += base * (*cur - '0'); ++cur; base *= 0.1; } if (neg) num = -num; } template <class T> inline void read(std::vector<T> &vec) { for (T &e : vec) read(e); } template <class T, class U> inline void read(std::pair<T, U> &p) { read(p.first, p.second); } template <class Tuple, std::size_t... Is> inline void tuple_scan(Tuple &tp, std::index_sequence<Is...>) { (read(std::get<Is>(tp)), ...); } template <class... Args> inline void read(std::tuple<Args...> &tp) { tuple_scan(tp, std::index_sequence_for<Args...>{}); } inline void read() {} template <class Head, class... Tail> inline void read(Head &&head, Tail &&...tail) { read(head); read(std::forward<Tail>(tail)...); } }; class Printer { static constexpr int buf_size = (1 << 18); static constexpr int integer_size = 20; static constexpr int margin = 1; static constexpr int n = 10000; char buf[buf_size + margin] = {}; char integer[integer_size + margin] = {}; char table[n * 4] = {}; char *cur = buf; public: constexpr Printer() { build(); } ~Printer() { flush(); } template <class T> inline Printer &operator<<(T val) { write(val); return *this; } private: constexpr void build() { for (int i = 0; i < 10000; ++i) { int tmp = i; for (int j = 3; j >= 0; --j) { table[i * 4 + j] = tmp % 10 + '0'; tmp /= 10; } } } inline void flush() { fwrite(buf, 1, cur - buf, stdout); cur = buf; } template <class T, std::enable_if_t<std::is_same<T, int>::value, int> = 0> inline int get_digit(T n) { if (n >= (int)1e5) { if (n >= (int)1e8) return 9; if (n >= (int)1e7) return 8; if (n >= (int)1e6) return 7; return 6; } else { if (n >= (int)1e4) return 5; if (n >= (int)1e3) return 4; if (n >= (int)1e2) return 3; if (n >= (int)1e1) return 2; return 1; } } template <class T, std::enable_if_t<std::is_same<T, int64>::value, int> = 0> inline int get_digit(T n) { if (n >= (int64)1e10) { if (n >= (int64)1e14) { if (n >= (int64)1e18) return 19; if (n >= (int64)1e17) return 18; if (n >= (int64)1e16) return 17; if (n >= (int64)1e15) return 16; return 15; } else { if (n >= (int64)1e14) return 15; if (n >= (int64)1e13) return 14; if (n >= (int64)1e12) return 13; if (n >= (int64)1e11) return 12; return 11; } } else { if (n >= (int64)1e5) { if (n >= (int64)1e9) return 10; if (n >= (int64)1e8) return 9; if (n >= (int64)1e7) return 8; if (n >= (int64)1e6) return 7; return 6; } else { if (n >= (int64)1e4) return 5; if (n >= (int64)1e3) return 4; if (n >= (int64)1e2) return 3; if (n >= (int64)1e1) return 2; return 1; } } } template <class T, std::enable_if_t<std::is_same<T, int>::value, int> = 0> inline void write(T num) { if (__builtin_expect(cur + integer_size >= buf + buf_size, 0)) flush(); if (num == 0) { write('0'); return; } if (num < 0) { write('-'); num = -num; } int len = get_digit(num); int digits = len; while (num >= 10000) { memcpy(cur + len - 4, table + (num % 10000) * 4, 4); num /= 10000; len -= 4; } memcpy(cur, table + num * 4 + (4 - len), len); cur += digits; } template <class T, std::enable_if_t<std::is_same<T, int64>::value, int> = 0> inline void write(T num) { if (__builtin_expect(cur + integer_size >= buf + buf_size, 0)) flush(); if (num == 0) { write('0'); return; } if (num < 0) { write('-'); num = -num; } int len = get_digit(num); int digits = len; while (num >= 10000) { memcpy(cur + len - 4, table + (num % 10000) * 4, 4); num /= 10000; len -= 4; } memcpy(cur, table + num * 4 + (4 - len), len); cur += digits; } template <class T, std::enable_if_t<std::is_same<T, char>::value, int> = 0> inline void write(T c) { if (__builtin_expect(cur + 1 >= buf + buf_size, 0)) flush(); *cur = c; ++cur; } template <class T, std::enable_if_t<std::is_same<T, std::string>::value, int> = 0> inline void write(T str) { if (__builtin_expect(cur + str.size() >= buf + buf_size, 0)) flush(); for (char c : str) write(c); } }; } // namespace FastIO FastIO::Scanner fin; FastIO::Printer fout; int main() { // ios_base::sync_with_stdio(false); // cin.tie(nullptr); int n; fin >> n; map<string, int> mp; for (int i = 0; i < n; ++i) { string s; fin >> s; ++mp[s]; } fout << "AC x "s << mp["AC"] << '\n'; fout << "WA x "s << mp["WA"] << '\n'; fout << "TLE x "s << mp["TLE"] << '\n'; fout << "RE x "s << mp["RE"] << '\n'; return 0; }
#pragma region kyomukyomupurin /** * author : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏 * created : 2020-07-05 22:47:33 **/ #include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <chrono> #include <cmath> #include <complex> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; using int64 = long long; template <class T> inline void eraque(std::vector<T> &vec) { vec.erase(std::unique(vec.begin(), vec.end()), vec.end()); return; } template <class T> inline int lower_position(const std::vector<T> &vec, T value) { return static_cast<int>(std::distance( vec.begin(), std::lower_bound(vec.begin(), vec.end(), value))); } template <class T> inline int upper_position(const std::vector<T> &vec, T value) { return static_cast<int>(std::distance( vec.begin(), std::upper_bound(vec.begin(), vec.end(), value))); } template <class T> std::string to_binary(T n) { assert(n > 0); std::string ret = ""; while (n) ret += (n & 1) ? '1' : '0', n >>= 1; std::reverse(ret.begin(), ret.end()); return ret; } template <class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>; template <class T, class U> std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template <class Tuple, std::size_t... Is> void tuple_out(std::ostream &os, const Tuple &tp, std::index_sequence<Is...>) { ((os << (Is ? ", " : "(") << std::get<Is>(tp)), ...) << ")"; } template <class... Args> std::ostream &operator<<(std::ostream &os, const std::tuple<Args...> &tp) { tuple_out(os, tp, std::index_sequence_for<Args...>{}); return os; } template <class T> std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec) { int n = 0; for (auto e : vec) os << (n++ ? ", " : "{") << e; return os << (n ? "}" : "{}"); } template <class T, class Compare> std::ostream &operator<<(std::ostream &os, const std::set<T, Compare> &st) { int n = 0; for (auto e : st) os << (n++ ? ", " : "{") << e; return os << (n ? "}" : "{}"); } template <class T, class U, class Compare> std::ostream &operator<<(std::ostream &os, const std::map<T, U, Compare> &mp) { int n = 0; for (auto e : mp) os << (n++ ? ", " : "{") << e; return os << (n ? "}" : "{}"); } template <class T> std::istream &operator>>(std::istream &is, std::vector<T> &vec) { for (T &e : vec) is >> e; return is; } template <class T, class U> std::istream &operator>>(std::istream &is, std::pair<T, U> &p) { return is >> p.first >> p.second; } template <class Tuple, std::size_t... Is> void tuple_in(std::istream &is, Tuple &tp, std::index_sequence<Is...>) { ((is >> std::get<Is>(tp)), ...); } template <class... Args> std::istream &operator>>(std::istream &is, std::tuple<Args...> &tp) { tuple_in(is, tp, std::index_sequence_for<Args...>{}); return is; } #define all(_) begin(_), end(_) #define rall(_) rbegin(_), rend(_) #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__) #else #define debug(...) #endif void debug_out() { std::cerr << '\n'; } template <class Head, class... Tail> void debug_out(Head &&head, Tail &&...tail) { std::cerr << head; if (sizeof...(Tail) != 0) std::cerr << ", "; debug_out(std::forward<Tail>(tail)...); } #pragma endregion kyomukyomupurin namespace FastIO { class Scanner { static constexpr int buf_size = (1 << 18); static constexpr int integer_size = 20; char buf[buf_size] = {}; char *cur = buf, *ed = buf; public: Scanner() {} template <class T> inline Scanner &operator>>(T &val) { read(val); return *this; } private: inline void reload() { size_t len = ed - cur; memmove(buf, cur, len); char *tmp = buf + len; ed = tmp + fread(tmp, 1, buf_size - len, stdin); *ed = 0; cur = buf; } inline void skip_space() { while (true) { if (cur == ed) reload(); while (*cur == ' ' || *cur == '\n') ++cur; if (__builtin_expect(cur != ed, 1)) return; } } template <class T, std::enable_if_t<std::is_same<T, int>::value, int> = 0> inline void read(T &num) { skip_space(); if (cur + integer_size >= ed) reload(); bool neg = false; num = 0; if (*cur == '-') neg = true, ++cur; while (*cur >= '0') num = num * 10 + (*cur ^ 48), ++cur; if (neg) num = -num; } template <class T, std::enable_if_t<std::is_same<T, int64>::value, int> = 0> inline void read(T &num) { skip_space(); if (cur + integer_size >= ed) reload(); bool neg = false; num = 0; if (*cur == '-') neg = true, ++cur; while (*cur >= '0') num = num * 10 + (*cur ^ 48), ++cur; if (neg) num = -num; } template <class T, std::enable_if_t<std::is_same<T, std::string>::value, int> = 0> inline void read(T &str) { skip_space(); if (cur + buf_size >= ed) reload(); auto it = cur; while (!(*cur == ' ' || *cur == '\n')) ++cur; str = std::string(it, cur); } template <class T, std::enable_if_t<std::is_same<T, char>::value, int> = 0> inline void read(T &c) { skip_space(); if (cur + 1 >= ed) reload(); c = *cur, ++cur; } template <class T, std::enable_if_t<std::is_same<T, double>::value, int> = 0> inline void read(T &num) { skip_space(); if (cur + integer_size >= ed) reload(); bool neg = false; num = 0; if (*cur == '-') neg = true, ++cur; while (*cur >= '0' && *cur <= '9') num = num * 10 + (*cur - '0'), ++cur; if (*cur != '.') return; ++cur; T base = 0.1; while (*cur >= '0' && *cur <= '9') { num += base * (*cur - '0'); ++cur; base *= 0.1; } if (neg) num = -num; } template <class T, std::enable_if_t<std::is_same<T, long double>::value, int> = 0> inline void read(T &num) { skip_space(); if (cur + integer_size >= ed) reload(); bool neg = false; num = 0; if (*cur == '-') neg = true, ++cur; while (*cur >= '0' && *cur <= '9') num = num * 10 + (*cur - '0'), ++cur; if (*cur != '.') return; ++cur; T base = 0.1; while (*cur >= '0' && *cur <= '9') { num += base * (*cur - '0'); ++cur; base *= 0.1; } if (neg) num = -num; } template <class T> inline void read(std::vector<T> &vec) { for (T &e : vec) read(e); } template <class T, class U> inline void read(std::pair<T, U> &p) { read(p.first, p.second); } template <class Tuple, std::size_t... Is> inline void tuple_scan(Tuple &tp, std::index_sequence<Is...>) { (read(std::get<Is>(tp)), ...); } template <class... Args> inline void read(std::tuple<Args...> &tp) { tuple_scan(tp, std::index_sequence_for<Args...>{}); } inline void read() {} template <class Head, class... Tail> inline void read(Head &&head, Tail &&...tail) { read(head); read(std::forward<Tail>(tail)...); } }; class Printer { static constexpr int buf_size = (1 << 18); static constexpr int integer_size = 20; static constexpr int margin = 1; static constexpr int n = 10000; char buf[buf_size + margin] = {}; char integer[integer_size + margin] = {}; char table[n * 4] = {}; char *cur = buf; public: constexpr Printer() { build(); } ~Printer() { flush(); } template <class T> inline Printer &operator<<(T val) { write(val); return *this; } private: constexpr void build() { for (int i = 0; i < 10000; ++i) { int tmp = i; for (int j = 3; j >= 0; --j) { table[i * 4 + j] = tmp % 10 + '0'; tmp /= 10; } } } inline void flush() { fwrite(buf, 1, cur - buf, stdout); cur = buf; } template <class T, std::enable_if_t<std::is_same<T, int>::value, int> = 0> inline int get_digit(T n) { if (n >= (int)1e5) { if (n >= (int)1e8) return 9; if (n >= (int)1e7) return 8; if (n >= (int)1e6) return 7; return 6; } else { if (n >= (int)1e4) return 5; if (n >= (int)1e3) return 4; if (n >= (int)1e2) return 3; if (n >= (int)1e1) return 2; return 1; } } template <class T, std::enable_if_t<std::is_same<T, int64>::value, int> = 0> inline int get_digit(T n) { if (n >= (int64)1e10) { if (n >= (int64)1e14) { if (n >= (int64)1e18) return 19; if (n >= (int64)1e17) return 18; if (n >= (int64)1e16) return 17; if (n >= (int64)1e15) return 16; return 15; } else { if (n >= (int64)1e14) return 15; if (n >= (int64)1e13) return 14; if (n >= (int64)1e12) return 13; if (n >= (int64)1e11) return 12; return 11; } } else { if (n >= (int64)1e5) { if (n >= (int64)1e9) return 10; if (n >= (int64)1e8) return 9; if (n >= (int64)1e7) return 8; if (n >= (int64)1e6) return 7; return 6; } else { if (n >= (int64)1e4) return 5; if (n >= (int64)1e3) return 4; if (n >= (int64)1e2) return 3; if (n >= (int64)1e1) return 2; return 1; } } } template <class T, std::enable_if_t<std::is_same<T, int>::value, int> = 0> inline void write(T num) { if (__builtin_expect(cur + integer_size >= buf + buf_size, 0)) flush(); if (num == 0) { write('0'); return; } if (num < 0) { write('-'); num = -num; } int len = get_digit(num); int digits = len; while (num >= 10000) { memcpy(cur + len - 4, table + (num % 10000) * 4, 4); num /= 10000; len -= 4; } memcpy(cur, table + num * 4 + (4 - len), len); cur += digits; } template <class T, std::enable_if_t<std::is_same<T, int64>::value, int> = 0> inline void write(T num) { if (__builtin_expect(cur + integer_size >= buf + buf_size, 0)) flush(); if (num == 0) { write('0'); return; } if (num < 0) { write('-'); num = -num; } int len = get_digit(num); int digits = len; while (num >= 10000) { memcpy(cur + len - 4, table + (num % 10000) * 4, 4); num /= 10000; len -= 4; } memcpy(cur, table + num * 4 + (4 - len), len); cur += digits; } template <class T, std::enable_if_t<std::is_same<T, char>::value, int> = 0> inline void write(T c) { if (__builtin_expect(cur + 1 >= buf + buf_size, 0)) flush(); *cur = c; ++cur; } template <class T, std::enable_if_t<std::is_same<T, std::string>::value, int> = 0> inline void write(T str) { if (__builtin_expect(cur + str.size() >= buf + buf_size, 0)) flush(); for (char c : str) write(c); } }; } // namespace FastIO FastIO::Scanner fin; FastIO::Printer fout; int main() { // ios_base::sync_with_stdio(false); // cin.tie(nullptr); int n; fin >> n; map<string, int> mp; for (int i = 0; i < n; ++i) { string s; fin >> s; ++mp[s]; } fout << "AC x "s << mp["AC"] << '\n'; fout << "WA x "s << mp["WA"] << '\n'; fout << "TLE x "s << mp["TLE"] << '\n'; fout << "RE x "s << mp["RE"] << '\n'; return 0; }
replace
216
217
216
217
0
p02613
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { string s[100]; int n, c1 = 0, c2 = 0, c3 = 0, c4 = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> s[i]; if (s[i] == "AC") c1++; else if (s[i] == "WA") c2++; else if (s[i] == "TLE") c3++; else if (s[i] == "RE") c4++; } cout << "AC x " << c1 << endl << "WA x " << c2 << endl << "TLE x " << c3 << endl << "RE x " << c4 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { string s[100005]; int n, c1 = 0, c2 = 0, c3 = 0, c4 = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> s[i]; if (s[i] == "AC") c1++; else if (s[i] == "WA") c2++; else if (s[i] == "TLE") c3++; else if (s[i] == "RE") c4++; } cout << "AC x " << c1 << endl << "WA x " << c2 << endl << "TLE x " << c3 << endl << "RE x " << c4 << endl; }
replace
3
4
3
4
0
p02613
C++
Runtime Error
/* QUESTION : RULE : INPUT : OUTPUT : */ /* int :10^9 long long :10^19 */ #include <bits/stdc++.h> #define rep(i, a, n) for (int i = a; i < (n); ++i) #define repeq(i, a, n) for (int i = a; i <= (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n; cin >> n; string s; vector<int> c(n); rep(i, 0, n) { cin >> s; if (s == "AC") { c.at(0)++; } if (s == "WA") { c.at(1)++; } if (s == "TLE") { c.at(2)++; } if (s == "RE") { c.at(3)++; } } cout << "AC x " << c.at(0) << endl; cout << "WA x " << c.at(1) << endl; cout << "TLE x " << c.at(2) << endl; cout << "RE x " << c.at(3) << endl; return 0; }
/* QUESTION : RULE : INPUT : OUTPUT : */ /* int :10^9 long long :10^19 */ #include <bits/stdc++.h> #define rep(i, a, n) for (int i = a; i < (n); ++i) #define repeq(i, a, n) for (int i = a; i <= (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n; cin >> n; string s; vector<int> c(4); rep(i, 0, n) { cin >> s; if (s == "AC") { c.at(0)++; } if (s == "WA") { c.at(1)++; } if (s == "TLE") { c.at(2)++; } if (s == "RE") { c.at(3)++; } } cout << "AC x " << c.at(0) << endl; cout << "WA x " << c.at(1) << endl; cout << "TLE x " << c.at(2) << endl; cout << "RE x " << c.at(3) << endl; return 0; }
replace
24
25
24
25
0
p02613
C++
Runtime Error
#include <algorithm> #include <functional> #include <iostream> #include <string> using namespace std; #include <climits> #include <iomanip> #include <math.h> #include <queue> #include <vector> using Graph = vector<vector<int>>; const double PI = 3.14159265358979323846; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // 約数をベクトル形式で返す vector<int> vect_yakusuu(int n) { vector<int> ret; for (int i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return ret; } int main() { long long N; string S[10100]; int ans[5]; cin >> N; for (int i = 0; i < N; i++) { cin >> S[i]; } for (int i = 0; i < 4; i++) { ans[i] = 0; } for (int i = 0; i < N; i++) { if (S[i] == "AC") { ans[0]++; } if (S[i] == "WA") { ans[1]++; } if (S[i] == "TLE") { ans[2]++; } if (S[i] == "RE") { ans[3]++; } } cout << "AC x " << ans[0] << endl; cout << "WA x " << ans[1] << endl; cout << "TLE x " << ans[2] << endl; cout << "RE x " << ans[3] << endl; cin >> ans[0]; return 0; }
#include <algorithm> #include <functional> #include <iostream> #include <string> using namespace std; #include <climits> #include <iomanip> #include <math.h> #include <queue> #include <vector> using Graph = vector<vector<int>>; const double PI = 3.14159265358979323846; long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // 約数をベクトル形式で返す vector<int> vect_yakusuu(int n) { vector<int> ret; for (int i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return ret; } int main() { long long N; string S[100100]; int ans[5]; cin >> N; for (int i = 0; i < N; i++) { cin >> S[i]; } for (int i = 0; i < 4; i++) { ans[i] = 0; } for (int i = 0; i < N; i++) { if (S[i] == "AC") { ans[0]++; } if (S[i] == "WA") { ans[1]++; } if (S[i] == "TLE") { ans[2]++; } if (S[i] == "RE") { ans[3]++; } } cout << "AC x " << ans[0] << endl; cout << "WA x " << ans[1] << endl; cout << "TLE x " << ans[2] << endl; cout << "RE x " << ans[3] << endl; cin >> ans[0]; return 0; }
replace
42
43
42
43
0
p02613
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int a = 0, b = 0, c = 0, d = 0, N; cin >> N; vector<string> vec(N); for (int i = 0; i < N; i++) { cin >> vec.at(i); if (vec.at(i) == "AC") { a += 1; continue; } else if (vec.at(i) == "WA") { b += 1; continue; } else if (vec.at(i) == "TLE") { c += 1; continue; } else { d += 1; continue; } } cout << "AC x " + a << endl; cout << "WA x " + b << endl; cout << "TLE x " + c << endl; cout << "RE x " + d << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int a = 0, b = 0, c = 0, d = 0, N; cin >> N; vector<string> vec(N); for (int i = 0; i < N; i++) { cin >> vec.at(i); if (vec.at(i) == "AC") { a += 1; continue; } else if (vec.at(i) == "WA") { b += 1; continue; } else if (vec.at(i) == "TLE") { c += 1; continue; } else { d += 1; continue; } } cout << "AC x " << a << endl; cout << "WA x " << b << endl; cout << "TLE x " << c << endl; cout << "RE x " << d << endl; }
replace
22
26
22
26
0
p02613
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<string> result; for (int i = 0; i < N; i++) { cin >> result.at(i); } int a, b, c, d; a = 0; b = 0; c = 0; d = 0; for (int i = 0; i < N; i++) { if (result.at(i) == "AC") { a++; } else if (result.at(i) == "WA") { b++; } else if (result.at(i) == "TLE") { c++; } else { d++; } } cout << "AC x " << a << endl; cout << "WA x " << b << endl; cout << "TLE x " << c << endl; cout << "RE x " << d << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<string> result(N); for (int i = 0; i < N; i++) { cin >> result.at(i); } int a, b, c, d; a = 0; b = 0; c = 0; d = 0; for (int i = 0; i < N; i++) { if (result.at(i) == "AC") { a++; } else if (result.at(i) == "WA") { b++; } else if (result.at(i) == "TLE") { c++; } else { d++; } } cout << "AC x " << a << endl; cout << "WA x " << b << endl; cout << "TLE x " << c << endl; cout << "RE x " << d << endl; }
replace
6
7
6
7
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)
p02613
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define V(i) vector<i> #define rep(i, n) for (__typeof(n) i = 0; i < n; i++) #define crep(i, N, n) for (__typeof(n) i = N; i < n; i++) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define P(i, j) pair<i, j> #define MP make_pair #define MOD 1000000007 typedef long long ll; typedef long l; #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) int main() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); ll n; cin >> n; map<string, ll> mp; rep(i, n) { string s; cin >> s; mp[s]++; } cout << "AC x " << mp["AC"] << "\n"; cout << "WA x " << mp["WA"] << "\n"; cout << "TLE x " << mp["TLE"] << "\n"; cout << "RE x " << mp["RE"] << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define V(i) vector<i> #define rep(i, n) for (__typeof(n) i = 0; i < n; i++) #define crep(i, N, n) for (__typeof(n) i = N; i < n; i++) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define P(i, j) pair<i, j> #define MP make_pair #define MOD 1000000007 typedef long long ll; typedef long l; #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) int main() { // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ll n; cin >> n; map<string, ll> mp; rep(i, n) { string s; cin >> s; mp[s]++; } cout << "AC x " << mp["AC"] << "\n"; cout << "WA x " << mp["WA"] << "\n"; cout << "TLE x " << mp["TLE"] << "\n"; cout << "RE x " << mp["RE"] << "\n"; return 0; }
replace
17
19
17
19
TLE
p02613
C++
Runtime Error
// #pragma region ALL(include define etc) #include <algorithm> // max(a, b) min(a, b) reverse() sort() #include <cmath> // abs(絶対値) sin cos tan(角度 / 180.0 * 3.141592) #include <functional> // sort(a, a + N, greater<型>()); #include <iomanip> #include <iostream> // swap(a, b) #include <math.h> #include <string> #include <vector> // vec.push_back(a) vec.pop_back() #define int long long // #define int unsigned long long #define ll long long #define double long double using namespace std; // #pragma endregion signed main() { // 10^18 = 1000000000000000000 // int h1, h2, m1, m2, k; // int box, box1,box2; // int N; int n; // char n; // int a = -111, b = -111; int m; int k; // string s; // string t; // int m1, m2; // int a, b, c, k; // int x, y; string s[10000000]; // char a[1000000]; // int a[200000]; // int b[200000]; // int a[2000000] = { 0 }; // int b[2000000] = { 0 }; // int a[20000] = { 0 }; // int b[20000] = { 0 }; // vector<int>a(2000000); // vector<int>b(2000000); // int aaa = 0; // int bbb = 0; // int box[1000000000000000000]; int box = 0; // int box2; // int p[1111]; // long double aaa; int ac = 0; int wa = 0; int tle = 0; int re = 0; int count = 0; // int k, d; int all = 0; // double all; // double a, b; // double h, m; // int a[30000] = { 0 }; // double c, d, e; // double mbox, hbox; // double box, box2; // bool flag = true; bool flag = false; // string str; // cin >> h1 >> m1 >> h2 >> m2 >> k; cin >> n; // cin >> a >> b; // cin >> n >> m >> k; for (int i = 0; i < n; i++) { cin >> s[i]; if (s[i] == "AC") { ac++; } else if (s[i] == "WA") { wa++; } else if (s[i] == "TLE") { tle++; } else { re++; } } // n = s.length(); // sort(p, p + n); // n = n - 'Z'; // for (int i = 0; i < 1000; i++) //{ // if (n < 1000) // { // all = 1000 - n; // break; // } // n -= 1000; // if (n == 0) // { // all = 0; // break; // } // } // box = n % 26; // for (int i = 0; i < k; i++) //{ // all += p[i]; // } // all = n + (n * n) + (n * n * n); /*if (n > 0) { cout << "a\n"; } else { cout << "A\n"; }*/ // n = t.length(); cout << "AC x " << ac << "\n"; cout << "WA x " << wa << "\n"; cout << "TLE x " << tle << "\n"; cout << "RE x " << re << "\n"; // cout << all << "\n"; // cout << box << "\n"; // cout << a << "\n"; /*if (flag == true) { cout << "Yes\n"; } else { cout << "No\n"; }*/ // cout << fixed << setprecision(111) << all; }
// #pragma region ALL(include define etc) #include <algorithm> // max(a, b) min(a, b) reverse() sort() #include <cmath> // abs(絶対値) sin cos tan(角度 / 180.0 * 3.141592) #include <functional> // sort(a, a + N, greater<型>()); #include <iomanip> #include <iostream> // swap(a, b) #include <math.h> #include <string> #include <vector> // vec.push_back(a) vec.pop_back() #define int long long // #define int unsigned long long #define ll long long #define double long double using namespace std; // #pragma endregion signed main() { // 10^18 = 1000000000000000000 // int h1, h2, m1, m2, k; // int box, box1,box2; // int N; int n; // char n; // int a = -111, b = -111; int m; int k; // string s; // string t; // int m1, m2; // int a, b, c, k; // int x, y; string s[111111]; // string s[100000]; // char a[1000000]; // int a[200000]; // int b[200000]; // int a[2000000] = { 0 }; // int b[2000000] = { 0 }; // int a[20000] = { 0 }; // int b[20000] = { 0 }; // vector<int>a(2000000); // vector<int>b(2000000); // int aaa = 0; // int bbb = 0; // int box[1000000000000000000]; int box = 0; // int box2; // int p[1111]; // long double aaa; int ac = 0; int wa = 0; int tle = 0; int re = 0; int count = 0; // int k, d; int all = 0; // double all; // double a, b; // double h, m; // int a[30000] = { 0 }; // double c, d, e; // double mbox, hbox; // double box, box2; // bool flag = true; bool flag = false; // string str; // cin >> h1 >> m1 >> h2 >> m2 >> k; cin >> n; // cin >> a >> b; // cin >> n >> m >> k; for (int i = 0; i < n; i++) { cin >> s[i]; if (s[i] == "AC") { ac++; } else if (s[i] == "WA") { wa++; } else if (s[i] == "TLE") { tle++; } else { re++; } } // n = s.length(); // sort(p, p + n); // n = n - 'Z'; // for (int i = 0; i < 1000; i++) //{ // if (n < 1000) // { // all = 1000 - n; // break; // } // n -= 1000; // if (n == 0) // { // all = 0; // break; // } // } // box = n % 26; // for (int i = 0; i < k; i++) //{ // all += p[i]; // } // all = n + (n * n) + (n * n * n); /*if (n > 0) { cout << "a\n"; } else { cout << "A\n"; }*/ // n = t.length(); cout << "AC x " << ac << "\n"; cout << "WA x " << wa << "\n"; cout << "TLE x " << tle << "\n"; cout << "RE x " << re << "\n"; // cout << all << "\n"; // cout << box << "\n"; // cout << a << "\n"; /*if (flag == true) { cout << "Yes\n"; } else { cout << "No\n"; }*/ // cout << fixed << setprecision(111) << all; }
replace
34
35
34
36
-11
p02613
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define FASTIO \ ios_base::sync_with_stdio(false); \ cin.tie(0); using namespace std; using ii = pair<int, int>; using ll = long long int; int a, b, c, d; int main() { FASTIO; int T; cin >> T; while (1) { string s; cin >> s; if (s == "AC") a++; else if (s == "WA") b++; else if (s == "TLE") c++; else d++; } cout << "AC x " << a << endl; cout << "WA x " << b << endl; cout << "TLE x " << c << endl; cout << "RE x " << d << endl; return 0; }
#include <bits/stdc++.h> #define FASTIO \ ios_base::sync_with_stdio(false); \ cin.tie(0); using namespace std; using ii = pair<int, int>; using ll = long long int; int a, b, c, d; int main() { FASTIO; int T; cin >> T; while (T--) { string s; cin >> s; if (s == "AC") a++; else if (s == "WA") b++; else if (s == "TLE") c++; else d++; } cout << "AC x " << a << endl; cout << "WA x " << b << endl; cout << "TLE x " << c << endl; cout << "RE x " << d << endl; return 0; }
replace
14
15
14
15
TLE
p02613
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; string S; int A = 0, W = 0, T = 0, R = 0; for (int i = 0; i < N; i++) { cin >> S; if (S == "AC") A++; else if (S == "WA") W++; else if (S == "TLE") T++; else if (S == "RE") R++; } cout << "AC x " + A << endl; cout << "WA x " + W << endl; cout << "TLE x " + T << endl; cout << "RE x " + R << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; string S; int A = 0, W = 0, T = 0, R = 0; for (int i = 0; i < N; i++) { cin >> S; if (S == "AC") A++; else if (S == "WA") W++; else if (S == "TLE") T++; else if (S == "RE") R++; } cout << "AC x " << A << endl; cout << "WA x " << W << endl; cout << "TLE x " << T << endl; cout << "RE x " << R << endl; }
replace
19
23
19
23
0
p02613
C++
Runtime Error
#include <bits/stdc++.h> #define Vsort(a) sort(a.bigin(), a.end()) #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; int main() { int n, ac = 0, wa = 0, tle = 0, re = 0; cin >> n; vector<string> s(n); for (int i = 0; i < n; i++) { cin >> s[i]; if (s[i] == "AC") { ac++; } else if (s[i] == "WA") { wa++; } else if (s[i] == "TLE") { tle++; } else { re++; } } cout << "AC × " + ac << endl; cout << "WA × " + wa << endl; cout << "TLE × " + tle << endl; cout << "RE × " + re << endl; return 0; }
#include <bits/stdc++.h> #define Vsort(a) sort(a.bigin(), a.end()) #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; int main() { int n, ac = 0, wa = 0, tle = 0, re = 0; cin >> n; vector<string> s(n); for (int i = 0; i < n; i++) { cin >> s[i]; if (s[i] == "AC") { ac++; } else if (s[i] == "WA") { wa++; } else if (s[i] == "TLE") { tle++; } else { re++; } } cout << "AC x " << ac << endl; cout << "WA x " << wa << endl; cout << "TLE x " << tle << endl; cout << "RE x " << re << endl; return 0; }
replace
23
27
23
27
0
p02613
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define db double using namespace std; map<string, int> mp; int n; string s; int main() { cin >> n; while (n--) cin >> s, mp[s]++; cout << "AC x " + mp["AC"] << endl; cout << "WA x " + mp["WA"] << endl; cout << "TLE x " + mp["TLE"] << endl; cout << "RE x " + mp["RE"] << endl; return 0; }
#include <bits/stdc++.h> #define ll long long #define db double using namespace std; map<string, int> mp; int n; string s; int main() { cin >> n; while (n--) cin >> s, mp[s]++; cout << "AC x " << mp["AC"] << endl; cout << "WA x " << mp["WA"] << endl; cout << "TLE x " << mp["TLE"] << endl; cout << "RE x " << mp["RE"] << endl; return 0; }
replace
11
15
11
15
0
p02613
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; vector<int> a(4, 0); while (n--) { cin >> s; if (s == "AC") a[0]++; else if (s == "WA") a[1]++; else if (s == "TLE") a[2]++; else a[3]++; } cout << "AC x " << a[0] << '\n'; cout << "WA x " << a[1] << '\n'; cout << "TLE x " << a[2] << '\n'; cout << "RE x " << a[3] << '\n'; return 1; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s; vector<int> a(4, 0); while (n--) { cin >> s; if (s == "AC") a[0]++; else if (s == "WA") a[1]++; else if (s == "TLE") a[2]++; else a[3]++; } cout << "AC x " << a[0] << '\n'; cout << "WA x " << a[1] << '\n'; cout << "TLE x " << a[2] << '\n'; cout << "RE x " << a[3] << '\n'; return 0; }
replace
22
23
22
23
1
p02614
C++
Runtime Error
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; int main() { int h, w, k; cin >> h >> w >> k; vector<char> a(h * w); for (int i = 0; i < h * w; i++) cin >> a[i]; vector<char> reset(h * w); for (int i = 0; i < h * w; i++) reset[i] = a[i]; int count = 0; int ans = 0; for (int bit = 0; bit < (1 << h); bit++) { for (int bitw = 0; bitw < (1 << w); bitw++) { for (int i = 0; i < h; i++) { if (bit & (1 << i)) { for (int j = w * i; j < w * (i + 1); j++) a[j] = 'R'; } } for (int i = 0; i < w; i++) { if (bitw & (1 << i)) { for (int j = i - 1; j <= h * w - 1; j += w) a[j] = 'R'; } } for (int i = 0; i < h * w; i++) { if (a[i] == '#') count++; } if (count == k) ans++; count = 0; for (int i = 0; i < h * w; i++) a[i] = reset[i]; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG using namespace std; int main() { int h, w, k; cin >> h >> w >> k; vector<char> a(h * w); for (int i = 0; i < h * w; i++) cin >> a[i]; vector<char> reset(h * w); for (int i = 0; i < h * w; i++) reset[i] = a[i]; int count = 0; int ans = 0; for (int bit = 0; bit < (1 << h); bit++) { for (int bitw = 0; bitw < (1 << w); bitw++) { for (int i = 0; i < h; i++) { if (bit & (1 << i)) { for (int j = w * i; j < w * (i + 1); j++) a[j] = 'R'; } } for (int i = 0; i < w; i++) { if (bitw & (1 << i)) { for (int j = i; j <= h * w; j += w) a[j] = 'R'; } } for (int i = 0; i < h * w; i++) { if (a[i] == '#') count++; } if (count == k) ans++; count = 0; for (int i = 0; i < h * w; i++) a[i] = reset[i]; } } cout << ans << endl; return 0; }
replace
32
33
32
33
-6
double free or corruption (out)
p02614
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using i64 = int_fast64_t; #define INF (i64)1e18 #define MOD (i64)(1e9 + 7) #define REP(i, n) for (i64 i = 0; i < n; i++) #define RANGE(i, a, b) for (i64 i = a; i < b; i++) #define EACH(v, e, p) for_each(v.begin(), v.end(), [](auto &e) p) int main() { int h, w, k; cin >> h >> w >> k; vector<vector<bool>> c(h, vector<bool>(w)); REP(i, h) { string s; cin >> s; REP(j, w) { c[i][j] = s[j] == '#'; } } int ans = 0; for (int wbit = 0; wbit < (1 << w); ++wbit) { for (int hbit = 0; hbit < (1 << h); ++hbit) { int count = 0; for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { if ((wbit & (1 << i)) && (hbit & (1 << j))) { if (c[i][j]) count++; } } } if (count == k) ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using i64 = int_fast64_t; #define INF (i64)1e18 #define MOD (i64)(1e9 + 7) #define REP(i, n) for (i64 i = 0; i < n; i++) #define RANGE(i, a, b) for (i64 i = a; i < b; i++) #define EACH(v, e, p) for_each(v.begin(), v.end(), [](auto &e) p) int main() { int h, w, k; cin >> h >> w >> k; vector<vector<bool>> c(h, vector<bool>(w)); REP(i, h) { string s; cin >> s; REP(j, w) { c[i][j] = s[j] == '#'; } } int ans = 0; for (int wbit = 0; wbit < (1 << w); ++wbit) { for (int hbit = 0; hbit < (1 << h); ++hbit) { int count = 0; for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { if ((wbit & (1 << i)) && (hbit & (1 << j))) { if (c[j][i]) count++; } } } if (count == k) ans++; } } cout << ans << endl; return 0; }
replace
28
29
28
29
-11
p02614
C++
Runtime Error
#include <iostream> #include <vector> int main() { int H, W, K; std::cin >> H >> W >> K; std::vector<std::vector<char>> c(W, std::vector<char>(H, 0)); int blackCount = 0; std::vector<int> hBlackCount(H, 0); std::vector<int> vBlackCount(W, 0); for (int i = 0; i != H; i++) { for (int j = 0; j != W; j++) { std::cin >> c[i][j]; if (c[i][j] == '#') { blackCount++; hBlackCount[i]++; vBlackCount[j]++; } } } int result = 0; for (int hBit = 0; hBit != 1 << H; hBit++) { std::vector<int> horizontal; for (int i = 0; i != H; i++) { if (hBit & (1 << i)) { horizontal.push_back(i); } } int black = blackCount; for (auto e : horizontal) black -= hBlackCount[e]; for (int vBit = 0; vBit != 1 << W; vBit++) { std::vector<int> vertical; for (int j = 0; j != W; j++) { if (vBit & (1 << j)) { vertical.push_back(j); } } int black2 = black; for (auto e : vertical) { black2 -= vBlackCount[e]; for (auto e2 : horizontal) { if (c[e2][e] == '#') { black2++; } } } if (black2 == K) { result++; } } } std::cout << result << std::endl; return 0; }
#include <iostream> #include <vector> int main() { int H, W, K; std::cin >> H >> W >> K; std::vector<std::vector<char>> c(H, std::vector<char>(W, 0)); int blackCount = 0; std::vector<int> hBlackCount(H, 0); std::vector<int> vBlackCount(W, 0); for (int i = 0; i != H; i++) { for (int j = 0; j != W; j++) { std::cin >> c[i][j]; if (c[i][j] == '#') { blackCount++; hBlackCount[i]++; vBlackCount[j]++; } } } int result = 0; for (int hBit = 0; hBit != 1 << H; hBit++) { std::vector<int> horizontal; for (int i = 0; i != H; i++) { if (hBit & (1 << i)) { horizontal.push_back(i); } } int black = blackCount; for (auto e : horizontal) black -= hBlackCount[e]; for (int vBit = 0; vBit != 1 << W; vBit++) { std::vector<int> vertical; for (int j = 0; j != W; j++) { if (vBit & (1 << j)) { vertical.push_back(j); } } int black2 = black; for (auto e : vertical) { black2 -= vBlackCount[e]; for (auto e2 : horizontal) { if (c[e2][e] == '#') { black2++; } } } if (black2 == K) { result++; } } } std::cout << result << std::endl; return 0; }
replace
7
8
7
8
0
p02614
C++
Runtime Error
#include <iostream> int main() { int h, w, k, count = 0; std::cin >> h >> w >> k; char c[w + 1][h + 1]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { std::cin >> c[i][j]; } } for (int maskH = 0; maskH < (1 << h); maskH++) { // bit全探索 '1'の行を塗る for (int maskW = 0; maskW < (1 << w); maskW++) { int black = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (((maskH >> i) & 1) == 1) { continue; } // i行目が赤なら飛ばす if (((maskW >> j) & 1) == 1) { continue; } if (c[i][j] == '#') { black++; } } } if (black == k) { count++; } } } std::cout << count << std::endl; return 0; }
#include <iostream> int main() { int h, w, k, count = 0; std::cin >> h >> w >> k; char c[100][100]; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { std::cin >> c[i][j]; } } for (int maskH = 0; maskH < (1 << h); maskH++) { // bit全探索 '1'の行を塗る for (int maskW = 0; maskW < (1 << w); maskW++) { int black = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (((maskH >> i) & 1) == 1) { continue; } // i行目が赤なら飛ばす if (((maskW >> j) & 1) == 1) { continue; } if (c[i][j] == '#') { black++; } } } if (black == k) { count++; } } } std::cout << count << std::endl; return 0; }
replace
5
6
5
6
0
p02614
C++
Runtime Error
#include <bits/stdc++.h> #define boost \ ios::sync_with_stdio(false); \ cin.tie(0) #define ll long long int #define ld long double #define mk make_pair #define pb push_back #define f first #define s second #define fo(i, a, b) for (i = a; i < b; i++) #define foe(i, a, b) for (i = a; i <= b; i++) #define all(x) x.begin(), x.end() // #define vi vector<int> #define vl vector<long long int> // #define pii pair <int,int> #define pll pair<long long int, long long int> // #define vpii vector< pair<int,int> > #define vpll vector<pair<long long int, long long int>> #define MOD 1000000007 using namespace std; const int inf = INT_MAX; const ll inf64 = LLONG_MAX; char arr[6][6]; ll ans; ll h, w, k; ll work(ll a, ll b) { char temp[h][w]; ll i, j; fo(i, 0, h) { fo(j, 0, w) temp[i][j] = arr[i][j]; } fo(i, 0, h) { if (a & (1 << i)) { fo(j, 0, w) temp[i][j] = '.'; } } fo(i, 0, w) { if (b & (1 << i)) { fo(j, 0, h) temp[j][i] = '.'; } } ll cnt = 0; fo(i, 0, h) { fo(j, 0, w) { if (temp[i][j] == '#') cnt++; } } if (cnt == k) ans++; } int main() { boost; cin >> h >> w >> k; ll i, j; fo(i, 0, h) fo(j, 0, w) cin >> arr[i][j]; fo(i, 0, (1 << h)) { fo(j, 0, (1 << w)) { work(i, j); } } cout << ans; return 0; }
#include <bits/stdc++.h> #define boost \ ios::sync_with_stdio(false); \ cin.tie(0) #define ll long long int #define ld long double #define mk make_pair #define pb push_back #define f first #define s second #define fo(i, a, b) for (i = a; i < b; i++) #define foe(i, a, b) for (i = a; i <= b; i++) #define all(x) x.begin(), x.end() // #define vi vector<int> #define vl vector<long long int> // #define pii pair <int,int> #define pll pair<long long int, long long int> // #define vpii vector< pair<int,int> > #define vpll vector<pair<long long int, long long int>> #define MOD 1000000007 using namespace std; const int inf = INT_MAX; const ll inf64 = LLONG_MAX; char arr[6][6]; ll ans; ll h, w, k; void work(ll a, ll b) { char temp[h][w]; ll i, j; fo(i, 0, h) { fo(j, 0, w) temp[i][j] = arr[i][j]; } fo(i, 0, h) { if (a & (1 << i)) { fo(j, 0, w) temp[i][j] = '.'; } } fo(i, 0, w) { if (b & (1 << i)) { fo(j, 0, h) temp[j][i] = '.'; } } ll cnt = 0; fo(i, 0, h) { fo(j, 0, w) { if (temp[i][j] == '#') cnt++; } } if (cnt == k) ans++; } int main() { boost; cin >> h >> w >> k; ll i, j; fo(i, 0, h) fo(j, 0, w) cin >> arr[i][j]; fo(i, 0, (1 << h)) { fo(j, 0, (1 << w)) { work(i, j); } } cout << ans; return 0; }
replace
27
28
27
28
0
p02614
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) using namespace std; using ll = unsigned long long; using p = pair<int, int>; int main() { int H, W, K; cin >> H >> W >> K; vector<vector<int>> m(W, vector<int>(H)); const int black = 1; rep(y, 0, H) { string s; cin >> s; rep(x, 0, W) { char c = s[x]; if (c == '#') { m[y][x] = black; } } } int ans = 0; rep(j, 0, 1 << H) { rep(i, 0, 1 << W) { int count = 0; rep(y, 0, H) { rep(x, 0, W) { if ((j >> y) & 1) continue; if ((i >> x) & 1) continue; if (m[y][x] == black) ++count; } } if (count == K) { ++ans; } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) using namespace std; using ll = unsigned long long; using p = pair<int, int>; int main() { int H, W, K; cin >> H >> W >> K; vector<vector<int>> m(H, vector<int>(W)); const int black = 1; rep(y, 0, H) { string s; cin >> s; rep(x, 0, W) { char c = s[x]; if (c == '#') { m[y][x] = black; } } } int ans = 0; rep(j, 0, 1 << H) { rep(i, 0, 1 << W) { int count = 0; rep(y, 0, H) { rep(x, 0, W) { if ((j >> y) & 1) continue; if ((i >> x) & 1) continue; if (m[y][x] == black) ++count; } } if (count == K) { ++ans; } } } cout << ans << endl; return 0; }
replace
10
11
10
11
0
p02614
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define endl '\n' int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); int h, w, k; cin >> h >> w >> k; string grid[h]; for (int i = 0; i < h; i++) cin >> grid[i]; int res = 0; for (int mask = 0; mask < (1 << (h + w)); mask++) { int cnt = 0; for (int col = 0; col < w; col++) { for (int row = 0; row < h; row++) { if (grid[col][row] != '#') continue; if ((mask & ((1 << col) | (1 << (w + row)))) != 0) continue; cnt++; } } if (cnt == k) res++; } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; #define endl '\n' int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0); int h, w, k; cin >> h >> w >> k; string grid[h]; for (int i = 0; i < h; i++) cin >> grid[i]; int res = 0; for (int mask = 0; mask < (1 << (h + w)); mask++) { int cnt = 0; for (int col = 0; col < w; col++) { for (int row = 0; row < h; row++) { if (grid[row][col] != '#') continue; if ((mask & ((1 << col) | (1 << (w + row)))) != 0) continue; cnt++; } } if (cnt == k) res++; } cout << res << endl; }
replace
17
18
17
18
-11
p02614
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) int main() { int h, w, k; cin >> h >> w >> k; vector<string> s(h); rep(i, h) cin >> s[i]; int ans = 0; rep(is, 1 << h) rep(js, 1 << w) { int cnt = 0; rep(i, h) rep(j, w) { if (is >> i & 1) continue; if (js >> j & 1) continue; if ('#' == s[is][js]) ++cnt; } if (k == cnt) ++ans; } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) int main() { int h, w, k; cin >> h >> w >> k; vector<string> s(h); rep(i, h) cin >> s[i]; int ans = 0; rep(is, 1 << h) rep(js, 1 << w) { int cnt = 0; rep(i, h) rep(j, w) { if (is >> i & 1) continue; if (js >> j & 1) continue; if ('#' == s[i][j]) ++cnt; } if (k == cnt) ++ans; } cout << ans << endl; return 0; }
replace
22
23
22
23
-11
p02614
C++
Runtime Error
#include <iostream> #include <string> using namespace std; int main() { int H, W, K; scanf("%d%d%d", &H, &W, &K); string m[H]; for (int i = 0; i < H; i++) { cin >> m[i]; } int count = 0; for (int b = 0; b < 1 << (H + W); b++) { int black = 0; for (int i = 0; i < H * W; i++) { if (b >> (i / H) & 1 && b >> (H + i % H) & 1) { if (m[i / H][i % H] == '#') { if (++black > K) { break; } } } } if (black == K) { count++; } } printf("%d\n", count); return 0; }
#include <iostream> #include <string> using namespace std; int main() { int H, W, K; scanf("%d%d%d", &H, &W, &K); string m[H]; for (int i = 0; i < H; i++) { cin >> m[i]; } int count = 0; for (int b = 0; b < 1 << (H + W); b++) { int black = 0; for (int i = 0; i < H * W; i++) { if (b >> (i / W) & 1 && b >> (H + i % W) & 1) { if (m[i / W][i % W] == '#') { if (++black > K) { break; } } } } if (black == K) { count++; } } printf("%d\n", count); return 0; }
replace
16
18
16
18
-11
p02614
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long long int Exp(long long int exp_n, long long int exp_e, long long exp_mod); int main() { int H, W, K, O = 0; cin >> H >> W >> K; int C[H][W], T[H][W]; string s; for (int i = 0; i < H; i++) { cin >> s; for (int j = 0; j < W; j++) { if (s[j] == '#') { C[i][j] = 1; T[i][j] = 1; } else { C[i][j] = 0; T[i][j] = 0; } } } int A = int(Exp(2, H + W, 999999999)); int count = 0; for (int i = 0; i < A; i++) { for (int j = 0; j < H; j++) { if (i & (1 << j)) { for (int k = 0; k < W; k++) { T[j][k] = 0; } } } for (int j = H; j < H + W; j++) { if (i & (1 << j)) { for (int k = 0; k < W; k++) { T[k][j - H] = 0; } } } for (int j = 0; j < H; j++) { for (int k = 0; k < W; k++) { if (T[j][k] == 1) { count++; } T[j][k] = C[j][k]; } } if (count == K) { O++; // cout << i <<endl; } count = 0; } cout << O << endl; return 0; } long long int Exp(long long int exp_n, long long int exp_e, long long int exp_mod) { long long int exp_o = 1; long long int exp_x = exp_n; long long int exp_tmp; while (0 < exp_e) { exp_tmp = exp_e / 2; if (exp_e - exp_tmp * 2 == 1) { exp_o = exp_o * exp_x; if (exp_o > exp_mod) { exp_o = exp_o % exp_mod; } } exp_x = exp_x * exp_x; if (exp_x > exp_mod) { exp_x = exp_x % exp_mod; } exp_e = exp_tmp; } return exp_o; }
#include <bits/stdc++.h> using namespace std; long long int Exp(long long int exp_n, long long int exp_e, long long exp_mod); int main() { int H, W, K, O = 0; cin >> H >> W >> K; int C[H][W], T[H][W]; string s; for (int i = 0; i < H; i++) { cin >> s; for (int j = 0; j < W; j++) { if (s[j] == '#') { C[i][j] = 1; T[i][j] = 1; } else { C[i][j] = 0; T[i][j] = 0; } } } int A = int(Exp(2, H + W, 999999999)); int count = 0; for (int i = 0; i < A; i++) { for (int j = 0; j < H; j++) { if (i & (1 << j)) { for (int k = 0; k < W; k++) { T[j][k] = 0; } } } for (int j = H; j < H + W; j++) { if (i & (1 << j)) { for (int k = 0; k < H; k++) { T[k][j - H] = 0; } } } for (int j = 0; j < H; j++) { for (int k = 0; k < W; k++) { if (T[j][k] == 1) { count++; } T[j][k] = C[j][k]; } } if (count == K) { O++; // cout << i <<endl; } count = 0; } cout << O << endl; return 0; } long long int Exp(long long int exp_n, long long int exp_e, long long int exp_mod) { long long int exp_o = 1; long long int exp_x = exp_n; long long int exp_tmp; while (0 < exp_e) { exp_tmp = exp_e / 2; if (exp_e - exp_tmp * 2 == 1) { exp_o = exp_o * exp_x; if (exp_o > exp_mod) { exp_o = exp_o % exp_mod; } } exp_x = exp_x * exp_x; if (exp_x > exp_mod) { exp_x = exp_x % exp_mod; } exp_e = exp_tmp; } return exp_o; }
replace
35
36
35
36
0
p02614
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; using P = pair<int, int>; int main(void) { int h, w, k; cin >> h >> w >> k; vector<string> c(w); for (int i = 0; i < h; i++) { cin >> c[i]; } int ans = 0; for (int bith = 0; bith < (1 << h); bith++) { for (int bitw = 0; bitw < (1 << w); bitw++) { int cntb = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (c[i][j] == '#') { if (((bith >> i) & 1) == 0 && ((bitw >> j) & 1) == 0) { cntb++; } } } } if (cntb == k) ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; using P = pair<int, int>; int main(void) { int h, w, k; cin >> h >> w >> k; vector<string> c(h); for (int i = 0; i < h; i++) { cin >> c[i]; } int ans = 0; for (int bith = 0; bith < (1 << h); bith++) { for (int bitw = 0; bitw < (1 << w); bitw++) { int cntb = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (c[i][j] == '#') { if (((bith >> i) & 1) == 0 && ((bitw >> j) & 1) == 0) { cntb++; } } } } if (cntb == k) ans++; } } cout << ans << endl; return 0; }
replace
8
9
8
9
0
p02614
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int h, w, k; cin >> h >> w >> k; vector<string> vec(w); for (int i = 0; i < w; i++) { cin >> vec.at(i); // cout << vec.at(i) << endl; } int ans = 0; for (int mask_h = 0; mask_h < (1 << h) - 1; mask_h++) { for (int mask_w = 0; mask_w < (1 << w) - 1; mask_w++) { // マスクするパターン(2^h * 2^w 通り) // 全マスのmask_hとmask_w以外の黒色をカウントする int cnt = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { // マスク対象の行・列は除外する if (mask_h & (1 << i)) continue; if (mask_w & (1 << j)) continue; // 黒色のマスをカウントする if (vec.at(i).at(j) == '#') cnt++; } } // cout << mask_h << ":" << mask_w << "...マスク後の黒マスは" << cnt << // endl; if (cnt == k) ans++; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int h, w, k; cin >> h >> w >> k; vector<string> vec(h); for (int i = 0; i < h; i++) { cin >> vec.at(i); // cout << vec.at(i) << endl; } int ans = 0; for (int mask_h = 0; mask_h < (1 << h) - 1; mask_h++) { for (int mask_w = 0; mask_w < (1 << w) - 1; mask_w++) { // マスクするパターン(2^h * 2^w 通り) // 全マスのmask_hとmask_w以外の黒色をカウントする int cnt = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { // マスク対象の行・列は除外する if (mask_h & (1 << i)) continue; if (mask_w & (1 << j)) continue; // 黒色のマスをカウントする if (vec.at(i).at(j) == '#') cnt++; } } // cout << mask_h << ":" << mask_w << "...マスク後の黒マスは" << cnt << // endl; if (cnt == k) ans++; } } cout << ans << endl; }
replace
7
9
7
9
0
p02614
C++
Runtime Error
#include <algorithm> #include <array> #include <cassert> #include <climits> #include <iostream> #include <map> #include <memory> #include <numeric> #include <queue> #include <set> #include <stack> #include <vector> #define IN(a, b) (a.find(b) != a.end()) #define p(a, b) make_pair(a, b) #define readVec(a) \ for (int __i = 0; __i < (int)a.size(); __i++) { \ cin >> a[__i]; \ } // jimjam template <typename T> void pMin(T &a, T b) { if (b < a) { a = b; } } template <typename T> void pMax(T &a, T b) { if (b > a) { a = b; } } template <typename T> std::ostream &operator<<(std::ostream &os, const std::vector<T> &c); template <typename A, typename B> std::ostream &operator<<(std::ostream &os, const std::pair<A, B> &c) { std::cout << "(" << c.first << ", " << c.second << ")"; return os; } template <typename T> std::ostream &operator<<(std::ostream &os, const std::vector<T> &c) { if (c.size() == 0) { os << "{}"; return os; } os << "{" << c[0]; for (int64_t i = 1; i < (int)c.size(); i++) { os << ", " << c[i]; } os << "}"; return os; } using namespace std; bool grid[6][6]; int main() { freopen("input", "r", stdin); ios::sync_with_stdio(0); cin.tie(0); int h, w, k; cin >> h >> w >> k; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { char ch; cin >> ch; grid[x][y] = (ch == '#'); } } int ans = 0; for (int i = 0; i < (1 << (h + w)); i++) { int curr = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int t1 = (i & (1 << x)); int t2 = (i & (1 << w + y)); if (grid[x][y] && ((i & (1 << x)) == 0) && ((i & (1 << w + y)) == 0)) { curr++; } } } if (curr == k) { ans++; } } cout << ans << endl; return 0; }
#include <algorithm> #include <array> #include <cassert> #include <climits> #include <iostream> #include <map> #include <memory> #include <numeric> #include <queue> #include <set> #include <stack> #include <vector> #define IN(a, b) (a.find(b) != a.end()) #define p(a, b) make_pair(a, b) #define readVec(a) \ for (int __i = 0; __i < (int)a.size(); __i++) { \ cin >> a[__i]; \ } // jimjam template <typename T> void pMin(T &a, T b) { if (b < a) { a = b; } } template <typename T> void pMax(T &a, T b) { if (b > a) { a = b; } } template <typename T> std::ostream &operator<<(std::ostream &os, const std::vector<T> &c); template <typename A, typename B> std::ostream &operator<<(std::ostream &os, const std::pair<A, B> &c) { std::cout << "(" << c.first << ", " << c.second << ")"; return os; } template <typename T> std::ostream &operator<<(std::ostream &os, const std::vector<T> &c) { if (c.size() == 0) { os << "{}"; return os; } os << "{" << c[0]; for (int64_t i = 1; i < (int)c.size(); i++) { os << ", " << c[i]; } os << "}"; return os; } using namespace std; bool grid[6][6]; int main() { ios::sync_with_stdio(0); cin.tie(0); int h, w, k; cin >> h >> w >> k; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { char ch; cin >> ch; grid[x][y] = (ch == '#'); } } int ans = 0; for (int i = 0; i < (1 << (h + w)); i++) { int curr = 0; for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { int t1 = (i & (1 << x)); int t2 = (i & (1 << w + y)); if (grid[x][y] && ((i & (1 << x)) == 0) && ((i & (1 << w + y)) == 0)) { curr++; } } } if (curr == k) { ans++; } } cout << ans << endl; return 0; }
delete
57
58
57
57
0
p02614
Python
Runtime Error
import itertools from typing import List def main(): h, w, k = map(int, input().split()) c = [] for _ in range(h): c.append(input().split()) print(hv(c, h, w, k)) def hv(c: List[List[str]], h: int, w: int, k: int) -> int: ret = 0 for comb_h in itertools.product((False, True), repeat=h): for comb_w in itertools.product((False, True), repeat=w): cnt = 0 for i in range(h): for j in range(w): if comb_h[i] and comb_w[j] and c[i][j] == "#": cnt += 1 if cnt == k: ret += 1 return ret if __name__ == "__main__": main()
import itertools from typing import List def main(): h, w, k = map(int, input().split()) c = [] for _ in range(h): c.append(list(input())) print(hv(c, h, w, k)) def hv(c: List[List[str]], h: int, w: int, k: int) -> int: ret = 0 for comb_h in itertools.product((False, True), repeat=h): for comb_w in itertools.product((False, True), repeat=w): cnt = 0 for i in range(h): for j in range(w): if comb_h[i] and comb_w[j] and c[i][j] == "#": cnt += 1 if cnt == k: ret += 1 return ret if __name__ == "__main__": main()
replace
8
9
8
9
IndexError: list index out of range
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02614/Python/s784555472.py", line 29, in <module> main() File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02614/Python/s784555472.py", line 11, in main print(hv(c, h, w, k)) File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02614/Python/s784555472.py", line 21, in hv if comb_h[i] and comb_w[j] and c[i][j] == '#': IndexError: list index out of range
p02614
Python
Runtime Error
import itertools import numpy as np def _run(H, W, K, C): input = np.zeros([H, W], dtype=np.int8) for h in range(H): for w in range(W): if C[h][w] == "#": input[h, w] = 1 count = 0 for r in itertools.product(*[[0, 1] for _ in range(H + W)]): copy_input = input.copy() for h in range(H): if r[h] == 1: copy_input[h] = 0 for w in range(W): if r[H + w] == 1: copy_input[:, w] = 0 if np.sum(copy_input) == K: count += 1 print(count) def _main(): H, W, K = map(int, input().split()) C = [] for _ in range(H): C.append(list(map(str, input().split()))) _run(H, W, K, C) if __name__ == "__main__": _main()
import itertools import numpy as np def _run(H, W, K, C): input = np.zeros([H, W], dtype=np.int8) for h in range(H): for w in range(W): if C[h][w] == "#": input[h, w] = 1 count = 0 for r in itertools.product(*[[0, 1] for _ in range(H + W)]): copy_input = input.copy() for h in range(H): if r[h] == 1: copy_input[h] = 0 for w in range(W): if r[H + w] == 1: copy_input[:, w] = 0 if np.sum(copy_input) == K: count += 1 print(count) def _main(): H, W, K = map(int, input().split()) C = [str(input()) for _ in range(H)] _run(H, W, K, C) if __name__ == "__main__": _main()
replace
29
32
29
30
TLE
p02614
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int h, w, need; long long ans = 0; cin >> h >> w >> need; vector<string> s(w); for (int i = 0; i < w; i++) { cin >> s[i]; } for (int i = 0; i < (1 << h); i++) { for (int j = 0; j < (1 << w); j++) { int bl = 0; for (int k = 0; k < h; k++) { for (int l = 0; l < w; l++) { if (!(i & (1 << k)) && !(j & (1 << l)) && s[k][l] == '#') bl++; } } if (bl == need) ans++; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int h, w, need; long long ans = 0; cin >> h >> w >> need; vector<string> s(h); for (int i = 0; i < h; i++) { cin >> s[i]; } for (int i = 0; i < (1 << h); i++) { for (int j = 0; j < (1 << w); j++) { int bl = 0; for (int k = 0; k < h; k++) { for (int l = 0; l < w; l++) { if (!(i & (1 << k)) && !(j & (1 << l)) && s[k][l] == '#') bl++; } } if (bl == need) ans++; } } cout << ans << endl; }
replace
6
8
6
8
0
p02614
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int h, w, k; cin >> h >> w >> k; vector<string> c(h); for (int i = 0; i < h; i++) { cin >> c[i]; } int count = 0; for (int ih = 0; ih < (1 << h); ih++) { for (int jw = 0; jw < (1 << w); jw++) { int cnt = 0; for (int i = 0; i < h; h++) { for (int j = 0; j < w; j++) { if (ih >> i & 1) continue; if (jw >> j & 1) continue; if (c[i][j] == '#') cnt++; } } if (cnt == k) count++; } } cout << count << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int h, w, k; cin >> h >> w >> k; vector<string> c(h); for (int i = 0; i < h; i++) { cin >> c[i]; } int count = 0; for (int ih = 0; ih < (1 << h); ih++) { for (int jw = 0; jw < (1 << w); jw++) { int cnt = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (ih >> i & 1) continue; if (jw >> j & 1) continue; if (c[i][j] == '#') cnt++; } } if (cnt == k) count++; } } cout << count << endl; return 0; }
replace
15
16
15
16
TLE
p02614
C++
Runtime Error
#define rep(i, n) for (int i = 0; i < (int)(n); i++) #include <bits/stdc++.h> using namespace std; int main() { long long int H, W, K, res = 0; vector<vector<bool>> m, tmp0, tmp1; cin >> H >> W >> K; m.resize(H); rep(i, H) { string s; cin >> s; rep(j, W) { m[i].push_back((s[j] == '#')); } } rep(i, H) { m.resize(W); } for (int biti = 0; biti < (1 << H); ++biti) { tmp0 = m; for (int i = 0; i < H; ++i) { if (biti & (1 << i)) { rep(k, W) { tmp0[i][k] = false; } } } tmp1 = tmp0; for (int bitj = 0; bitj < (1 << W); ++bitj) { for (int j = 0; j < W; ++j) { if (bitj & (1 << j)) { rep(l, H) { tmp0[l][j] = false; } } } long long int count = 0; rep(p, H) { rep(q, W) { if (tmp0[p][q]) { count++; } } } if (count == K) { res++; } tmp0 = tmp1; } } cout << res; return 0; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++) #include <bits/stdc++.h> using namespace std; int main() { long long int H, W, K, res = 0; vector<vector<bool>> m, tmp0, tmp1; cin >> H >> W >> K; m.resize(H); rep(i, H) { string s; cin >> s; rep(j, W) { m[i].push_back((s[j] == '#')); } } for (int biti = 0; biti < (1 << H); ++biti) { tmp0 = m; for (int i = 0; i < H; ++i) { if (biti & (1 << i)) { rep(k, W) { tmp0[i][k] = false; } } } tmp1 = tmp0; for (int bitj = 0; bitj < (1 << W); ++bitj) { for (int j = 0; j < W; ++j) { if (bitj & (1 << j)) { rep(l, H) { tmp0[l][j] = false; } } } long long int count = 0; rep(p, H) { rep(q, W) { if (tmp0[p][q]) { count++; } } } if (count == K) { res++; } tmp0 = tmp1; } } cout << res; return 0; }
delete
17
18
17
17
0
p02614
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long long ans = 0, ha[10] = {0}, wi[10] = {0}, k, h, w; string c[10]; bool judge(void) { int i, j, cntk = 0; for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { if (c[i][j] == '#' && ha[i] == 0 && wi[j] == 0) cntk++; } } if (cntk == k) return true; else return false; } int dfs(int cnt) { if (cnt == (h + w)) { if (judge()) ans++; return 0; } if (cnt < h) { cnt++; ha[cnt - 1] = 0; dfs(cnt); ha[cnt - 1] = 1; dfs(cnt); } else { cnt++; wi[cnt - h - 1] = 0; dfs(cnt); wi[cnt - h - 1] = 1; dfs(cnt); } } int main() { long long i; cin >> h >> w >> k; for (i = 0; i < h; i++) { cin >> c[i]; } dfs(0); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long ans = 0, ha[10] = {0}, wi[10] = {0}, k, h, w; string c[10]; bool judge(void) { int i, j, cntk = 0; for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { if (c[i][j] == '#' && ha[i] == 0 && wi[j] == 0) cntk++; } } if (cntk == k) return true; else return false; } int dfs(int cnt) { if (cnt == (h + w)) { if (judge()) ans++; return 0; } if (cnt < h) { cnt++; ha[cnt - 1] = 0; dfs(cnt); ha[cnt - 1] = 1; dfs(cnt); } else { cnt++; wi[cnt - h - 1] = 0; dfs(cnt); wi[cnt - h - 1] = 1; dfs(cnt); } return 0; } int main() { long long i; cin >> h >> w >> k; for (i = 0; i < h; i++) { cin >> c[i]; } dfs(0); cout << ans << endl; return 0; }
insert
36
36
36
37
0
p02614
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vii; typedef vector<pll> vll; #define pb push_back #define mp make_pair #define mod 1000000007 #define F first #define S second #define p(s) cout << (s) << endl #define p2(s, t) cout << (s) << " " << (t) << endl #define For(i, a, b) for (__typeof(a) i = a; i <= b; i++) #define inp_arr(a, n) \ for (__typeof(n) i = 0; i < n; ++i) { \ cin >> a[i]; \ } #define debug_arr(a, n) \ { \ { \ for (__typeof(n) i = 0; i < n; ++i) { \ cout << a[i] << " "; \ } \ cout << "\n"; \ } \ } ll power(ll x, ll y) { ll res = 1; while (y > 0) { if (y & 1) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res % mod; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); // #ifndef ONLINE_JUDGE // freopen("inp.txt", "r", stdin); // freopen("out.txt", "w", stdout); // #endif int h, w, k; cin >> h >> w >> k; string s[w]; for (int i = 0; i < h; ++i) { cin >> s[i]; } int total = 0; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { if (s[i][j] == '#') ++total; } } int cc1 = 0; bitset<10> bh(0); int ans = 0; while (cc1 < 100) { int r = bh.to_ulong(); cc1 += 1; bitset<10> bw(0); int cc2 = 0; while (cc2 < 100) { int c = bw.to_ulong(); cc2 += 1; int temp = 0; for (int i = 0; i < h; ++i) { if (bh[i] == 1) { for (int j = 0; j < w; ++j) { if (s[i][j] == '#') ++temp; } } } for (int i = 0; i < w; ++i) { if (bw[i] == 1) { for (int j = 0; j < h; ++j) { if (s[j][i] == '#') ++temp; } } } for (int i = 0; i < h; ++i) { if (bh[i] == 1) { for (int j = 0; j < w; ++j) { if (bw[j] == 1) { if (s[i][j] == '#') --temp; } } } } if (total - temp == k) ++ans; // cout<<temp<<"\n"; int ff = 1; for (int i = 0; i < w; ++i) { if (bw[i] == 0) { ff = 0; break; } } if (ff) break; c += 1; bw = c; } int f = 1; for (int i = 0; i < h; ++i) { if (bh[i] == 0) { f = 0; break; } } if (f) break; r += 1; bh = r; } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vii; typedef vector<pll> vll; #define pb push_back #define mp make_pair #define mod 1000000007 #define F first #define S second #define p(s) cout << (s) << endl #define p2(s, t) cout << (s) << " " << (t) << endl #define For(i, a, b) for (__typeof(a) i = a; i <= b; i++) #define inp_arr(a, n) \ for (__typeof(n) i = 0; i < n; ++i) { \ cin >> a[i]; \ } #define debug_arr(a, n) \ { \ { \ for (__typeof(n) i = 0; i < n; ++i) { \ cout << a[i] << " "; \ } \ cout << "\n"; \ } \ } ll power(ll x, ll y) { ll res = 1; while (y > 0) { if (y & 1) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res % mod; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); // #ifndef ONLINE_JUDGE // freopen("inp.txt", "r", stdin); // freopen("out.txt", "w", stdout); // #endif int h, w, k; cin >> h >> w >> k; string s[h]; for (int i = 0; i < h; ++i) { cin >> s[i]; } int total = 0; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { if (s[i][j] == '#') ++total; } } int cc1 = 0; bitset<10> bh(0); int ans = 0; while (cc1 < 100) { int r = bh.to_ulong(); cc1 += 1; bitset<10> bw(0); int cc2 = 0; while (cc2 < 100) { int c = bw.to_ulong(); cc2 += 1; int temp = 0; for (int i = 0; i < h; ++i) { if (bh[i] == 1) { for (int j = 0; j < w; ++j) { if (s[i][j] == '#') ++temp; } } } for (int i = 0; i < w; ++i) { if (bw[i] == 1) { for (int j = 0; j < h; ++j) { if (s[j][i] == '#') ++temp; } } } for (int i = 0; i < h; ++i) { if (bh[i] == 1) { for (int j = 0; j < w; ++j) { if (bw[j] == 1) { if (s[i][j] == '#') --temp; } } } } if (total - temp == k) ++ans; // cout<<temp<<"\n"; int ff = 1; for (int i = 0; i < w; ++i) { if (bw[i] == 0) { ff = 0; break; } } if (ff) break; c += 1; bw = c; } int f = 1; for (int i = 0; i < h; ++i) { if (bh[i] == 0) { f = 0; break; } } if (f) break; r += 1; bh = r; } cout << ans << "\n"; return 0; }
replace
56
57
56
57
0
p02614
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int i, j, n, m, ans = 0, k, t, r, c; char ch; cin >> n >> m >> k; int a[n][m]; memset(a, 0, sizeof(a)); for (i = 0; i < n; i++) { for (i = 0; i < m; i++) { cin >> ch; if (ch == '#') a[i][j] = 1; } } for (r = 0; r < (1 << n); r++) { for (c = 0; c < (1 << m); c++) { t = 0; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { if ((1 << i) & r) continue; if ((1 << j) & c) continue; t += a[i][j]; } } if (t == k) ans++; } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int i, j, n, m, ans = 0, k, t, r, c; char ch; cin >> n >> m >> k; int a[n][m]; memset(a, 0, sizeof(a)); for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { cin >> ch; if (ch == '#') a[i][j] = 1; } } for (r = 0; r < (1 << n); r++) { for (c = 0; c < (1 << m); c++) { t = 0; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { if ((1 << i) & r) continue; if ((1 << j) & c) continue; t += a[i][j]; } } if (t == k) ans++; } } cout << ans; return 0; }
replace
9
10
9
10
-11
p02614
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int H, W, K; cin >> H >> W >> K; vector<string> vec(W); for (int i = 0; i < H; i++) { cin >> vec[i]; } int ans = 0; for (int is = 0; is < (1 << H); is++) { for (int js = 0; js < (1 << W); js++) { int cnt = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (is >> i & 1) { continue; } if (js >> j & 1) { continue; } if (vec[i][j] == '#') { cnt++; } } } if (cnt == K) { ans++; } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int H, W, K; cin >> H >> W >> K; vector<string> vec(H); for (int i = 0; i < H; i++) { cin >> vec[i]; } int ans = 0; for (int is = 0; is < (1 << H); is++) { for (int js = 0; js < (1 << W); js++) { int cnt = 0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { if (is >> i & 1) { continue; } if (js >> j & 1) { continue; } if (vec[i][j] == '#') { cnt++; } } } if (cnt == K) { ans++; } } } cout << ans << endl; }
replace
6
7
6
7
0
p02615
C++
Time Limit Exceeded
/** * @copyright (c) 2020 Daisuke Hashimoto */ #include <bits/stdc++.h> using namespace std; using Pair = pair<int64_t, int64_t>; constexpr int64_t kInf = INT64_MAX / 2L; // std::cout << std::setprecision(20) << 1.1 << endl; int main() { cin.tie(0); ios::sync_with_stdio(false); int64_t N; cin >> N; // const int64_t L = static_cast<int64_t>(T.length()); vector<int64_t> A(N); for (int64_t i = 0; i < N; ++i) { cin >> A[i]; } sort(A.begin(), A.end()); reverse(A.begin(), A.end()); int64_t result = 0; list<int64_t> ring; ring.emplace_back(A[0]); for (int64_t i = 1; i < N; ++i) { auto prev = ring.begin(); int64_t max_score = min(*ring.begin(), *ring.rbegin()); auto ins = ring.begin(); for (auto itr = ring.begin(); itr != ring.end(); ++itr) { const int64_t c_score = min(*itr, *prev); if (c_score > max_score) { max_score = c_score; ins = itr; } prev = itr; } ring.insert(ins, A[i]); result += max_score; } cout << result << endl; return 0; }
/** * @copyright (c) 2020 Daisuke Hashimoto */ #include <bits/stdc++.h> using namespace std; using Pair = pair<int64_t, int64_t>; constexpr int64_t kInf = INT64_MAX / 2L; // std::cout << std::setprecision(20) << 1.1 << endl; int main() { cin.tie(0); ios::sync_with_stdio(false); int64_t N; cin >> N; // const int64_t L = static_cast<int64_t>(T.length()); vector<int64_t> A(N); for (int64_t i = 0; i < N; ++i) { cin >> A[i]; } sort(A.begin(), A.end()); reverse(A.begin(), A.end()); int64_t result = A[0]; // cerr << "hoge " << A[0] << endl; using mypair = pair<int64_t, Pair>; multiset<mypair, std::greater<mypair>> nextscore_pair; nextscore_pair.insert(mypair(A[1], Pair(0, 1))); nextscore_pair.insert(mypair(A[1], Pair(0, 1))); for (int64_t i = 2; i < N; ++i) { result += nextscore_pair.begin()->first; // cerr << "hoge " << nextscore_pair.begin()->first << endl; const int64_t next_1 = nextscore_pair.begin()->second.first; const int64_t next_2 = nextscore_pair.begin()->second.second; nextscore_pair.erase(nextscore_pair.begin()); nextscore_pair.insert(mypair(A[i], Pair(i, next_1))); nextscore_pair.insert(mypair(A[i], Pair(i, next_2))); } cout << result << endl; return 0; }
replace
24
41
24
39
TLE
p02615
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < (n); ++i) #define all(a) (a).begin(), (a).end() using namespace std; using Graph = vector<vector<int>>; typedef pair<int, int> P; typedef long long ll; int main() { ll n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; sort(all(a)); reverse(all(a)); ll ans = a[0]; ll cnt = 0; ll id = 1; while (1) { rep(i, 2) { ans += a[id]; cnt++; if (cnt == n - 2) { cout << ans << endl; return 0; } } id++; } }
#include <bits/stdc++.h> #define rep(i, n) for (ll i = 0; i < (n); ++i) #define all(a) (a).begin(), (a).end() using namespace std; using Graph = vector<vector<int>>; typedef pair<int, int> P; typedef long long ll; int main() { ll n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; sort(all(a)); reverse(all(a)); ll ans = a[0]; ll cnt = 0; ll id = 1; if (n == 2) { cout << ans << endl; return 0; } while (1) { rep(i, 2) { ans += a[id]; cnt++; if (cnt == n - 2) { cout << ans << endl; return 0; } } id++; } }
insert
22
22
22
27
0
p02615
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define REP(i, n) FOR(i, 0, (n)) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define LAR(a, b) ((a) = max((a), (b))) #define SML(a, b) ((a) = min((a), (b))) using ll = long long; using ld = long double; using vi = vector<int>; using vl = vector<ll>; using pii = pair<int, int>; using vpii = vector<pair<int, int>>; template <typename T> using pque = priority_queue<T, vector<T>, greater<T>>; #define PB push_back #define EB emplace_back #define MP make_pair #define ALL(a) (a).begin(), (a).end() #ifdef LOCAL_DEBUG #define DEBUG(...) printf(__VA_ARGS__) #else #define DEBUG(...) #endif ll a[212345]; multiset<pair<ll, ll>, greater<pair<ll, ll>>> st; int main() { int n; scanf("%d", &n); REP(i, n) scanf("%lld", a + i); sort(a, a + n, greater<ll>()); st.emplace(a[0], a[0]); ll ans = 0; FOR(i, 1, n) { ll b = a[i]; auto it = st.begin(); auto [c, d] = *it; st.erase(it); ans += c; st.emplace(min(b, c), max(b, c)); st.emplace(min(b, d), max(b, d)); for (auto [e, f] : st) DEBUG("(%lld, %lld) ", e, f); DEBUG("\n"); } printf("%lld\n", ans); }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) FOR(i, 0, (n)) #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define LAR(a, b) ((a) = max((a), (b))) #define SML(a, b) ((a) = min((a), (b))) using ll = long long; using ld = long double; using vi = vector<int>; using vl = vector<ll>; using pii = pair<int, int>; using vpii = vector<pair<int, int>>; template <typename T> using pque = priority_queue<T, vector<T>, greater<T>>; #define PB push_back #define EB emplace_back #define MP make_pair #define ALL(a) (a).begin(), (a).end() #ifdef LOCAL_DEBUG #define DEBUG(...) printf(__VA_ARGS__) #else #define DEBUG(...) #endif ll a[212345]; multiset<pair<ll, ll>, greater<pair<ll, ll>>> st; int main() { int n; scanf("%d", &n); REP(i, n) scanf("%lld", a + i); sort(a, a + n, greater<ll>()); st.emplace(a[0], a[0]); ll ans = 0; FOR(i, 1, n) { ll b = a[i]; auto it = st.begin(); auto [c, d] = *it; st.erase(it); ans += c; st.emplace(min(b, c), max(b, c)); st.emplace(min(b, d), max(b, d)); // for(auto [e, f] : st) DEBUG("(%lld, %lld) ", e, f); DEBUG("\n"); } printf("%lld\n", ans); }
replace
41
44
41
42
TLE
p02615
C++
Runtime Error
// // じょえチャンネル // 高評価・チャンネル登録よろしくお願いします! // https://www.youtube.com/watch?v=gPFr7q7eLL8 // /*------------------------------------             ∧_∧       ∧_∧  (´<_` )       ( ´_ゝ`) /  ⌒i     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/ _/ .| .|____      \/____/ (u ⊃ -------------------------------------*/ #include <algorithm> #include <cstdio> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; #define int long long #define ll long long #define ld long double #define rep(i, n) for (ll i = 0; i < n; ++i) #define Rep(i, n) for (ll i = 1; i <= n; ++i) #define loop(i, m, n) for (ll i = m; i < n; ++i) #define rev(i, n) for (ll i = n - 1; i >= 0; --i) #define ggr \ getchar(); \ getchar(); \ return 0; #define pie 3.141592653589793238462643383279 #define elif else if #define P pair<ll, ll> #define prique priority_queue<ll> #define all(a) (a).begin(), (a).end() const int mod = 1000000007; const int mod2 = 998244353; const int inf = 1 << 30; const int MOD = 1e9 + 7; long long fac[510000], finv[510000], inv[510000]; long long MAX = 510000; bool COMinited = false; long long COM(int n, int k) { if (COMinited == false) { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } COMinited = true; } if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } template <int MOD> struct Fp { long long val; constexpr Fp(long long v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr int getmod() { return MOD; } constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; } constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; } constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; } constexpr Fp &operator+=(const Fp &r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp &operator-=(const Fp &r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp &operator*=(const Fp &r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp &operator/=(const Fp &r) noexcept { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator==(const Fp &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const Fp &r) const noexcept { return this->val != r.val; } friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept { return os << x.val; } friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; using mint = Fp<1000000007>; int bin(int bina) { int ans = 0; for (int i = 0; bina > 0; i++) { ans = ans + (bina % 2) * pow(10, i); bina = bina / 2; } return ans; } bool prime(int n) { for (ll i = 2; i <= sqrt(n); i++) { if (n % i == 0) return false; } return n != 1; } ll gcd(ll a, ll b) { if (b == 0) { return a; } return gcd(b, a % b); } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } 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 mod_pow(int x, int y, int m) { int res = 1; while (y > 0) { if (y & 1) { res = res * x % m; } x = x * x % m; y >>= 1; } return res; } int jo(int x, int y) { int res = 1; while (y > 0) { if (y & 1) { res = res * x; } x = x * x; y >>= 1; } return res; } int per(int n, int r) { r = n - r; int sum = 1; int i; for (i = n; i >= r + 1; i--) sum *= i; return sum; } struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; 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...)); } void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; } 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; } // cout << fixed << setprecision(10) << num << endl; struct edge { int to, cost; }; #define F first #define S second vector<pair<long long, long long>> prime_factorize(long long N) { vector<pair<long long, long long>> res; for (long long a = 2; a * a <= N; ++a) { if (N % a != 0) continue; long long ex = 0; // 指数 // 割れる限り割り続ける while (N % a == 0) { ++ex; N /= a; } // その結果を push res.push_back({a, ex}); } // 最後に残った数について if (N != 1) res.push_back({N, 1}); return res; } using graph = vector<vector<int>>; // cout << fixed << setprecision(10) << num << endl; prique que; int a[100010]; signed main() { int n; cin >> n; rep(i, n) cin >> a[i]; sort(a, a + n); reverse(a, a + n); que.push(a[0]); int ans = 0; loop(i, 1, n) { ans += que.top(); que.pop(); que.push(a[i]); que.push(a[i]); } cout << ans << endl; }
// // じょえチャンネル // 高評価・チャンネル登録よろしくお願いします! // https://www.youtube.com/watch?v=gPFr7q7eLL8 // /*------------------------------------             ∧_∧       ∧_∧  (´<_` )       ( ´_ゝ`) /  ⌒i     /   \    | |     /   / ̄ ̄ ̄ ̄/  |   __(__ニつ/ _/ .| .|____      \/____/ (u ⊃ -------------------------------------*/ #include <algorithm> #include <cstdio> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; #define int long long #define ll long long #define ld long double #define rep(i, n) for (ll i = 0; i < n; ++i) #define Rep(i, n) for (ll i = 1; i <= n; ++i) #define loop(i, m, n) for (ll i = m; i < n; ++i) #define rev(i, n) for (ll i = n - 1; i >= 0; --i) #define ggr \ getchar(); \ getchar(); \ return 0; #define pie 3.141592653589793238462643383279 #define elif else if #define P pair<ll, ll> #define prique priority_queue<ll> #define all(a) (a).begin(), (a).end() const int mod = 1000000007; const int mod2 = 998244353; const int inf = 1 << 30; const int MOD = 1e9 + 7; long long fac[510000], finv[510000], inv[510000]; long long MAX = 510000; bool COMinited = false; long long COM(int n, int k) { if (COMinited == false) { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } COMinited = true; } if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } template <int MOD> struct Fp { long long val; constexpr Fp(long long v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr int getmod() { return MOD; } constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; } constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; } constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; } constexpr Fp &operator+=(const Fp &r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp &operator-=(const Fp &r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp &operator*=(const Fp &r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp &operator/=(const Fp &r) noexcept { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator==(const Fp &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const Fp &r) const noexcept { return this->val != r.val; } friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept { return os << x.val; } friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; using mint = Fp<1000000007>; int bin(int bina) { int ans = 0; for (int i = 0; bina > 0; i++) { ans = ans + (bina % 2) * pow(10, i); bina = bina / 2; } return ans; } bool prime(int n) { for (ll i = 2; i <= sqrt(n); i++) { if (n % i == 0) return false; } return n != 1; } ll gcd(ll a, ll b) { if (b == 0) { return a; } return gcd(b, a % b); } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } 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 mod_pow(int x, int y, int m) { int res = 1; while (y > 0) { if (y & 1) { res = res * x % m; } x = x * x % m; y >>= 1; } return res; } int jo(int x, int y) { int res = 1; while (y > 0) { if (y & 1) { res = res * x; } x = x * x; y >>= 1; } return res; } int per(int n, int r) { r = n - r; int sum = 1; int i; for (i = n; i >= r + 1; i--) sum *= i; return sum; } struct UnionFind { vector<int> par; UnionFind(int n) : par(n, -1) {} int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool issame(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } }; 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...)); } void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; } 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; } // cout << fixed << setprecision(10) << num << endl; struct edge { int to, cost; }; #define F first #define S second vector<pair<long long, long long>> prime_factorize(long long N) { vector<pair<long long, long long>> res; for (long long a = 2; a * a <= N; ++a) { if (N % a != 0) continue; long long ex = 0; // 指数 // 割れる限り割り続ける while (N % a == 0) { ++ex; N /= a; } // その結果を push res.push_back({a, ex}); } // 最後に残った数について if (N != 1) res.push_back({N, 1}); return res; } using graph = vector<vector<int>>; // cout << fixed << setprecision(10) << num << endl; prique que; int a[200010]; signed main() { int n; cin >> n; rep(i, n) cin >> a[i]; sort(a, a + n); reverse(a, a + n); que.push(a[0]); int ans = 0; loop(i, 1, n) { ans += que.top(); que.pop(); que.push(a[i]); que.push(a[i]); } cout << ans << endl; }
replace
278
279
278
279
0
p02615
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> int main() { using namespace std; long long n, a[2000] = {}, s, w; bool flag = 0; cin >> n; for (long i = 0; i < n; ++i) { cin >> a[i]; } sort(a, a + n); s = a[n - 1]; w = n - 2; for (long j = n - 2; j > 0; --j) { s += a[w]; if (flag) w--; flag = !flag; } cout << s; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> int main() { using namespace std; long long n, a[200000] = {}, s, w; bool flag = 0; cin >> n; for (long i = 0; i < n; ++i) { cin >> a[i]; } sort(a, a + n); s = a[n - 1]; w = n - 2; for (long j = n - 2; j > 0; --j) { s += a[w]; if (flag) w--; flag = !flag; } cout << s; return 0; }
replace
7
8
7
8
0
p02615
C++
Runtime Error
#include <bits/stdc++.h> #define sz(v) ((int)(v).size()) #define all(v) ((v).begin()), ((v).end()) #define allr(v) ((v).rbegin()), ((v).rend()) #define pb push_back #define mp make_pair #define clr(v, val) memset(v, val, sizeof(v)) #define lcm(a, b) ((a * b) / (__gcd(a, b))) typedef long long ll; typedef unsigned long long ull; const double eps = (1e-9); using namespace std; int getBit(ll num, int idx) { return ((num >> idx) & 1ll) == 1; } ll setBit1(ll num, ll idx) { return num | (1ll << idx); } ll setBit0(ll num, int idx) { return num & ~(1ll << idx); } ll flipBit(ll num, int idx) { return num ^ (1ll << idx); } int dcmp(long double a, long double b) { return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1; } void GO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const int N = 500000 + 5, mod = 1e9 + 7; int a[100000 + 9]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); ll ans = 0; int lim = n - 1; for (int i = n - 1; i >= 0 && lim > 0; i--) { ans += a[i]; lim--; if (lim > 0 && i != n - 1) ans += a[i], lim--; } cout << ans << "\n"; }
#include <bits/stdc++.h> #define sz(v) ((int)(v).size()) #define all(v) ((v).begin()), ((v).end()) #define allr(v) ((v).rbegin()), ((v).rend()) #define pb push_back #define mp make_pair #define clr(v, val) memset(v, val, sizeof(v)) #define lcm(a, b) ((a * b) / (__gcd(a, b))) typedef long long ll; typedef unsigned long long ull; const double eps = (1e-9); using namespace std; int getBit(ll num, int idx) { return ((num >> idx) & 1ll) == 1; } ll setBit1(ll num, ll idx) { return num | (1ll << idx); } ll setBit0(ll num, int idx) { return num & ~(1ll << idx); } ll flipBit(ll num, int idx) { return num ^ (1ll << idx); } int dcmp(long double a, long double b) { return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1; } void GO() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); } const int N = 500000 + 5, mod = 1e9 + 7; int a[200000 + 9]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); ll ans = 0; int lim = n - 1; for (int i = n - 1; i >= 0 && lim > 0; i--) { ans += a[i]; lim--; if (lim > 0 && i != n - 1) ans += a[i], lim--; } cout << ans << "\n"; }
replace
25
26
25
26
0
p02615
C++
Runtime Error
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; typedef long long ll; int main() { ll c; int a[100000]; int x; scanf("%d", &x); for (int i = 1; i <= x; i++) { scanf("%lld", &a[i]); } sort(a + 1, a + 1 + x); c = a[x]; int d = 0; for (int i = 1; i <= x - 2; i++) { if (i & 1) d++; c += a[x - d]; } printf("%lld\n", c); return 0; }
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; typedef long long ll; int main() { ll c; int a[200005]; int x; scanf("%d", &x); for (int i = 1; i <= x; i++) { scanf("%lld", &a[i]); } sort(a + 1, a + 1 + x); c = a[x]; int d = 0; for (int i = 1; i <= x - 2; i++) { if (i & 1) d++; c += a[x - d]; } printf("%lld\n", c); return 0; }
replace
9
10
9
10
0
p02615
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // #include<ext/pb_ds/assoc_container.hpp> // #include<ext/pb_ds/tree_policy.hpp> // // #pragma GCC optimize("unroll-loops") // #pragma GCC optimize("Ofast") // #pragma GCC optimize("-O3") // #pragma GCC optimize("no-stack-protector") // #pragma GCC optimize("fast-math") // #define LOCAL #define sim template <class c #define ris return *this #define dor > debug &operator<< #define eni(x) \ sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \ c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c *x) -> decltype(cout << *x, 0); sim > char dud(...); struct debug { #ifndef LOCAL ~debug() { cout << endl; } eni(!=) cout << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair<b, c> d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c &) { ris; } #endif } ; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define fi first #define f first #define se second #define s second #define vi_a vector<int> a; #define p_b push_back ////////////////////////////////???????????????CHECK THIS ///OUT???????????????////////////////////////////// #define ll long long ////////////////////////////////???????????????CHECK THIS ///OUT???????????????////////////////////////////// #define ld long double #define pll pair<ll, ll> #define pii pair<int, int> #define m_p make_pair #define fast_io \ cin.tie(0); \ cout.tie(0); \ ios_base::sync_with_stdio(0); #define all(x) x.begin(), x.end() #define getfiles \ ifstream cin("input.txt"); \ ofstream cout("output.txt"); #define pw(x) (1ll << x) #define sz(x) (ll) x.size() #define rall(x) x.rbegin(), x.rend() #define len(a) (ll) a.size() #define rep(x, l, r) for (ll x = l; x < r; x++) // using namespace __gnu_pbds; ld eps = (ld)1 / 1e6; const ld pi = 3.14159265359; ll inf = 1e18, mod1 = 1e9 + 7; ll sqr(ll a) { return a * a; } ll qb(ll a) { return a * a * a; } ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); } ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; } ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// const ll R = 1e4; const ll tx[4] = {0, 0, -1, 1}; const ll ty[4] = {-1, 1, 0, 0}; const char rev_to[4] = {'E', 'W', 'N', 'S'}; const int N = 1e5 + 1; const int M = 1e9 + 7; int n; int a[N]; signed main() { fast_io; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); // reverse(a,a+n); int cur = n - 1, cnt = 1; ll ans = 0; for (int i = 1; i < n; i++) { cnt++; // cout<<a[cur]<<' '<<cur<<endl; ans += a[cur]; if (cnt % 2 == 0) { cur--; } } cout << ans; return 0; } /// stuff you should look for : /* * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * read the conditions carefully * WRITE STUFF DOWN */
#include <bits/stdc++.h> using namespace std; // #include<ext/pb_ds/assoc_container.hpp> // #include<ext/pb_ds/tree_policy.hpp> // // #pragma GCC optimize("unroll-loops") // #pragma GCC optimize("Ofast") // #pragma GCC optimize("-O3") // #pragma GCC optimize("no-stack-protector") // #pragma GCC optimize("fast-math") // #define LOCAL #define sim template <class c #define ris return *this #define dor > debug &operator<< #define eni(x) \ sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \ c i) { sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c *x) -> decltype(cout << *x, 0); sim > char dud(...); struct debug { #ifndef LOCAL ~debug() { cout << endl; } eni(!=) cout << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair<b, c> d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; } #else sim dor(const c &) { ris; } #endif } ; #define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] " #define fi first #define f first #define se second #define s second #define vi_a vector<int> a; #define p_b push_back ////////////////////////////////???????????????CHECK THIS ///OUT???????????????////////////////////////////// #define ll long long ////////////////////////////////???????????????CHECK THIS ///OUT???????????????////////////////////////////// #define ld long double #define pll pair<ll, ll> #define pii pair<int, int> #define m_p make_pair #define fast_io \ cin.tie(0); \ cout.tie(0); \ ios_base::sync_with_stdio(0); #define all(x) x.begin(), x.end() #define getfiles \ ifstream cin("input.txt"); \ ofstream cout("output.txt"); #define pw(x) (1ll << x) #define sz(x) (ll) x.size() #define rall(x) x.rbegin(), x.rend() #define len(a) (ll) a.size() #define rep(x, l, r) for (ll x = l; x < r; x++) // using namespace __gnu_pbds; ld eps = (ld)1 / 1e6; const ld pi = 3.14159265359; ll inf = 1e18, mod1 = 1e9 + 7; ll sqr(ll a) { return a * a; } ll qb(ll a) { return a * a * a; } ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); } ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; } ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// const ll R = 1e4; const ll tx[4] = {0, 0, -1, 1}; const ll ty[4] = {-1, 1, 0, 0}; const char rev_to[4] = {'E', 'W', 'N', 'S'}; const int N = 1e6 + 1; const int M = 1e9 + 7; int n; int a[N]; signed main() { fast_io; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); // reverse(a,a+n); int cur = n - 1, cnt = 1; ll ans = 0; for (int i = 1; i < n; i++) { cnt++; // cout<<a[cur]<<' '<<cur<<endl; ans += a[cur]; if (cnt % 2 == 0) { cur--; } } cout << ans; return 0; } /// stuff you should look for : /* * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * read the conditions carefully * WRITE STUFF DOWN */
replace
97
98
97
98
0
p02615
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define db(x) cout << (x) << '\n'; #define all(x) x.begin(), x.end() #define UNIQUE(x) sort(all(x)), x.resize(unique(all(x)) - x.begin()) #define LB(v, x) lower_bound(all(v), x) #define UB(v, x) upper_bound(all(v), x) #define endl "\n" #define F first #define S second #define PB push_back #define PF push_front #define int long long #define double long double #define trick int m = (l + r) >> 1, lc = n << 1, rc = lc | 1 typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vii; int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; int dx[] = {-1, -1, 0, 1, 1, 1, 0, -1}; const int maxn = 1e5; const int OO = 1e18; const int mod = 1e9 + 7; const double PI = acos(-1); void maxself(int &a, int b) { a = max(a, b); } void minself(int &a, int b) { a = min(a, b); } vector<vi> g(maxn); int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("name.in","r",stdin); // freopen("name.out","w",stdout); int n; cin >> n; vi v(n); for (int i = 0; i < n; i++) cin >> v[i]; sort(all(v)); deque<int> d; d.PB(v[n - 1]); int ans = 0; for (int i = n - 2; i >= 0; i--) { int ele = v[i]; int pos = -1; int mx = 0; for (int j = 0; j < d.size(); j++) { if (min(d[j], d[(j + 1) % d.size()]) > mx) { mx = min(d[j], d[(j + 1) % d.size()]); pos = j + 1; } } // cout << mx << endl; ans += mx; if (pos <= d.size() / 2) { vi aux; for (int j = 0; j < pos; j++) { aux.PB(d.front()); d.pop_front(); } d.push_front(v[i]); while (aux.size()) { d.push_front(aux[aux.size() - 1]); aux.pop_back(); } } else { vi aux; int y = d.size(); while (y != pos - 1) { aux.PB(d[y]); d.pop_back(); y--; } d.PB(v[i]); while (aux.size()) { d.PB(aux[aux.size() - 1]); aux.pop_back(); } } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define db(x) cout << (x) << '\n'; #define all(x) x.begin(), x.end() #define UNIQUE(x) sort(all(x)), x.resize(unique(all(x)) - x.begin()) #define LB(v, x) lower_bound(all(v), x) #define UB(v, x) upper_bound(all(v), x) #define endl "\n" #define F first #define S second #define PB push_back #define PF push_front #define int long long #define double long double #define trick int m = (l + r) >> 1, lc = n << 1, rc = lc | 1 typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vii; int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; int dx[] = {-1, -1, 0, 1, 1, 1, 0, -1}; const int maxn = 1e5; const int OO = 1e18; const int mod = 1e9 + 7; const double PI = acos(-1); void maxself(int &a, int b) { a = max(a, b); } void minself(int &a, int b) { a = min(a, b); } vector<vi> g(maxn); int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("name.in","r",stdin); // freopen("name.out","w",stdout); int n; cin >> n; vi v(n); for (int i = 0; i < n; i++) cin >> v[i]; sort(all(v)); int ans = v[n - 1]; int j = n - 2; int cont = 0; for (int i = n - 3; i >= 0; i--) { ans += v[j]; cont++; if (cont == 2) cont = 0, j--; } cout << ans; return 0; }
replace
49
92
49
57
-11
p02615
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> Pi; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, n) for (int i = 1; i <= (n); i++) #define rep3(i, i0, n) for (int i = i0; i < (n); i++) #define pb push_back #define mod 1000000007 const ll INF = 1LL << 60; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } 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; } #define all(x) x.begin(), x.end() #define mp make_pair bool compare(Pi a, Pi b) { if (a.first != b.first) { return a.first < b.first; } else { return a.second < b.second; } } bool In_map(ll y, ll x, ll h, ll w) { if (y < 0 || x < 0 || y >= h || x >= w) { return 0; } else { return 1; } } const vector<ll> dx{1, 0, -1, 0}; const vector<ll> dy{0, 1, 0, -1}; int main() { ll N; cin >> N; vector<ll> A(N); rep(i, N) { cin >> A[i]; } sort(all(A)); reverse(all(A)); ll ans = A[0]; ll i = 1; ll cnt = 1; while (1) { ans += A[i]; cnt++; if (cnt == N - 1) break; ans += A[i]; cnt++; if (cnt == N - 1) break; i++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> Pi; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, n) for (int i = 1; i <= (n); i++) #define rep3(i, i0, n) for (int i = i0; i < (n); i++) #define pb push_back #define mod 1000000007 const ll INF = 1LL << 60; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } 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; } #define all(x) x.begin(), x.end() #define mp make_pair bool compare(Pi a, Pi b) { if (a.first != b.first) { return a.first < b.first; } else { return a.second < b.second; } } bool In_map(ll y, ll x, ll h, ll w) { if (y < 0 || x < 0 || y >= h || x >= w) { return 0; } else { return 1; } } const vector<ll> dx{1, 0, -1, 0}; const vector<ll> dy{0, 1, 0, -1}; int main() { ll N; cin >> N; vector<ll> A(N); rep(i, N) { cin >> A[i]; } sort(all(A)); reverse(all(A)); ll ans = A[0]; ll i = 1; ll cnt = 1; while (1) { if (cnt == N - 1) break; ans += A[i]; cnt++; if (cnt == N - 1) break; ans += A[i]; cnt++; if (cnt == N - 1) break; i++; } cout << ans << endl; return 0; }
insert
60
60
60
62
0
p02615
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)n; ++i) using namespace std; using ll = long long; const int MAXN = 100001; int a[MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; rep(i, n) cin >> a[i]; sort(a, a + n); reverse(a, a + n); ll ans = a[0]; map<int, int> spaces{{a[1], 2}}; for (int i = 2; i < n; ++i) { int best_space = spaces.rbegin()->first; ans += best_space; spaces[best_space]--; if (spaces[best_space] == 0) { spaces.erase(best_space); } spaces[a[i]] += 2; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)n; ++i) using namespace std; using ll = long long; const int MAXN = 200001; int a[MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; rep(i, n) cin >> a[i]; sort(a, a + n); reverse(a, a + n); ll ans = a[0]; map<int, int> spaces{{a[1], 2}}; for (int i = 2; i < n; ++i) { int best_space = spaces.rbegin()->first; ans += best_space; spaces[best_space]--; if (spaces[best_space] == 0) { spaces.erase(best_space); } spaces[a[i]] += 2; } cout << ans << endl; return 0; }
replace
4
5
4
5
0
p02615
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define fi first #define se second #define pb push_back #define me(a, b) memset(a, b, sizeof(a)) #define INIT() std::ios::sync_with_stdio(false) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; const int MAX_N = 100000 + 5; const int INF = 0x7fffffff; const int inf = 100000; const double EPS = 1e-6; const ull base = 123; const ll mod = 1e9 + 7; const double pi = 4 * atan(1.0); ll a[MAX_N]; bool cmp(ll a, ll b) { return a > b; } int main(void) { int n; ll sum = 0; cin >> n; int i; for (i = 1; i <= n; i++) scanf("%lld", &a[i]); sort(a + 1, a + 1 + n, cmp); sum += a[1]; int pos = 2; for (i = 2; i < n; i++) { if (i % 2 == 0) sum += a[pos]; else sum += a[pos++]; } cout << sum << endl; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> #define fi first #define se second #define pb push_back #define me(a, b) memset(a, b, sizeof(a)) #define INIT() std::ios::sync_with_stdio(false) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; const int MAX_N = 200000 + 5; const int INF = 0x7fffffff; const int inf = 100000; const double EPS = 1e-6; const ull base = 123; const ll mod = 1e9 + 7; const double pi = 4 * atan(1.0); ll a[MAX_N]; bool cmp(ll a, ll b) { return a > b; } int main(void) { int n; ll sum = 0; cin >> n; int i; for (i = 1; i <= n; i++) scanf("%lld", &a[i]); sort(a + 1, a + 1 + n, cmp); sum += a[1]; int pos = 2; for (i = 2; i < n; i++) { if (i % 2 == 0) sum += a[pos]; else sum += a[pos++]; } cout << sum << endl; }
replace
23
24
23
24
0
p02615
C++
Runtime Error
#include <bits/stdc++.h> // #define DEBUG using namespace std; constexpr uint32_t mxN = 2e5; uint64_t A[mxN]; void solve() { uint32_t N; cin >> N; for (uint32_t i = 0; i < N; i++) { cin >> A[i]; } std::sort(A, A + N, std::greater<uint64_t>()); // cout << "A " << endl; // for(uint32_t i = 0 ; i < N ; i++){ // cout << A[i] << " "; // } // cout << endl; uint64_t sum = A[0]; std::queue<uint32_t> q; q.push(1); for (uint64_t i = 2; i < N; i++) { sum += A[q.front()]; // cout << "Got " << A[q.front()] << endl; q.push(A[i]); if (i % 2) { q.pop(); } } cout << sum << endl; } int main() { // making data IO Fast std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); /****************************/ #ifdef DEBUG int TEST_CASES = 2; while (TEST_CASES--) { #endif // DEBBUG solve(); #ifdef DEBUG } #endif // DEBUG return 0; }
#include <bits/stdc++.h> // #define DEBUG using namespace std; constexpr uint32_t mxN = 2e5; uint64_t A[mxN]; void solve() { uint32_t N; cin >> N; for (uint32_t i = 0; i < N; i++) { cin >> A[i]; } std::sort(A, A + N, std::greater<uint64_t>()); // cout << "A " << endl; // for(uint32_t i = 0 ; i < N ; i++){ // cout << A[i] << " "; // } // cout << endl; uint64_t sum = A[0]; std::queue<uint32_t> q; q.push(1); for (uint64_t i = 2; i < N; i++) { sum += A[q.front()]; // cout << "Got " << A[q.front()] << endl; q.push(i); if (i % 2) { q.pop(); } } cout << sum << endl; } int main() { // making data IO Fast std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); /****************************/ #ifdef DEBUG int TEST_CASES = 2; while (TEST_CASES--) { #endif // DEBBUG solve(); #ifdef DEBUG } #endif // DEBUG return 0; }
replace
28
29
28
29
0
p02615
C++
Runtime Error
/** ____ ____ ____ ____ ____ ||a |||t |||o |||d |||o || ||__|||__|||__|||__|||__|| |/__\|/__\|/__\|/__\|/__\| **/ #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N_MAX = 100002; int n; int f[N_MAX]; multiset<int> s; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> f[i]; sort(f + 1, f + n + 1); reverse(f + 1, f + n + 1); ll ans = 0; s.insert(-f[1]); for (int i = 2; i <= n; i++) { int t = -(*s.begin()); s.erase(s.begin()); ans += t; s.insert(-f[i]); s.insert(-f[i]); } cout << ans << "\n"; return 0; }
/** ____ ____ ____ ____ ____ ||a |||t |||o |||d |||o || ||__|||__|||__|||__|||__|| |/__\|/__\|/__\|/__\|/__\| **/ #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N_MAX = 200002; int n; int f[N_MAX]; multiset<int> s; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n; for (int i = 1; i <= n; i++) cin >> f[i]; sort(f + 1, f + n + 1); reverse(f + 1, f + n + 1); ll ans = 0; s.insert(-f[1]); for (int i = 2; i <= n; i++) { int t = -(*s.begin()); s.erase(s.begin()); ans += t; s.insert(-f[i]); s.insert(-f[i]); } cout << ans << "\n"; return 0; }
replace
14
15
14
15
0
p02615
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstdlib> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> #define DEBUG 1 using namespace std; constexpr int kMod = 1000000007; typedef long long LL; template <typename T> istream &operator>>(istream &is, vector<T> &vs) { for (T &v : vs) is >> v; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &m) { for (const auto [k, v] : m) os << "{" << k << "," << v << "} "; return os; } int main() { int N; cin >> N; vector<LL> A(N); cin >> A; sort(A.rbegin(), A.rend()); LL sum = 0; map<LL, LL> m; m[A[0]] = 1; for (int i = 1; i < N; ++i) { for (auto it = m.rbegin(); it != m.rend(); ++it) { auto &[k, v] = *it; if (v == 0) continue; sum += k; --v; break; } m[A[i]] += 2; } cout << sum << endl; }
#include <algorithm> #include <bitset> #include <cassert> #include <climits> #include <cmath> #include <cstdlib> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> #define DEBUG 1 using namespace std; constexpr int kMod = 1000000007; typedef long long LL; template <typename T> istream &operator>>(istream &is, vector<T> &vs) { for (T &v : vs) is >> v; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &m) { for (const auto [k, v] : m) os << "{" << k << "," << v << "} "; return os; } int main() { int N; cin >> N; vector<LL> A(N); cin >> A; sort(A.rbegin(), A.rend()); LL sum = 0; map<LL, LL> m; m[A[0]] = 1; for (int i = 1; i < N; ++i) { auto it = m.rbegin(); auto &[k, v] = *it; sum += k; --v; if (v == 0) m.erase(k); m[A[i]] += 2; } cout << sum << endl; }
replace
42
50
42
48
TLE
p02615
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <queue> using namespace std; typedef long long ll; const int N = 100005; int n; ll ans; int w[N]; priority_queue<int> q; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", w + i); sort(w, w + n); reverse(w, w + n); q.push(w[0]); for (int i = 1; i < n; i++) { ans += q.top(), q.pop(); q.push(w[i]), q.push(w[i]); } printf("%lld\n", ans); return 0; }
#include <algorithm> #include <cstdio> #include <queue> using namespace std; typedef long long ll; const int N = 200005; int n; ll ans; int w[N]; priority_queue<int> q; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", w + i); sort(w, w + n); reverse(w, w + n); q.push(w[0]); for (int i = 1; i < n; i++) { ans += q.top(), q.pop(); q.push(w[i]), q.push(w[i]); } printf("%lld\n", ans); return 0; }
replace
7
8
7
8
0
p02615
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> #define rep(i, n) for (int i = 0; i < n; ++i) #define rep1(i, n) for (int i = 1; i <= n; ++i) using namespace std; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } typedef long long ll; int main() { int n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; sort(a.begin(), a.end()); ll res = a[n - 1]; int idx = n - 2; n -= 2; while (1) { if (n == 1) { res += a[idx]; break; } else { n -= 2; res += 2 * a[idx]; idx--; } if (n == 0) break; } cout << res << "\n"; return 0; }
#include <algorithm> #include <iostream> #include <vector> #define rep(i, n) for (int i = 0; i < n; ++i) #define rep1(i, n) for (int i = 1; i <= n; ++i) using namespace std; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } typedef long long ll; int main() { int n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; sort(a.begin(), a.end()); ll res = a[n - 1]; int idx = n - 2; n -= 2; while (1) { if (n == 0) break; if (n == 1) { res += a[idx]; break; } else { n -= 2; res += 2 * a[idx]; idx--; } if (n == 0) break; } cout << res << "\n"; return 0; }
insert
32
32
32
34
0
p02615
C++
Runtime Error
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) int main() { int n; cin >> n; vi a(n); rep(i, 0, n) cin >> a[i]; sort(a.begin(), a.end()); ll ans = 0; rep(i, 1, n) { int j = n - (j / 2); j--; ans += a[j]; } cout << ans << endl; return 0; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) int main() { int n; cin >> n; vi a(n); rep(i, 0, n) cin >> a[i]; sort(a.begin(), a.end()); ll ans = 0; rep(i, 1, n) { int j = n - (i / 2); j--; ans += a[j]; } cout << ans << endl; return 0; }
replace
22
23
22
23
-6
/usr/include/c++/12/debug/vector:442: In function: std::debug::vector<_Tp, _Allocator>::reference std::debug::vector<_Tp, _Allocator>::operator[](size_type) [with _Tp = int; _Allocator = std::allocator<int>; reference = int&; size_type = long unsigned int] Error: attempt to subscript container with out-of-bounds index -16282, but container only holds 4 elements. Objects involved in the operation: sequence "this" @ 0x7ffcf2e74430 { type = std::debug::vector<int, std::allocator<int> >; }
p02615
C++
Runtime Error
#include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <string> #include <vector> using namespace std; #define fori(x) for (int i = 0; i < x; ++i) #define forj(x) for (int j = 0; j < x; ++j) typedef long long ll; const int INF = 2e9 + 5; const int alength = 100100; int main() { int n; cin >> n; ll a[alength] = {}; fori(n) { cin >> a[i]; } sort(a, a + n, greater<ll>()); unsigned long long ans = a[0]; for (int i = 1; i * 2 < n - n % 2; ++i) { ans += a[i] * 2; } if (n % 2 != 0) { ans += a[n / 2]; } cout << ans; }
#include <algorithm> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <string> #include <vector> using namespace std; #define fori(x) for (int i = 0; i < x; ++i) #define forj(x) for (int j = 0; j < x; ++j) typedef long long ll; const int INF = 2e9 + 5; const int alength = 100100 * 2; int main() { int n; cin >> n; ll a[alength] = {}; fori(n) { cin >> a[i]; } sort(a, a + n, greater<ll>()); unsigned long long ans = a[0]; for (int i = 1; i * 2 < n - n % 2; ++i) { ans += a[i] * 2; } if (n % 2 != 0) { ans += a[n / 2]; } cout << ans; }
replace
17
18
17
18
0
p02615
C++
Runtime Error
#include <algorithm> #include <iostream> #include <math.h> #include <vector> using namespace std; int main() { long int N, a[100000], count = 0; cin >> N; for (int i = 0; i < N; i++) { cin >> a[i]; } sort(a, a + N, greater<int>()); for (int j = 0; j < N; j++) { count += a[j / 2]; } count -= a[0]; cout << count << endl; return 0; }
#include <algorithm> #include <iostream> #include <math.h> #include <vector> using namespace std; int main() { long int N, a[200000], count = 0; cin >> N; for (int i = 0; i < N; i++) { cin >> a[i]; } sort(a, a + N, greater<int>()); for (int j = 0; j < N; j++) { count += a[j / 2]; } count -= a[0]; cout << count << endl; return 0; }
replace
7
8
7
8
0
p02615
C++
Runtime Error
// https://atcoder.jp/contests/abc173/tasks/abc173_d #include <algorithm> #include <cstdio> #include <cstdlib> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; using P = pair<ll, ll>; int main() { int N; cin >> N; vector<ll> A(N); for (int i = 0; i < N; ++i) cin >> A[i]; // 降順にソートして、大きい要素から並べる std::sort(A.begin(), A.end(), std::greater_equal<ll>()); ll ans = A[0]; if (N == 2) { cout << ans << endl; return 0; } for (int i = 2; i < N; ++i) { ans += A[i / 2]; } cout << ans << endl; return 0; }
// https://atcoder.jp/contests/abc173/tasks/abc173_d #include <algorithm> #include <cstdio> #include <cstdlib> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; using P = pair<ll, ll>; int main() { int N; cin >> N; vector<ll> A(N); for (int i = 0; i < N; ++i) cin >> A[i]; // 降順にソートして、大きい要素から並べる std::sort(A.begin(), A.end(), std::greater<ll>()); ll ans = A[0]; if (N == 2) { cout << ans << endl; return 0; } for (int i = 2; i < N; ++i) { ans += A[i / 2]; } cout << ans << endl; return 0; }
replace
24
25
24
25
0
p02615
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; int main() { int N; cin >> N; int arr[N]; for (int i = 0; i < N; i++) cin >> arr[i]; sort(arr, arr + N); long long ans = arr[N - 1]; int j = arr[N - 2]; for (int i = N - 3; i >= 0;) { ans += arr[j], --i; if (i >= 0) ans += arr[j], --i; j--; } cout << ans << endl; }
#include <algorithm> #include <iostream> using namespace std; int main() { int N; cin >> N; int arr[N]; for (int i = 0; i < N; i++) cin >> arr[i]; sort(arr, arr + N); long long ans = arr[N - 1]; int j = N - 2; for (int i = N - 3; i >= 0;) { ans += arr[j], --i; if (i >= 0) ans += arr[j], --i; j--; } cout << ans << endl; }
replace
12
13
12
13
0
p02615
Python
Time Limit Exceeded
# -*- coding: utf-8 -*- N = int(input()) A = list(map(int, input().split())) a_sorted = sorted(A, key=lambda x: -x) circle = [a_sorted[0]] ans = 0 for a in a_sorted: tmp = 0 tmp_idx = -1 for i in range(len(circle) - 1): cand = min(circle[i], circle[i + 1]) if cand > tmp: tmp = cand tmp_idx = i ans += tmp circle.insert(tmp_idx + 1, a) print(ans)
# -*- coding: utf-8 -*- N = int(input()) A = list(map(int, input().split())) a_sorted = sorted(A, key=lambda x: -x) circle = [a_sorted[0]] ans = 0 for idx, a in enumerate(a_sorted[1:]): ans += circle[idx] circle.extend([a, a]) print(ans)
replace
9
19
9
12
TLE
p02615
Python
Runtime Error
from collections import deque n = int(input()) a = sorted(map(int, input().split()), reverse=True) ans, cnt = 0, deque([a[0]]) for i in a[1:]: ans += cnt.popleft() cnt.append(a[i]) cnt.append(a[i]) print(ans)
from collections import deque n = int(input()) a = sorted(map(int, input().split()), reverse=True) ans, cnt = 0, deque([a[0]]) for i in a[1:]: ans += cnt.popleft() cnt.append(i) cnt.append(i) print(ans)
replace
8
10
8
10
0
p02615
Python
Time Limit Exceeded
n = int(input()) a = [int(i) for i in input().split()] a.sort() a = a[::-1] cur = [a[0], a[1]] now = a[0] for i in a[2:]: loc = 0 maxer = min(cur[0], cur[-1]) for j in range(1, len(cur)): temp = min(cur[j - 1], cur[j]) if temp > maxer: loc = j maxer = temp now += maxer cur = cur[:loc] + [i] + cur[loc:] print(now)
n = int(input()) a = [int(i) for i in input().split()] a.sort() a = a[::-1] if n % 3 == 0: if n % 2 == 0: print(a[0] + sum(a[1 : n // 2]) * 2) else: print(a[0] + sum(a[1 : n // 2]) * 2 + a[n // 2]) elif n % 3 == 2: if n % 2 == 0: print(a[0] + sum(a[1 : n // 2]) * 2) else: print(a[0] + sum(a[1 : n // 2]) * 2 + a[n // 2]) else: if n % 2 == 0: print(a[0] + sum(a[1 : n // 2]) * 2) else: print(a[0] + sum(a[1 : n // 2]) * 2 + a[n // 2])
replace
5
19
5
20
TLE
p02615
C++
Time Limit Exceeded
#include <bits/stdc++.h> // #include <boost/lexical_cast.hpp> using namespace std; #define ll long long int #define vll vector<ll> #define vllv vector<vector<ll>> #define vpii vector<pair<ll, ll>> #define sz size() #define pb push_back #define ff first #define ss second #define all(v) v.begin(), v.end() #define allr(v) v.rbegin(), v.rend() #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) ll MOD = 1000000000 + 7; ll ceil1(ll n, ll m) { if (n % m == 0) { return n / m; } return n / m + 1; } ll factor(ll n) { vll ans; if (n == 2) ans.pb(2); else { for (ll i = 2; i * i <= n; i++) { if (n % i == 0 && n % i != i) { ans.pb(i); if (n / i != i) ans.pb(n / i); } } ans.pb(n); } return ans.sz + 1; } ll fact(ll n) { ll res = 1; for (ll i = 2; i <= n; i++) res = res * i; return res; } ll nCr(ll n, ll r) { return fact(n) / (fact(r) * fact(n - r)); } void dfs(vllv &v, ll k, vll &par, vll &dis, ll p) { par[k] = p; dis[k] = dis[p] + 1; for (ll i = 0; i < v[k].sz; i++) { if (v[k][i] != p) { dfs(v, v[k][i], par, dis, k); } } } bool sortbysec(const pair<string, int> &a, const pair<string, int> &b) { return (a.second < b.second); } ll pow2(ll n, ll k) { ll ans = 1; while (k > 0) { if (k % 2 == 1) ans = ans * n; n = n * n; k /= 2; } return ans; } bool prime(int n) { int i, j; for (i = 2; i <= sqrt(n); i++) { if (n % i == 0) { return false; } } return true; } bool bserch(vector<string> a, string s) { ll l = 0, r = a.sz - 1, mid; while (l <= r) { mid = (l + r) / 2; if (a[mid] == s) return true; if (a[mid] < s) { l = mid + 1; } else { r = mid - 1; } } return false; } bool sortcol(const vector<int> &v1, const vector<int> &v2) { return v1[0] < v2[0]; } ll sumdegit(ll n) { ll sum = 0; while (n > 0) { sum += (n % 10); n /= 10; } return sum; } void solve() { /*ll h,w,k; vector<string> s; for(ll i=0;i<n;i++) cin>>s;*/ ll n; cin >> n; vll a(n); for (ll i = 0; i < n; i++) cin >> a[i]; sort(all(a)); ll ans = 0; ans += a[n - 1]; ll k = n - 2; ll c = n - 2; while (1) { if (c > 1) { // cout<<a[k]<<" "; ans += (2 * a[k]); k--; c -= 2; if (c == 0) break; } else if (c == 1) { // cout<<a[k]<<" "; ans += a[k]; k--; break; } } cout << ans; return; } int main() { fast; ll q; q = 1; // cin>>q; while (q--) { solve(); } return 0; }
#include <bits/stdc++.h> // #include <boost/lexical_cast.hpp> using namespace std; #define ll long long int #define vll vector<ll> #define vllv vector<vector<ll>> #define vpii vector<pair<ll, ll>> #define sz size() #define pb push_back #define ff first #define ss second #define all(v) v.begin(), v.end() #define allr(v) v.rbegin(), v.rend() #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) ll MOD = 1000000000 + 7; ll ceil1(ll n, ll m) { if (n % m == 0) { return n / m; } return n / m + 1; } ll factor(ll n) { vll ans; if (n == 2) ans.pb(2); else { for (ll i = 2; i * i <= n; i++) { if (n % i == 0 && n % i != i) { ans.pb(i); if (n / i != i) ans.pb(n / i); } } ans.pb(n); } return ans.sz + 1; } ll fact(ll n) { ll res = 1; for (ll i = 2; i <= n; i++) res = res * i; return res; } ll nCr(ll n, ll r) { return fact(n) / (fact(r) * fact(n - r)); } void dfs(vllv &v, ll k, vll &par, vll &dis, ll p) { par[k] = p; dis[k] = dis[p] + 1; for (ll i = 0; i < v[k].sz; i++) { if (v[k][i] != p) { dfs(v, v[k][i], par, dis, k); } } } bool sortbysec(const pair<string, int> &a, const pair<string, int> &b) { return (a.second < b.second); } ll pow2(ll n, ll k) { ll ans = 1; while (k > 0) { if (k % 2 == 1) ans = ans * n; n = n * n; k /= 2; } return ans; } bool prime(int n) { int i, j; for (i = 2; i <= sqrt(n); i++) { if (n % i == 0) { return false; } } return true; } bool bserch(vector<string> a, string s) { ll l = 0, r = a.sz - 1, mid; while (l <= r) { mid = (l + r) / 2; if (a[mid] == s) return true; if (a[mid] < s) { l = mid + 1; } else { r = mid - 1; } } return false; } bool sortcol(const vector<int> &v1, const vector<int> &v2) { return v1[0] < v2[0]; } ll sumdegit(ll n) { ll sum = 0; while (n > 0) { sum += (n % 10); n /= 10; } return sum; } void solve() { /*ll h,w,k; vector<string> s; for(ll i=0;i<n;i++) cin>>s;*/ ll n; cin >> n; vll a(n); for (ll i = 0; i < n; i++) cin >> a[i]; sort(all(a)); ll ans = 0; ans += a[n - 1]; ll k = n - 2; ll c = n - 2; while (1) { if (c == 0) break; if (c > 1) { // cout<<a[k]<<" "; ans += (2 * a[k]); k--; c -= 2; if (c == 0) break; } else if (c == 1) { // cout<<a[k]<<" "; ans += a[k]; k--; break; } } cout << ans; return; } int main() { fast; ll q; q = 1; // cin>>q; while (q--) { solve(); } return 0; }
insert
128
128
128
130
TLE
p02615
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long long n, a[100010], ans, x; int main() { cin >> n; for (long long i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); ans += a[n - 1]; for (long long i = n - 2; i > 0; i--) { ans = ans + a[i]; x++; if (x + 2 == n) break; ans = ans + a[i]; x++; if (x + 2 == n) break; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; long long n, a[200010], ans, x; int main() { cin >> n; for (long long i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); ans += a[n - 1]; for (long long i = n - 2; i > 0; i--) { ans = ans + a[i]; x++; if (x + 2 == n) break; ans = ans + a[i]; x++; if (x + 2 == n) break; } cout << ans << endl; return 0; }
replace
2
3
2
3
0
p02615
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n; cin >> n; ll a[n], i; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); ll ans = a[n - 1], k = n - 2, m = 0; for (i = n - 3; i >= 0; i--) { if (m < 2) { ans += a[k]; m++; } else { ans += a[++k]; m = 1; } } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n; cin >> n; ll a[n], i; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); ll ans = a[n - 1], k = n - 2, m = 0; for (i = n - 3; i >= 0; i--) { if (m < 2) { ans += a[k]; m++; } else { ans += a[--k]; m = 1; } } cout << ans; return 0; }
replace
17
18
17
18
0
p02615
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n; cin >> n; vector<int> a(n); vector<int> b(n, 2); b[0] = 1; rep(i, n) cin >> a[i]; sort(a.begin(), a.end(), greater<int>()); if (n == 2) { cout << a[0] << endl; return 0; } ll ans = 0; rep(i, n - 1) rep(j, n) { if (b[j] > 0) { ans += a[j]; b[j]--; break; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; ++i) using namespace std; using ll = long long; using P = pair<int, int>; int main() { int n; cin >> n; vector<int> a(n); vector<int> b(n, 2); b[0] = 1; rep(i, n) cin >> a[i]; sort(a.begin(), a.end(), greater<int>()); if (n == 2) { cout << a[0] << endl; return 0; } ll ans = 0; int c = 0; rep(i, n - 1) { ans += a[c]; b[c]--; if (b[c] <= 0) c++; } cout << ans << endl; return 0; }
replace
22
28
22
28
TLE
p02615
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define N 100010 using namespace std; ll ans; int n; int a[N]; bool cmp(int a, int b) { return a > b; } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1, cmp); int hal = n / 2; ans += a[1]; for (int i = 2; i <= hal; i++) { ans += (long long)a[i]; ans += (long long)a[i]; } if (n % 2 == 1) ans += (long long)a[hal + 1]; cout << ans; return 0; }
#include <bits/stdc++.h> #define ll long long #define N 200010 using namespace std; ll ans; int n; int a[N]; bool cmp(int a, int b) { return a > b; } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + n + 1, cmp); int hal = n / 2; ans += a[1]; for (int i = 2; i <= hal; i++) { ans += (long long)a[i]; ans += (long long)a[i]; } if (n % 2 == 1) ans += (long long)a[hal + 1]; cout << ans; return 0; }
replace
2
3
2
3
0
p02615
C++
Runtime Error
#include <cstdio> #include <queue> using namespace std; int n, a[100010], max; long long sum; priority_queue<int> s1; priority_queue<pair<int, pair<int, int>>> s2; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", a + i); s1.push(a[i]); } s2.push(make_pair(s1.top(), make_pair(s1.top(), s1.top()))); s1.pop(); for (int i = 2; i <= n; ++i) { int x = s1.top(); s1.pop(); sum += s2.top().first; pair<int, pair<int, int>> k; k = s2.top(); s2.pop(); s2.push(make_pair(x, make_pair(k.second.first, x))); s2.push(make_pair(x, make_pair(k.second.second, x))); } printf("%lld\n", sum); return 0; }
#include <cstdio> #include <queue> using namespace std; int n, a[200010], max; long long sum; priority_queue<int> s1; priority_queue<pair<int, pair<int, int>>> s2; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", a + i); s1.push(a[i]); } s2.push(make_pair(s1.top(), make_pair(s1.top(), s1.top()))); s1.pop(); for (int i = 2; i <= n; ++i) { int x = s1.top(); s1.pop(); sum += s2.top().first; pair<int, pair<int, int>> k; k = s2.top(); s2.pop(); s2.push(make_pair(x, make_pair(k.second.first, x))); s2.push(make_pair(x, make_pair(k.second.second, x))); } printf("%lld\n", sum); return 0; }
replace
3
4
3
4
0
p02615
C++
Runtime Error
#include <algorithm> #include <algorithm> //sort,二分探索,など #include <bitset> //固定長bit集合 #include <cmath> //pow,logなど #include <complex> //複素数 #include <deque> //両端アクセスのキュー #include <functional> //sortのgreater #include <iomanip> //setprecision(浮動小数点の出力の誤差) #include <iostream> //入出力 #include <iterator> //集合演算(積集合,和集合,差集合など) #include <map> //map(辞書) #include <numeric> //iota(整数列の生成),gcdとlcm(c++17) #include <queue> //キュー #include <set> //集合 #include <stack> //スタック #include <string> //文字列 #include <unordered_map> //イテレータあるけど順序保持しないmap #include <unordered_set> //イテレータあるけど順序保持しないset #include <utility> //pair #include <vector> //可変長配列 using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<vector<int>> vvi; typedef vector<vector<ll>> vvll; typedef vector<vector<string>> vvs; typedef vector<vector<bool>> vvb; const ll MOD = 1000000007; const ll INF = 1000000000000000000; #define rep(i, n) for (int i = 0; i < n; i++) #define repl(i, s, e) for (int i = s; i < e; i++) #define reple(i, s, e) for (int i = s; i <= e; i++) #define revrep(i, n) for (int i = n - 1; i >= 0; i--) #define all(x) (x).begin(), (x).end() 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; } vll A; class aida { public: int left; int right; ll score; aida(int l, int r) { this->left = l; this->right = r; score = min(A[l], A[r]); }; }; bool operator<(const aida &lhs, const aida &rhs) { return lhs.score < rhs.score; }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; A.resize(N); rep(i, N) cin >> A[i]; sort(all(A), greater<ll>()); ll ans = 0; priority_queue<aida> q; q.emplace(0, 1); ans += A[0]; repl(i, 2, N) { auto a = q.top(); if (q.size() > 1) q.pop(); ans += min(A[a.left], A[a.right]); q.emplace(a.left, A[i]); q.emplace(A[i], a.right); } cout << ans << endl; return 0; }
#include <algorithm> #include <algorithm> //sort,二分探索,など #include <bitset> //固定長bit集合 #include <cmath> //pow,logなど #include <complex> //複素数 #include <deque> //両端アクセスのキュー #include <functional> //sortのgreater #include <iomanip> //setprecision(浮動小数点の出力の誤差) #include <iostream> //入出力 #include <iterator> //集合演算(積集合,和集合,差集合など) #include <map> //map(辞書) #include <numeric> //iota(整数列の生成),gcdとlcm(c++17) #include <queue> //キュー #include <set> //集合 #include <stack> //スタック #include <string> //文字列 #include <unordered_map> //イテレータあるけど順序保持しないmap #include <unordered_set> //イテレータあるけど順序保持しないset #include <utility> //pair #include <vector> //可変長配列 using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<vector<int>> vvi; typedef vector<vector<ll>> vvll; typedef vector<vector<string>> vvs; typedef vector<vector<bool>> vvb; const ll MOD = 1000000007; const ll INF = 1000000000000000000; #define rep(i, n) for (int i = 0; i < n; i++) #define repl(i, s, e) for (int i = s; i < e; i++) #define reple(i, s, e) for (int i = s; i <= e; i++) #define revrep(i, n) for (int i = n - 1; i >= 0; i--) #define all(x) (x).begin(), (x).end() 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; } vll A; class aida { public: int left; int right; ll score; aida(int l, int r) { this->left = l; this->right = r; score = min(A[l], A[r]); }; }; bool operator<(const aida &lhs, const aida &rhs) { return lhs.score < rhs.score; }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; A.resize(N); rep(i, N) cin >> A[i]; sort(all(A), greater<ll>()); ll ans = 0; priority_queue<aida> q; q.emplace(0, 1); ans += A[0]; repl(i, 2, N) { auto a = q.top(); if (q.size() > 1) q.pop(); ans += min(A[a.left], A[a.right]); q.emplace(a.left, i); q.emplace(i, a.right); } cout << ans << endl; return 0; }
replace
100
102
100
102
0
p02615
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> using namespace std; #define int long long #define double long double #define endl "\n" #define pb push_back #define PI 3.1415926535897932384626433832795l #define F first #define S second #define mp make_pair #define f(i, n) for (int i = 0; i < n; i++) #define fastio \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define gcd(a, b) __gcd((a), (b)) #define fill(a, value) memset(a, value, sizeof(a)); #define minn(v) *min_element(v.begin(), v.end()); #define maxx(v) *max_element(v.begin(), v.end()); #define print(x) cout << (x) << endl; #define sum(v) +x accumulate(v.begin(), v.end(), x); typedef pair<int, int> pii; typedef vector<int> vi; /* max and min value in a set max_element = *(my_set.rbegin()); min_element = *my_set.begin(); */ // x.substr(start, length); /* Create a vector containing n vectors of size m. ---vector<vector<int> > vec( n , vector<int> (m, 0)); */ /*left shifting an integer “x” with an integer “y” (x<<y) is equivalent to multiplying x with 2^y (2 raise to power y).*/ /*Similarly right shifting (x>>y) is equivalent to dividing x with 2^y. */ struct type { int k, i, j; }; // to check if a no is prime or not? bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } // minimum subaaray sum of size k-sliding window approach int findSubarray(int arr[], int n, int k) { int window_sum = 0; int min_window = INT_MAX; int last = 0; for (int i = 0; i < n; i++) { window_sum += arr[i]; if (i + 1 >= k) { if (min_window > window_sum) { min_window = window_sum; last = i; } window_sum -= arr[i + 1 - k]; } } int sum = 0; for (int i = last - k + 1; i <= last; i++) { sum += arr[i]; } return sum; } // finds the next permutation to given sequence of nos int nextpermutation(vi v) { vi t = v; sort(all(t)); int x = 0; while (true) { x++; if (t == v) { return x; } next_permutation(all(t)); } } vector<int> factors(int n) { // Note that this loop runs till square root vi ans; for (int i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (n == i * i) ans.pb(i); else { ans.pb(i); if (i != n / i) ans.pb(n / i); } } } sort(all(ans)); return ans; } // Recursive C++ program to check if a string is subsequence of another string bool isSubSequence(char str1[], char str2[], int m, int n) { // Base Cases if (m == 0) return true; if (n == 0) return false; // If last characters of two strings are matching if (str1[m - 1] == str2[n - 1]) return isSubSequence(str1, str2, m - 1, n - 1); // If last characters are not matching return isSubSequence(str1, str2, m, n - 1); } void findDivisors(int n) { int div[n + 1]; memset(div, 0, sizeof div); for (int i = 1; i <= n; i++) { for (int j = 1; j * i <= n; j++) div[i * j]++; } int ans = 0; for (int i = 1; i <= n; i++) ans += i * div[i]; cout << ans << endl; } int digits(int n) { int res = 0; while (n > 0) { res += n % 10; n /= 10; } return (res); } int power(int x, int y, int p) { int res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p while (y > 0) { // If y is odd, multiply x with result if (y & 1) res = (res * x) % p; // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } // Returns n^(-1) mod p int modInverse(int n, int p) { return power(n, p - 2, p); } // Returns nCr % p using Fermat's little // theorem. int nCr(int n, int r, int p) { // Base case if (r == 0) return 1; int fac[n + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p; return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } double dist(int x1, int y1, int x2, int y2) { double a = (x1 - x2) * (x1 - x2); double b = (y1 - y2) * (y1 - y2); return sqrt(a + b); } signed main() { fastio; cout << fixed << setprecision(12); int n; cin >> n; vi a(n); f(i, n) cin >> a[i]; sort(rall(a)); int ans = 0; ans += a[0]; ans += a[1]; int x = n - 3; int i = 1; while (x--) { ans += a[i]; i++; } print(ans) return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; #define int long long #define double long double #define endl "\n" #define pb push_back #define PI 3.1415926535897932384626433832795l #define F first #define S second #define mp make_pair #define f(i, n) for (int i = 0; i < n; i++) #define fastio \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define gcd(a, b) __gcd((a), (b)) #define fill(a, value) memset(a, value, sizeof(a)); #define minn(v) *min_element(v.begin(), v.end()); #define maxx(v) *max_element(v.begin(), v.end()); #define print(x) cout << (x) << endl; #define sum(v) +x accumulate(v.begin(), v.end(), x); typedef pair<int, int> pii; typedef vector<int> vi; /* max and min value in a set max_element = *(my_set.rbegin()); min_element = *my_set.begin(); */ // x.substr(start, length); /* Create a vector containing n vectors of size m. ---vector<vector<int> > vec( n , vector<int> (m, 0)); */ /*left shifting an integer “x” with an integer “y” (x<<y) is equivalent to multiplying x with 2^y (2 raise to power y).*/ /*Similarly right shifting (x>>y) is equivalent to dividing x with 2^y. */ struct type { int k, i, j; }; // to check if a no is prime or not? bool isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } // minimum subaaray sum of size k-sliding window approach int findSubarray(int arr[], int n, int k) { int window_sum = 0; int min_window = INT_MAX; int last = 0; for (int i = 0; i < n; i++) { window_sum += arr[i]; if (i + 1 >= k) { if (min_window > window_sum) { min_window = window_sum; last = i; } window_sum -= arr[i + 1 - k]; } } int sum = 0; for (int i = last - k + 1; i <= last; i++) { sum += arr[i]; } return sum; } // finds the next permutation to given sequence of nos int nextpermutation(vi v) { vi t = v; sort(all(t)); int x = 0; while (true) { x++; if (t == v) { return x; } next_permutation(all(t)); } } vector<int> factors(int n) { // Note that this loop runs till square root vi ans; for (int i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (n == i * i) ans.pb(i); else { ans.pb(i); if (i != n / i) ans.pb(n / i); } } } sort(all(ans)); return ans; } // Recursive C++ program to check if a string is subsequence of another string bool isSubSequence(char str1[], char str2[], int m, int n) { // Base Cases if (m == 0) return true; if (n == 0) return false; // If last characters of two strings are matching if (str1[m - 1] == str2[n - 1]) return isSubSequence(str1, str2, m - 1, n - 1); // If last characters are not matching return isSubSequence(str1, str2, m, n - 1); } void findDivisors(int n) { int div[n + 1]; memset(div, 0, sizeof div); for (int i = 1; i <= n; i++) { for (int j = 1; j * i <= n; j++) div[i * j]++; } int ans = 0; for (int i = 1; i <= n; i++) ans += i * div[i]; cout << ans << endl; } int digits(int n) { int res = 0; while (n > 0) { res += n % 10; n /= 10; } return (res); } int power(int x, int y, int p) { int res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p while (y > 0) { // If y is odd, multiply x with result if (y & 1) res = (res * x) % p; // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } // Returns n^(-1) mod p int modInverse(int n, int p) { return power(n, p - 2, p); } // Returns nCr % p using Fermat's little // theorem. int nCr(int n, int r, int p) { // Base case if (r == 0) return 1; int fac[n + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p; return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } double dist(int x1, int y1, int x2, int y2) { double a = (x1 - x2) * (x1 - x2); double b = (y1 - y2) * (y1 - y2); return sqrt(a + b); } signed main() { fastio; cout << fixed << setprecision(12); int n; cin >> n; vi a(n); f(i, n) cin >> a[i]; sort(rall(a)); int ans = 0; ans += a[0]; int x = 1; int y = 0; for (int i = 2; i < n; i++) { if (y == 2) { x += 1; y = 0; } ans += a[x]; y += 1; } print(ans) return 0; }
replace
202
208
202
211
0
p02615
C++
Runtime Error
#pragma comment(linker, "/STACK:1024000000,1024000000") #include <algorithm> #include <cctype> #include <cmath> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; #define ms(s) memset(s, 0, sizeof(s)) #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i <= (n); i++) const int inf = 0x3f3f3f3f; const int MAXN = 1e5 + 10; #define LOCAL int a[MAXN]; int main() { ios::sync_with_stdio(false); cout.tie(0), cin.tie(0); int t; cin >> t; rep(i, t) { cin >> a[i]; } sort(a, a + t, greater<int>()); std::vector<int> v; v.push_back(a[0]); for (int i = 1; i < t; i++) { v.push_back(a[i]); v.push_back(a[i]); } ll ans = 0; rep(i, t - 1) { ans += v[i]; } cout << ans << endl; return 0; }
#pragma comment(linker, "/STACK:1024000000,1024000000") #include <algorithm> #include <cctype> #include <cmath> #include <cstdlib> #include <cstring> #include <ctime> #include <fstream> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> using namespace std; typedef long long ll; typedef unsigned long long ull; #define ms(s) memset(s, 0, sizeof(s)) #define rep(i, n) for (int i = 0; i < (n); i++) #define rep1(i, n) for (int i = 1; i <= (n); i++) const int inf = 0x3f3f3f3f; const int MAXN = 2e5 + 10; #define LOCAL int a[MAXN]; int main() { ios::sync_with_stdio(false); cout.tie(0), cin.tie(0); int t; cin >> t; rep(i, t) { cin >> a[i]; } sort(a, a + t, greater<int>()); std::vector<int> v; v.push_back(a[0]); for (int i = 1; i < t; i++) { v.push_back(a[i]); v.push_back(a[i]); } ll ans = 0; rep(i, t - 1) { ans += v[i]; } cout << ans << endl; return 0; }
replace
26
27
26
27
0
p02615
C++
Runtime Error
#pragma GCC optimize("O3") #include <bits/stdc++.h> typedef long long ll; using namespace std; template <class TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << '=' << h << endl; } template <class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while (*sdbg != ',') cerr << *sdbg++; cerr << '=' << h << ','; _dbg(sdbg + 1, a...); } #ifdef LOCAL #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #else #define debug(...) 42 #endif typedef long long ll; const int maxn = 1e5 + 100; int a[maxn]; int cmp(int x, int y) { return x > y; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; sort(a, a + n, cmp); // for (int i = 0; i < n; ++i) // cout << a[i] << " "; cout << endl; int i = 0, now = 1; int t = 0; ll res = 0; while (t < n - 1) { res += a[i]; now = (now + 1) % 2; if (now == 0) i++; t++; } cout << res << endl; return 0; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> typedef long long ll; using namespace std; template <class TH> void _dbg(const char *sdbg, TH h) { cerr << sdbg << '=' << h << endl; } template <class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) { while (*sdbg != ',') cerr << *sdbg++; cerr << '=' << h << ','; _dbg(sdbg + 1, a...); } #ifdef LOCAL #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__) #else #define debug(...) 42 #endif typedef long long ll; const int maxn = 2e5 + 100; int a[maxn]; int cmp(int x, int y) { return x > y; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; for (int i = 0; i < n; ++i) cin >> a[i]; sort(a, a + n, cmp); // for (int i = 0; i < n; ++i) // cout << a[i] << " "; cout << endl; int i = 0, now = 1; int t = 0; ll res = 0; while (t < n - 1) { res += a[i]; now = (now + 1) % 2; if (now == 0) i++; t++; } cout << res << endl; return 0; }
replace
22
23
22
23
0
p02615
C++
Runtime Error
/* Author: topcoderme123 Date: 5th july */ #include <bits/stdc++.h> #define ll long long #define pb push_back #define mod 1000000007 #define F first #define S second #define all(v) (v).begin(), (v).end() #define np next_permutation using namespace std; using vi = vector<int>; #define lp(i, n) for (int i = 0; i < n; i++) #define lps(i, j, n) for (int i = j; i < n; i++) #define vii vector<vi> #define vb vector<bool> #define pr pair<int, int> #define vl vector<ll> #define vs vector<string> #define us unordered_map<int, int> #define Mpq priority_queue<int> #define mpq priority_queue<int, vi, greater<int>> #define eb emplace_back #define prl pair<ll, ll> #define vp vector<pr> #define inf 1000000000000000008 #define ld long double const ll N = 2e5 + 23; ll n, sum, j; ll a[N], dp[N + 6]; void solve() { cin >> n; lp(i, n) cin >> a[i], dp[a[i]] = 1; sort(a, a + n, greater<int>()); lps(i, 1, n) { if (i == 1) sum += a[j++], dp[a[i]] <<= 1; else { sum += a[j]; if (dp[a[i]] != N) dp[a[i]] = min(N, dp[a[i]] * 2); dp[a[j]]--; while (!dp[a[j]] and j < n) j++; } } cout << sum << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); // assert(freopen("input.txt", "r", stdin)); // assert(freopen("output.txt", "w", stdout)); solve(); return 0; }
/* Author: topcoderme123 Date: 5th july */ #include <bits/stdc++.h> #define ll long long #define pb push_back #define mod 1000000007 #define F first #define S second #define all(v) (v).begin(), (v).end() #define np next_permutation using namespace std; using vi = vector<int>; #define lp(i, n) for (int i = 0; i < n; i++) #define lps(i, j, n) for (int i = j; i < n; i++) #define vii vector<vi> #define vb vector<bool> #define pr pair<int, int> #define vl vector<ll> #define vs vector<string> #define us unordered_map<int, int> #define Mpq priority_queue<int> #define mpq priority_queue<int, vi, greater<int>> #define eb emplace_back #define prl pair<ll, ll> #define vp vector<pr> #define inf 1000000000000000008 #define ld long double const ll N = 2e5 + 23; ll n, sum, j; ll a[N]; unordered_map<ll, ll> dp; void solve() { cin >> n; lp(i, n) cin >> a[i], dp[a[i]] = 1; sort(a, a + n, greater<int>()); lps(i, 1, n) { if (i == 1) sum += a[j++], dp[a[i]] <<= 1; else { sum += a[j]; if (dp[a[i]] != N) dp[a[i]] = min(N, dp[a[i]] * 2); dp[a[j]]--; while (!dp[a[j]] and j < n) j++; } } cout << sum << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(nullptr); // assert(freopen("input.txt", "r", stdin)); // assert(freopen("output.txt", "w", stdout)); solve(); return 0; }
replace
33
34
33
35
0
p02615
C++
Runtime Error
#include <algorithm> #include <functional> #include <stdio.h> using namespace std; int main() { int n, A[100000]; scanf("%i", &n); for (int i = 0; i < n; i++) { scanf("%i", A + i); } sort(A, A + n, greater<int>()); long long ans = A[0]; n -= 2; for (int i = 1; n; i++) { if (n == 1) { ans += A[i]; n = 0; } else { ans += A[i] << 1ll; n -= 2; } } printf("%lli", ans); }
#include <algorithm> #include <functional> #include <stdio.h> using namespace std; int main() { int n, A[200000]; scanf("%i", &n); for (int i = 0; i < n; i++) { scanf("%i", A + i); } sort(A, A + n, greater<int>()); long long ans = A[0]; n -= 2; for (int i = 1; n; i++) { if (n == 1) { ans += A[i]; n = 0; } else { ans += A[i] << 1ll; n -= 2; } } printf("%lli", ans); }
replace
5
6
5
6
0
p02615
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double int t, n, a[100005], ans, pnt, tmp; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); t = 1; // cin>>t; while (t--) { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); ans = a[n - 1]; pnt = n - 2; tmp = n - 2; while (1) { if (tmp == 0) break; tmp--; ans += a[pnt]; if (tmp == 0) break; ans += a[pnt--]; tmp--; } cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; #define int long long #define double long double int t, n, a[200005], ans, pnt, tmp; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); t = 1; // cin>>t; while (t--) { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); ans = a[n - 1]; pnt = n - 2; tmp = n - 2; while (1) { if (tmp == 0) break; tmp--; ans += a[pnt]; if (tmp == 0) break; ans += a[pnt--]; tmp--; } cout << ans << endl; } }
replace
4
5
4
5
0
p02615
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <ctime> #include <iostream> #include <random> #include <vector> using namespace std; using ll = long long int; using P = pair<int, int>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) ll mod = 1000000007; vector<ll> dp(200010); int main() { int n; cin >> n; vector<ll> a(n + 1); rep(i, n) cin >> a[i]; sort(a.begin(), a.end(), greater<int>()); rep(i, n) dp[i] = a[i]; ll ans = dp[0]; for (int i = 1; i < (n - 1); i++) { int num = i + n / 2 + n % 2 - 1; ans += dp[i]; dp[num] = dp[i]; } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cmath> #include <ctime> #include <iostream> #include <random> #include <vector> using namespace std; using ll = long long int; using P = pair<int, int>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) ll mod = 1000000007; vector<ll> dp(400010); int main() { int n; cin >> n; vector<ll> a(n + 1); rep(i, n) cin >> a[i]; sort(a.begin(), a.end(), greater<int>()); rep(i, n) dp[i] = a[i]; ll ans = dp[0]; for (int i = 1; i < (n - 1); i++) { int num = i + n / 2 + n % 2 - 1; ans += dp[i]; dp[num] = dp[i]; } cout << ans << endl; }
replace
13
14
13
14
0
p02615
C++
Runtime Error
// author: hitch_hiker42; #include "bits/stdc++.h" using namespace std; // solution: #define int int64_t #define span(a) begin(a), end(a) void hike() { int n; cin >> n; vector<int> a(n); for (int &i : a) cin >> i; sort(span(a), greater<int>()); int cost = a.front(), j = 1; for (int i = n - 2; ~i; i -= 2, ++j) { cost += a[j] << 1; } if (n % 2 == 0) cout << cost << "\n"; else cout << cost - a[j - 1] << "\n"; } signed main() { int t = 1; // cin >> t; while (t--) hike(); return 0; } // farewell, until we meet again..
// author: hitch_hiker42; #include "bits/stdc++.h" using namespace std; // solution: #define int int64_t #define span(a) begin(a), end(a) void hike() { int n; cin >> n; vector<int> a(n); for (int &i : a) cin >> i; sort(span(a), greater<int>()); int cost = a.front(), j = 1; for (int i = n - 2; i > 0; i -= 2, ++j) { cost += a[j] << 1; } if (n % 2 == 0) cout << cost << "\n"; else cout << cost - a[j - 1] << "\n"; } signed main() { int t = 1; // cin >> t; while (t--) hike(); return 0; } // farewell, until we meet again..
replace
16
17
16
17
-11
p02615
C++
Runtime Error
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <climits> #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <deque> // deque #include <functional> #include <iomanip> //setprecision #include <iostream> #include <map> // map #include <math.h> #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <string> // string, to_string, stoi #include <tuple> // tuple, make_tuple #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <utility> // pair, make_pair #include <vector> // vector using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) #define mod 1000000007 vector<ll> to[1000005]; int main() { ll a, b = 0; cin >> a; vector<ll> c(a * 2 - 1), d(a); rep(i, a) cin >> d[i]; sort(d.begin(), d.end()); reverse(d.begin(), d.end()); c[0] = d[0]; for (ll i = 1; i < a * 2 - 1; i++) { c[i] = d[i]; i++; c[i] = d[i / 2]; } rep(i, a - 1) { b += c[i]; } cout << b; }
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <bitset> // bitset #include <cctype> // isupper, islower, isdigit, toupper, tolower #include <climits> #include <cstdint> // int64_t, int*_t #include <cstdio> // printf #include <deque> // deque #include <functional> #include <iomanip> //setprecision #include <iostream> #include <map> // map #include <math.h> #include <queue> // queue, priority_queue #include <set> // set #include <stack> // stack #include <string> // string, to_string, stoi #include <tuple> // tuple, make_tuple #include <unordered_map> // unordered_map #include <unordered_set> // unordered_set #include <utility> // pair, make_pair #include <vector> // vector using namespace std; #define ll long long #define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) #define mod 1000000007 vector<ll> to[1000005]; int main() { ll a, b = 0; cin >> a; vector<ll> c(a * 2 - 1), d(a); rep(i, a) cin >> d[i]; sort(d.begin(), d.end()); reverse(d.begin(), d.end()); c[0] = d[0]; for (ll i = 1; i < a * 2 - 1; i++) { c[i] = d[i / 2 + 1]; i++; c[i] = d[i / 2]; } rep(i, a - 1) { b += c[i]; } cout << b; }
replace
35
36
35
36
0
p02615
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; long long a[100010], ans = 0; int main() { int i, n; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); long long num = n - 1; ans += a[n - 1]; num--; for (i = n - 2; i >= 0; i--) { ans += min(2LL, num) * a[i]; num -= min(2LL, num); } cout << ans << endl; }
#include <algorithm> #include <iostream> using namespace std; long long a[200010], ans = 0; int main() { int i, n; cin >> n; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); long long num = n - 1; ans += a[n - 1]; num--; for (i = n - 2; i >= 0; i--) { ans += min(2LL, num) * a[i]; num -= min(2LL, num); } cout << ans << endl; }
replace
3
4
3
4
0
p02615
C++
Runtime Error
// ABHISHEK AGRAWAL// // Newbie......You have to be odd to be no. ONE :)// #include <bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define fl float #define lcm(a, b) (a * (b / __gcd(a, b))) #define vs vector<string> #define vc vector<char> #define vll vector<ll> #define sll set<ll> #define pll pair<ll, ll> #define plc pair<ll, char> #define tlll tuple<ll, ll, ll> #define mt make_tuple #define vpll vector<pair<ll, ll>> #define vtll vector<tuple<ll, ll, ll>> #define vvll vector<vector<ll>> #define lb lower_bound #define pb push_back #define pob pop_back #define f first #define s second #define mll map<ll, ll> #define mp make_pair #define sp(n) fixed << setprecision(n) #define mcl map<char, ll> #define msl map<string, ll> #define mod (ll)1000000007 #define flash \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define test \ ll t; \ read(t); \ while (t--) #define sortv(v) sort(v.begin(), v.end()) #define INF (ll)(1e15) #define loop(i, n) for (ll i = 0; i < n; i++) #define loop1(i, n) for (ll i = 1; i <= n; i++) #define rloop(n, i) for (ll i = n - 1; i >= 0; i--) #define loopab(i, a, b, c) for (ll i = a; i <= b; i += c) #define reada(a, n) loop(i, n) cin >> a[i]; #define reada1(a, n) loop1(i, n) cin >> a[i]; #define sorta(a) sort(a, a + n, greater<ll>()) #define countone(n) __builtin_popcount(n) #define numoftrailzero(n) __builtin_ctz(n) #define maxpowoftwo(n) __builtin_clz(n) #define leastindexwithone(n) __builtin_ffs(n) #define what_is(x) cerr << #x << " is " << x << endl; #define pfv(v) \ cout << v.size() << "\n"; \ loop(i, v.size()) cout << v[i] << " "; #define pv(v) loop(i, v.size()) cout << v[i] << " "; #define all(v) v.begin(), v.end() // if we need to devide any given number in powers of term the power of max term #define answer(n) ceil(log2(n + 1)) ll n, q, ans, sum; ll gcd(ll a, ll b) { if (b == 0) { return a; } return gcd(b, a % b); } ll powe(ll a, ll b) { ll res = 1; while (b > 0) { if (b % 2 == 1) { res = (res * a); } a = (a * a); b /= 2; } return res; } ll power(ll a, ll b, ll M) { a %= M; ll res = 1; while (b > 0) { if (b % 2 == 1) { res = (res * a) % M; } a = (a * a) % M; b /= 2; } return res; } ll extendedEuclid(ll A, ll B, ll &x, ll &y) { if (B == 0) { x = 1; y = 0; return A; } else { ll x1, y1; ll gcd = extendedEuclid(B, A % B, x1, y1); y = x1 - (A / B) * y1; x = y1; return gcd; } } ll mi(ll A, ll M) { ll x, y; extendedEuclid(A, M, x, y); if (x < 0) { x += mod; } return x; } vector<bool> sieve(1000000, true); void Sieve() { sieve[0] = false; sieve[1] = false; for (ll i = 2; i * i <= 1000000; i++) { if (sieve[i] == true) { for (ll j = i * i; j < 1000000; j += i) sieve[j] = false; } } } vll sieve_spf; void Sieve_spf() { const ll n = 1e6 + 5; sieve_spf.resize(n); loop(i, n) sieve_spf[i] = i; sieve_spf[0] = -1; sieve_spf[1] = 1; loopab(i, 2, n, 2) sieve_spf[i] = 2; loopab(i, 3, n, 2) if (sieve_spf[i] == i) loopab(j, i * i, n, i) if (sieve_spf[j] == j) sieve_spf[j] = i; } #ifdef TESTING #define DEBUG fprintf(stderr, "====TESTING====\n") #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl #define debug(...) fprintf(stderr, __VA_ARGS__) #else #define DEBUG #define VALUE(x) #define debug(...) #endif void the_happiest_place_on_earth() { flash; #ifdef ENABLE_FILE_IO freopen("in", "r", stdin); freopen("out", "w", stdout); #endif } const int N = 37; ll a[N], b[N], dp[N][N], m[N][N], dsr[N][N], dsl[N][N]; void solve() { cin >> n; sum = 0; loop(i, n) cin >> a[i]; sort(a, a + n, greater<ll>()); ll cnt = 0; loop(i, n) { if (i == 0) { sum += a[i]; cnt++; if (cnt >= n - 1) break; } else { sum += a[i]; cnt++; if (cnt >= n - 1) break; sum += a[i]; cnt++; if (cnt >= n - 1) break; } } cout << sum << " "; // cout<<sum; return; } int main() { the_happiest_place_on_earth(); // Today's thought: Push yourself, because no one else is going to do it for // you. Things aren’t always #000000 and #FFFFFF START OF PROGRAM LOGIC q = 1; // cin>>q;; while (q--) { solve(); } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; // END OF PROGRAM LOGIC return 0; } /* ###### ###### # # ####### # # ##### # # # ####### ####### ###### # # # ## # # # ## ## # ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ##### # # # # # # # # # # # # # # # # # ###### # # # # # # # # # # # # # # ####### # # # # # # # # # ## # # # # # # ## # # # # # # # ###### ###### # # ####### # # ##### # # # # # ####### # # */
// ABHISHEK AGRAWAL// // Newbie......You have to be odd to be no. ONE :)// #include <bits/stdc++.h> using namespace std; #define ll long long int #define ld long double #define fl float #define lcm(a, b) (a * (b / __gcd(a, b))) #define vs vector<string> #define vc vector<char> #define vll vector<ll> #define sll set<ll> #define pll pair<ll, ll> #define plc pair<ll, char> #define tlll tuple<ll, ll, ll> #define mt make_tuple #define vpll vector<pair<ll, ll>> #define vtll vector<tuple<ll, ll, ll>> #define vvll vector<vector<ll>> #define lb lower_bound #define pb push_back #define pob pop_back #define f first #define s second #define mll map<ll, ll> #define mp make_pair #define sp(n) fixed << setprecision(n) #define mcl map<char, ll> #define msl map<string, ll> #define mod (ll)1000000007 #define flash \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define test \ ll t; \ read(t); \ while (t--) #define sortv(v) sort(v.begin(), v.end()) #define INF (ll)(1e15) #define loop(i, n) for (ll i = 0; i < n; i++) #define loop1(i, n) for (ll i = 1; i <= n; i++) #define rloop(n, i) for (ll i = n - 1; i >= 0; i--) #define loopab(i, a, b, c) for (ll i = a; i <= b; i += c) #define reada(a, n) loop(i, n) cin >> a[i]; #define reada1(a, n) loop1(i, n) cin >> a[i]; #define sorta(a) sort(a, a + n, greater<ll>()) #define countone(n) __builtin_popcount(n) #define numoftrailzero(n) __builtin_ctz(n) #define maxpowoftwo(n) __builtin_clz(n) #define leastindexwithone(n) __builtin_ffs(n) #define what_is(x) cerr << #x << " is " << x << endl; #define pfv(v) \ cout << v.size() << "\n"; \ loop(i, v.size()) cout << v[i] << " "; #define pv(v) loop(i, v.size()) cout << v[i] << " "; #define all(v) v.begin(), v.end() // if we need to devide any given number in powers of term the power of max term #define answer(n) ceil(log2(n + 1)) ll n, q, ans, sum; ll gcd(ll a, ll b) { if (b == 0) { return a; } return gcd(b, a % b); } ll powe(ll a, ll b) { ll res = 1; while (b > 0) { if (b % 2 == 1) { res = (res * a); } a = (a * a); b /= 2; } return res; } ll power(ll a, ll b, ll M) { a %= M; ll res = 1; while (b > 0) { if (b % 2 == 1) { res = (res * a) % M; } a = (a * a) % M; b /= 2; } return res; } ll extendedEuclid(ll A, ll B, ll &x, ll &y) { if (B == 0) { x = 1; y = 0; return A; } else { ll x1, y1; ll gcd = extendedEuclid(B, A % B, x1, y1); y = x1 - (A / B) * y1; x = y1; return gcd; } } ll mi(ll A, ll M) { ll x, y; extendedEuclid(A, M, x, y); if (x < 0) { x += mod; } return x; } vector<bool> sieve(1000000, true); void Sieve() { sieve[0] = false; sieve[1] = false; for (ll i = 2; i * i <= 1000000; i++) { if (sieve[i] == true) { for (ll j = i * i; j < 1000000; j += i) sieve[j] = false; } } } vll sieve_spf; void Sieve_spf() { const ll n = 1e6 + 5; sieve_spf.resize(n); loop(i, n) sieve_spf[i] = i; sieve_spf[0] = -1; sieve_spf[1] = 1; loopab(i, 2, n, 2) sieve_spf[i] = 2; loopab(i, 3, n, 2) if (sieve_spf[i] == i) loopab(j, i * i, n, i) if (sieve_spf[j] == j) sieve_spf[j] = i; } #ifdef TESTING #define DEBUG fprintf(stderr, "====TESTING====\n") #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl #define debug(...) fprintf(stderr, __VA_ARGS__) #else #define DEBUG #define VALUE(x) #define debug(...) #endif void the_happiest_place_on_earth() { flash; #ifdef ENABLE_FILE_IO freopen("in", "r", stdin); freopen("out", "w", stdout); #endif } const int N = 200005; ll a[N], b[N]; void solve() { cin >> n; sum = 0; loop(i, n) cin >> a[i]; sort(a, a + n, greater<ll>()); ll cnt = 0; loop(i, n) { if (i == 0) { sum += a[i]; cnt++; if (cnt >= n - 1) break; } else { sum += a[i]; cnt++; if (cnt >= n - 1) break; sum += a[i]; cnt++; if (cnt >= n - 1) break; } } cout << sum << " "; // cout<<sum; return; } int main() { the_happiest_place_on_earth(); // Today's thought: Push yourself, because no one else is going to do it for // you. Things aren’t always #000000 and #FFFFFF START OF PROGRAM LOGIC q = 1; // cin>>q;; while (q--) { solve(); } cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"; // END OF PROGRAM LOGIC return 0; } /* ###### ###### # # ####### # # ##### # # # ####### ####### ###### # # # ## # # # ## ## # ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ##### # # # # # # # # # # # # # # # # # ###### # # # # # # # # # # # # # # ####### # # # # # # # # # ## # # # # # # ## # # # # # # # ###### ###### # # ####### # # ##### # # # # # ####### # # */
replace
152
154
152
154
0
Time : 23.665ms
p02616
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using int64 = long long; const int mod = 1e9 + 7; // const int mod = 998244353; const int64 infll = (1LL << 62) - 1; const int inf = (1 << 30) - 1; struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup; template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << p.first << " " << p.second; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); i++) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } template <typename T = int64> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } template <typename F> struct FixPoint : F { FixPoint(F &&f) : F(forward<F>(f)) {} template <typename... Args> decltype(auto) operator()(Args &&...args) const { return F::operator()(*this, forward<Args>(args)...); } }; template <typename F> inline decltype(auto) MFP(F &&f) { return FixPoint<F>{forward<F>(f)}; } template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int get_mod() { return mod; } }; using modint = ModInt<mod>; int main() { int N, K; cin >> N >> K; vector<int64> A(N); cin >> A; vector<pair<int64, bool>> x; for (auto &p : A) { if (p > 0) x.emplace_back(p, true); else if (p < 0) x.emplace_back(-p, false); else x.emplace_back(0, false); } sort(x.rbegin(), x.rend()); modint ret = 1; bool f = false; for (int i = 0; i < K; i++) { if (!x[i].second) f ^= 1; if (x[i].first == 0) f = false; ret *= x[i].first; } if (!f) { cout << ret << "\n"; return 0; } int last_pos = -1, last_pos2 = -1; for (int i = 0; i < K; i++) { if (!x[i].second) { // - last_pos = x[i].first; } else { // + last_pos2 = x[i].first; } } // tap: - を外して + を入れる // ris: + を外して - を入れる int64 tap = 0, ris = 0; for (int i = K; i < N; i++) { if (x[i].second) chmax(tap, x[i].first); // + else chmax(ris, x[i].first); // - } if (last_pos2 > 0 && ris > 0) { if (last_pos > 0 && tap > 0) { int64 u = last_pos2 - ris; int64 v = last_pos - tap; if (u < v) { ret /= last_pos2; ret *= ris; cout << ret << "\n"; } else { ret /= last_pos; ret *= tap; cout << ret << "\n"; assert(0); } } else { ret /= last_pos2; ret *= ris; cout << ret << "\n"; } } else { if (last_pos == 0 || tap == 0) { modint mul = 1; reverse(begin(x), end(x)); for (int i = 0; i < K; i++) { if (x[i].second) mul *= x[i].first; else mul *= -x[i].first; } cout << mul << "\n"; } else { ret /= last_pos; ret *= tap; cout << ret << "\n"; } } }
#include <bits/stdc++.h> using namespace std; using int64 = long long; const int mod = 1e9 + 7; // const int mod = 998244353; const int64 infll = (1LL << 62) - 1; const int inf = (1 << 30) - 1; struct IoSetup { IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup; template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << p.first << " " << p.second; return os; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); i++) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); } template <typename T = int64> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } template <typename F> struct FixPoint : F { FixPoint(F &&f) : F(forward<F>(f)) {} template <typename... Args> decltype(auto) operator()(Args &&...args) const { return F::operator()(*this, forward<Args>(args)...); } }; template <typename F> inline decltype(auto) MFP(F &&f) { return FixPoint<F>{forward<F>(f)}; } template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int get_mod() { return mod; } }; using modint = ModInt<mod>; int main() { int N, K; cin >> N >> K; vector<int64> A(N); cin >> A; vector<pair<int64, bool>> x; for (auto &p : A) { if (p > 0) x.emplace_back(p, true); else if (p < 0) x.emplace_back(-p, false); else x.emplace_back(0, false); } sort(x.rbegin(), x.rend()); modint ret = 1; bool f = false; for (int i = 0; i < K; i++) { if (!x[i].second) f ^= 1; if (x[i].first == 0) f = false; ret *= x[i].first; } if (!f) { cout << ret << "\n"; return 0; } int last_pos = -1, last_pos2 = -1; for (int i = 0; i < K; i++) { if (!x[i].second) { // - last_pos = x[i].first; } else { // + last_pos2 = x[i].first; } } // tap: - を外して + を入れる // ris: + を外して - を入れる int64 tap = 0, ris = 0; for (int i = K; i < N; i++) { if (x[i].second) chmax(tap, x[i].first); // + else chmax(ris, x[i].first); // - } if (last_pos2 > 0 && ris > 0) { if (last_pos > 0 && tap > 0) { int64 u = last_pos2 - ris; int64 v = last_pos - tap; if (u < v) { ret /= last_pos2; ret *= ris; cout << ret << "\n"; } else { random_device rng; if (rng() % 2) { ret /= last_pos2; ret *= ris; cout << ret << "\n"; } else { ret /= last_pos; ret *= tap; cout << ret << "\n"; } } } else { ret /= last_pos2; ret *= ris; cout << ret << "\n"; } } else { if (last_pos == 0 || tap == 0) { modint mul = 1; reverse(begin(x), end(x)); for (int i = 0; i < K; i++) { if (x[i].second) mul *= x[i].first; else mul *= -x[i].first; } cout << mul << "\n"; } else { ret /= last_pos; ret *= tap; cout << ret << "\n"; } } }
replace
220
224
220
230
0
p02616
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define double long double #pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math") #pragma GCC target("avx,avx2,sse") using namespace std; bool comp(int a, int b) { return abs(a) >= abs(b); } const int MOD = 1e9 + 7; const double EPS = 1e-9; bool can(int a, int b, int k) { if (b % 2) { b--; } if (k % 2) { return a + b >= k && a > 0; } else { return a + b >= k; } } int n, k; vector<int> arr; vector<double> pa; vector<double> pb; vector<int> ra; vector<int> rb; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; arr.resize(n); int a = 0; int b = 0; int z = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] > 0) { a++; } else if (arr[i] < 0) { b++; } else { z++; } } sort(arr.begin(), arr.end(), comp); if (can(a, b, k)) { pa.push_back(0); pb.push_back(0); ra.push_back(1); rb.push_back(1); for (int x : arr) { if (x > 0) { pa.push_back(pa.back() + log(x)); ra.push_back((ra.back() * x) % MOD); } else if (x < 0) { pb.push_back(pb.back() + log(-x)); rb.push_back((rb.back() * -x) % MOD); } } double fin = -1; int ans = INT_MIN; for (int i = 0; i <= k; i += 2) { if (i < pb.size() && k - i < pa.size()) { if (pb[i] + pa[k - i] > fin) { fin = pb[i] + pa[k - i]; ans = (rb[i] * ra[k - i]) % MOD; } } } cout << ans << '\n'; } else if (z > 0) { cout << 0 << '\n'; } else { int res = 1; for (int i = n - 1; i >= n - k; i--) { res = (((res * arr[i]) % MOD) + MOD) % MOD; } cout << res << '\n'; } fflush(stdout); return 0; }
#include <bits/stdc++.h> #define int long long #define double long double #pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math") #pragma GCC target("avx,avx2,sse") using namespace std; bool comp(int a, int b) { return abs(a) > abs(b); } const int MOD = 1e9 + 7; const double EPS = 1e-9; bool can(int a, int b, int k) { if (b % 2) { b--; } if (k % 2) { return a + b >= k && a > 0; } else { return a + b >= k; } } int n, k; vector<int> arr; vector<double> pa; vector<double> pb; vector<int> ra; vector<int> rb; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; arr.resize(n); int a = 0; int b = 0; int z = 0; for (int i = 0; i < n; i++) { cin >> arr[i]; if (arr[i] > 0) { a++; } else if (arr[i] < 0) { b++; } else { z++; } } sort(arr.begin(), arr.end(), comp); if (can(a, b, k)) { pa.push_back(0); pb.push_back(0); ra.push_back(1); rb.push_back(1); for (int x : arr) { if (x > 0) { pa.push_back(pa.back() + log(x)); ra.push_back((ra.back() * x) % MOD); } else if (x < 0) { pb.push_back(pb.back() + log(-x)); rb.push_back((rb.back() * -x) % MOD); } } double fin = -1; int ans = INT_MIN; for (int i = 0; i <= k; i += 2) { if (i < pb.size() && k - i < pa.size()) { if (pb[i] + pa[k - i] > fin) { fin = pb[i] + pa[k - i]; ans = (rb[i] * ra[k - i]) % MOD; } } } cout << ans << '\n'; } else if (z > 0) { cout << 0 << '\n'; } else { int res = 1; for (int i = n - 1; i >= n - k; i--) { res = (((res * arr[i]) % MOD) + MOD) % MOD; } cout << res << '\n'; } fflush(stdout); return 0; }
replace
7
8
7
8
0
p02616
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <climits> #include <cmath> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; int main(int argc, char **argv) { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(12); int n, K; cin >> n >> K; vector<long long> A(n); bool hasZero = false; for (int i = 0; i < n; ++i) { cin >> A[i]; hasZero = A[i] == 0; } sort(A.begin(), A.end()); const long long MOD = 1e9 + 7; if (n == K) { long long res = 1; for (auto x : A) { (res *= x) %= MOD; if (res < 0) { res += MOD; } } cout << res << '\n'; return 0; } vector<long long> negatives; vector<long long> nonNegatives; for (auto x : A) { if (x < 0) { negatives.push_back(x); } else { nonNegatives.push_back(x); } } if (negatives.size() == n) { long long res = 1; if (K % 2 == 1) { reverse(A.begin(), A.end()); } for (int i = 0; i < K; ++i) { (res *= A[i]) %= MOD; if (res < 0) { res += MOD; } } cout << res << '\n'; return 0; } if (K == n - 1) { long long res = 1; if (negatives.size() % 2 == 1) { for (int i = 0; i + 1 < negatives.size(); ++i) { (res *= negatives[i]) %= MOD; if (res < 0) { res += MOD; } } for (auto x : nonNegatives) { (res *= x) %= MOD; if (res < 0) { res += MOD; } } } else { reverse(nonNegatives.begin(), nonNegatives.end()); nonNegatives.pop_back(); for (auto x : negatives) { (res *= x) %= MOD; if (res < 0) { res += MOD; } } for (auto x : nonNegatives) { (res *= x) %= MOD; if (res < 0) { res += MOD; } } } cout << res << '\n'; return 0; } vector<long long> N; vector<long long> P; for (int i = 0; i + 1 < negatives.size(); i += 2) { long long x = negatives[i]; long long y = negatives[i + 1]; N.push_back(x * y); } long long res = 1; if (K % 2 == 1) { res = nonNegatives.back(); nonNegatives.pop_back(); --K; } for (int i = (int)nonNegatives.size() - 1; i > 0; i -= 2) { long long x = nonNegatives[i]; long long y = nonNegatives[i - 1]; P.push_back(x * y); } vector<long long> B; for (auto x : N) { B.push_back(x); } for (auto x : P) { B.push_back(x); } sort(B.begin(), B.end(), greater<long long>()); for (int i = 0; i < K; i += 2) { (B[i] %= MOD); if (B[i] < 0) { B[i] += MOD; } (res *= B[i]) %= MOD; } cout << res << '\n'; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <climits> #include <cmath> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; int main(int argc, char **argv) { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(12); int n, K; cin >> n >> K; vector<long long> A(n); bool hasZero = false; for (int i = 0; i < n; ++i) { cin >> A[i]; hasZero = A[i] == 0; } sort(A.begin(), A.end()); const long long MOD = 1e9 + 7; if (n == K) { long long res = 1; for (auto x : A) { (res *= x) %= MOD; if (res < 0) { res += MOD; } } cout << res << '\n'; return 0; } vector<long long> negatives; vector<long long> nonNegatives; for (auto x : A) { if (x < 0) { negatives.push_back(x); } else { nonNegatives.push_back(x); } } if (negatives.size() == n) { long long res = 1; if (K % 2 == 1) { reverse(A.begin(), A.end()); } for (int i = 0; i < K; ++i) { (res *= A[i]) %= MOD; if (res < 0) { res += MOD; } } cout << res << '\n'; return 0; } if (K == n - 1) { long long res = 1; if (negatives.size() % 2 == 1) { for (int i = 0; i + 1 < negatives.size(); ++i) { (res *= negatives[i]) %= MOD; if (res < 0) { res += MOD; } } for (auto x : nonNegatives) { (res *= x) %= MOD; if (res < 0) { res += MOD; } } } else { reverse(nonNegatives.begin(), nonNegatives.end()); nonNegatives.pop_back(); for (auto x : negatives) { (res *= x) %= MOD; if (res < 0) { res += MOD; } } for (auto x : nonNegatives) { (res *= x) %= MOD; if (res < 0) { res += MOD; } } } cout << res << '\n'; return 0; } vector<long long> N; vector<long long> P; for (int i = 0; i + 1 < negatives.size(); i += 2) { long long x = negatives[i]; long long y = negatives[i + 1]; N.push_back(x * y); } long long res = 1; if (K % 2 == 1) { res = nonNegatives.back(); nonNegatives.pop_back(); --K; } for (int i = (int)nonNegatives.size() - 1; i > 0; i -= 2) { long long x = nonNegatives[i]; long long y = nonNegatives[i - 1]; P.push_back(x * y); } vector<long long> B; for (auto x : N) { B.push_back(x); } for (auto x : P) { B.push_back(x); } sort(B.begin(), B.end(), greater<long long>()); for (int i = 0; K > 0; ++i, K -= 2) { (B[i] %= MOD); if (B[i] < 0) { B[i] += MOD; } (res *= B[i]) %= MOD; } cout << res << '\n'; return 0; }
replace
149
150
149
150
0
p02616
C++
Time Limit Exceeded
#include <bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; #define fr first #define sc second #define pii pair<int, int> #define all(v) v.begin(), v.end() using namespace std; const ll MOD = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; cin >> n >> k; vector<ll> pos, neg; for (int i = 0; i < n; i++) { ll temp; cin >> temp; if (temp >= 0) { pos.push_back(temp); } else { neg.push_back(-1 * temp); } } sort(all(pos)); sort(all(neg)); int i = (int)pos.size() - 1; int j = (int)neg.size() - 1; int rem = k; ll ans = 1; if (i == -1 && k % 2 == 1) { for (i = 0; i < k; i++) { ans = (ans * neg[i]) % MOD; } ans = (ans * (MOD - 1)) % MOD; } else { while (rem > 0) { if (rem > 1 && j > 0) { if (i < 1 || neg[j] * neg[j - 1] > pos[i] * pos[i - 1]) { ans = (ans * neg[j]) % MOD; j--; ans = (ans * neg[j]) % MOD; j--; rem -= 2; } } else { if (i >= 0) { ans = (ans * pos[i]) % MOD; i--; } else { ans = (ans * neg[j]) % MOD; ans = (ans * (MOD - 1)) % MOD; j--; } rem--; } } } cout << ans; return 0; }
#include <bits/stdc++.h> typedef long long ll; typedef unsigned long long ull; #define fr first #define sc second #define pii pair<int, int> #define all(v) v.begin(), v.end() using namespace std; const ll MOD = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, k; cin >> n >> k; vector<ll> pos, neg; for (int i = 0; i < n; i++) { ll temp; cin >> temp; if (temp >= 0) { pos.push_back(temp); } else { neg.push_back(-1 * temp); } } sort(all(pos)); sort(all(neg)); int i = (int)pos.size() - 1; int j = (int)neg.size() - 1; int rem = k; ll ans = 1; if (i == -1 && k % 2 == 1) { for (i = 0; i < k; i++) { ans = (ans * neg[i]) % MOD; } ans = (ans * (MOD - 1)) % MOD; } else { while (rem > 0) { if (rem > 1 && j > 0 && (i < 1 || neg[j] * neg[j - 1] > pos[i] * pos[i - 1])) { // if { ans = (ans * neg[j]) % MOD; j--; ans = (ans * neg[j]) % MOD; j--; rem -= 2; // } } else { if (i >= 0) { ans = (ans * pos[i]) % MOD; i--; } else { ans = (ans * neg[j]) % MOD; ans = (ans * (MOD - 1)) % MOD; j--; } rem--; } } } cout << ans; return 0; }
replace
48
56
48
57
TLE
p02616
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; (i) < ((int)(n)); ++(i)) const ll MOD = 1000000007; int main() { ll ans = 1; int N, K; cin >> N >> K; vector<ll> pos, neg; rep(i, N) { ll x; cin >> x; if (x >= 0) pos.push_back(x); else neg.push_back(x); } sort(pos.begin(), pos.end(), greater<ll>()); sort(neg.begin(), neg.end()); int p = pos.size(), n = neg.size(); if (n == 0) { rep(i, K) ans = (ans * pos[i]) % MOD; } else if (p == 0) { if (K % 2 == 0) rep(i, K) ans = (ans * neg[i]) % MOD; else { rep(i, K) ans = (ans * neg[N - 1 - i]) % MOD; ans = (ans + MOD) % MOD; } } else if (K == N) { rep(i, p) ans = (ans * pos[i]) % MOD; rep(i, n) ans = (ans * neg[i]) % MOD; ans = (ans + MOD) % MOD; } else { int count = 0; int i = 0, j = 0; while (count < K) { if (i < p - 1 && j < n - 1) { int x = pos[i] * pos[i + 1]; int y = neg[j] * neg[j + 1]; if (x > y || count == K - 1) { ans = (ans * pos[i]) % MOD; count++; i++; } else { ans = (ans * (y % MOD) % MOD) % MOD; j += 2; count += 2; } } else if (j == n - 1) { ans = (ans * pos[i]) % MOD; count++; i++; } else { if (count < K - 1) { ans = (ans * (neg[j] * neg[j + 1] % MOD) % MOD) % MOD; j += 2; count += 2; } else { ans = (ans * pos[i]) % MOD; count++; i++; } } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; (i) < ((int)(n)); ++(i)) const ll MOD = 1000000007; int main() { ll ans = 1; int N, K; cin >> N >> K; vector<ll> pos, neg; rep(i, N) { ll x; cin >> x; if (x >= 0) pos.push_back(x); else neg.push_back(x); } sort(pos.begin(), pos.end(), greater<ll>()); sort(neg.begin(), neg.end()); int p = pos.size(), n = neg.size(); if (n == 0) { rep(i, K) ans = (ans * pos[i]) % MOD; } else if (p == 0) { if (K % 2 == 0) rep(i, K) ans = (ans * neg[i]) % MOD; else { rep(i, K) ans = (ans * neg[N - 1 - i]) % MOD; ans = (ans + MOD) % MOD; } } else if (K == N) { rep(i, p) ans = (ans * pos[i]) % MOD; rep(i, n) ans = (ans * neg[i]) % MOD; ans = (ans + MOD) % MOD; } else { int count = 0; int i = 0, j = 0; while (count < K) { if (i < p - 1 && j < n - 1) { ll x = pos[i] * pos[i + 1]; ll y = neg[j] * neg[j + 1]; if (x > y || count == K - 1) { ans = (ans * pos[i]) % MOD; count++; i++; } else { ans = (ans * (y % MOD) % MOD) % MOD; j += 2; count += 2; } } else if (j == n - 1) { ans = (ans * pos[i]) % MOD; count++; i++; } else { if (count < K - 1) { ans = (ans * (neg[j] * neg[j + 1] % MOD) % MOD) % MOD; j += 2; count += 2; } else { ans = (ans * pos[i]) % MOD; count++; i++; } } } } cout << ans << endl; }
replace
39
41
39
41
0
p02616
C++
Runtime Error
#ifdef LOCAL #define _GLIBCXX_DEBUG #define __clock__ #else #pragma GCC optimize("Ofast") #endif #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using VI = vector<ll>; using VV = vector<VI>; using VS = vector<string>; using PII = pair<ll, ll>; // tourist set template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string &s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << '\n'; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif // tourist set end template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define rep(i, b) FOR(i, 0, b) #define ALL(v) (v).begin(), (v).end() #define p(s) cout << (s) << '\n' #define p2(s, t) cout << (s) << " " << (t) << '\n' #define br() p("") #define pn(s) cout << (#s) << " " << (s) << '\n' #define SZ(x) ((int)(x).size()) #define SORT(A) sort(ALL(A)) #define RSORT(A) sort(ALL(A), greater<ll>()) #define MP make_pair #define p_yes() p("Yes") #define p_no() p("No") ll SUM(VI &V) { return accumulate(ALL(V), 0LL); } ll MIN(VI &V) { return *min_element(ALL(V)); } ll MAX(VI &V) { return *max_element(ALL(V)); } void print_vector(VI &V) { ll n = V.size(); rep(i, n) { if (i) cout << ' '; cout << V[i]; } cout << endl; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } // long double using ld = long double; #define EPS (1e-14) #define equals(a, b) (fabs((a) - (b)) < EPS) void no() { p_no(); exit(0); } void yes() { p_yes(); exit(0); } const ll mod = 1e9 + 7; const ll inf = 1e18; const double PI = acos(-1); // snuke's mint // auto mod int // https://youtu.be/L8grWxBlIZ4?t=9858 // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize // https://youtu.be/8uowVvQ_-Mo?t=1329 : division // const int mod = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); // input ll N, K; cin >> N >> K; debug(N, K); VI A(N); rep(i, N) cin >> A[i]; ll zero = 0; for (ll a : A) { if (a == 0) zero++; } if (N - zero < K) { // ゼロしかつくれない debug("you can make zero only"); debug(A); debug(zero); p(0); return 0; } if (N == K) { debug("N==K easy"); mint m = 1; rep(i, N) m *= A[i]; p(m.x); return 0; } // 以降、K<N VI P, M; for (ll a : A) { if (a == 0) { zero++; } else if (a > 0) { P.push_back(a); } else { M.push_back(a); } } RSORT(P); SORT(M); // 全部負 if (SZ(M) == N) { debug("全部負"); mint m = 1; if (K % 2 == 0) { // 正 // 絶対値の大きい順から SORT(M); rep(i, K) m *= M[i]; } else { // 負 // 絶対値の小さい順から RSORT(M); rep(i, K) m *= M[i]; } p(m.x); return 0; } // 全部負 or 0 if (SZ(M) + zero == N) { debug("全部負 or 0"); if (K % 2 == 0) { // 正 or 0が可能 if (SZ(M) >= K) { mint m = 1; SORT(M); rep(i, K) m *= M[i]; p(m.x); } else { // 負が足りないので0になる p(0); } } else { // 負 or 0しか作れない p(0); } return 0; } if (SZ(P) + zero == N) { debug("全部正 or 0"); RSORT(P); if (SZ(P) >= K) { mint m = 1; rep(i, K) m *= P[i]; p(m.x); } else { p(0); } return 0; } // +, 0, - 混合 debug("+, 0, - 混合"); VI C; rep(i, SZ(P) / 2) { ll a = P[2 * i]; ll b = P[2 * i + 1]; C.push_back(a * b); } rep(i, SZ(M) / 2) { ll a = M[2 * i]; ll b = M[2 * i + 1]; C.push_back(a * b); } if (K % 2 == 0) { RSORT(C); mint m = 1; rep(i, K / 2) { m *= C[i]; } p(m.x); return 0; } // K%2==1 && 混合 // 1つは自由度があるので、0以上には必ずできる if (SZ(P) + SZ(M) / 2 * 2 >= K) { // プラスが可能 debug("プラスが可能"); vector<PII> V; rep(i, SZ(P)) { V.push_back(MP(P[i], -1)); // 符号注意(ソート都合) } rep(i, SZ(M)) { V.push_back(MP(-M[i], 1)); // 絶対値で入れる } sort(ALL(V), greater<PII>()); debug(V); mint m = 1; ll sign = 1; ll plus = 0; // count ll minus = 0; // count rep(i, K) { m *= V[i].first; sign *= -V[i].second; if (V[i].second < 0) { plus++; } else { minus++; } } if (sign > 0) { p(m.x); return 0; } debug("調整が必要"); // 負の数を 1 つ取り除き、非負の数を 1 つ加える if (plus < SZ(P) && minus < SZ(M) && plus > 0 && minus > 0) { // 2つの調整が可能(比較が必要) debug("TODO"); if (P[plus] * P[plus - 1] >= -M[minus - 1] * -M[minus]) { m *= P[plus]; m /= -M[minus - 1]; } else { m *= -M[minus]; m /= P[plus - 1]; } } else if (plus < SZ(P) && minus > 0) { debug("plan A"); // 正を1つふやし、負を1つへらす m /= -M[minus - 1]; m *= P[plus]; } else if (minus < SZ(M) && plus > 0) { debug("plan B", plus, minus); // 負を1つふやし、正を1つへらす m /= P[plus - 1]; debug(P[plus - 1]); m *= -M[minus]; debug(M[minus]); } else { assert(1 == 2); debug("???"); debug(plus, minus); } p(m.x); return 0; } else { // 雑 debug("雑"); p(0); } return 0; }
#ifdef LOCAL #define _GLIBCXX_DEBUG #define __clock__ #else #pragma GCC optimize("Ofast") #endif #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using VI = vector<ll>; using VV = vector<VI>; using VS = vector<string>; using PII = pair<ll, ll>; // tourist set template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string &s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } string to_string(vector<bool> v) { bool first = true; string res = "{"; for (int i = 0; i < static_cast<int>(v.size()); i++) { if (!first) { res += ", "; } first = false; res += to_string(v[i]); } res += "}"; return res; } template <size_t N> string to_string(bitset<N> v) { string res = ""; for (size_t i = 0; i < N; i++) { res += static_cast<char>('0' + v[i]); } return res; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")"; } template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p) { return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")"; } void debug_out() { cerr << '\n'; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #else #define debug(...) 42 #endif // tourist set end template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define rep(i, b) FOR(i, 0, b) #define ALL(v) (v).begin(), (v).end() #define p(s) cout << (s) << '\n' #define p2(s, t) cout << (s) << " " << (t) << '\n' #define br() p("") #define pn(s) cout << (#s) << " " << (s) << '\n' #define SZ(x) ((int)(x).size()) #define SORT(A) sort(ALL(A)) #define RSORT(A) sort(ALL(A), greater<ll>()) #define MP make_pair #define p_yes() p("Yes") #define p_no() p("No") ll SUM(VI &V) { return accumulate(ALL(V), 0LL); } ll MIN(VI &V) { return *min_element(ALL(V)); } ll MAX(VI &V) { return *max_element(ALL(V)); } void print_vector(VI &V) { ll n = V.size(); rep(i, n) { if (i) cout << ' '; cout << V[i]; } cout << endl; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } // long double using ld = long double; #define EPS (1e-14) #define equals(a, b) (fabs((a) - (b)) < EPS) void no() { p_no(); exit(0); } void yes() { p_yes(); exit(0); } const ll mod = 1e9 + 7; const ll inf = 1e18; const double PI = acos(-1); // snuke's mint // auto mod int // https://youtu.be/L8grWxBlIZ4?t=9858 // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize // https://youtu.be/8uowVvQ_-Mo?t=1329 : division // const int mod = 1000000007; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); // input ll N, K; cin >> N >> K; debug(N, K); VI A(N); rep(i, N) cin >> A[i]; ll zero = 0; for (ll a : A) { if (a == 0) zero++; } if (N - zero < K) { // ゼロしかつくれない debug("you can make zero only"); debug(A); debug(zero); p(0); return 0; } if (N == K) { debug("N==K easy"); mint m = 1; rep(i, N) m *= A[i]; p(m.x); return 0; } // 以降、K<N VI P, M; for (ll a : A) { if (a == 0) { zero++; } else if (a > 0) { P.push_back(a); } else { M.push_back(a); } } RSORT(P); SORT(M); // 全部負 if (SZ(M) == N) { debug("全部負"); mint m = 1; if (K % 2 == 0) { // 正 // 絶対値の大きい順から SORT(M); rep(i, K) m *= M[i]; } else { // 負 // 絶対値の小さい順から RSORT(M); rep(i, K) m *= M[i]; } p(m.x); return 0; } // 全部負 or 0 if (SZ(M) + zero == N) { debug("全部負 or 0"); if (K % 2 == 0) { // 正 or 0が可能 if (SZ(M) >= K) { mint m = 1; SORT(M); rep(i, K) m *= M[i]; p(m.x); } else { // 負が足りないので0になる p(0); } } else { // 負 or 0しか作れない p(0); } return 0; } if (SZ(P) + zero == N) { debug("全部正 or 0"); RSORT(P); if (SZ(P) >= K) { mint m = 1; rep(i, K) m *= P[i]; p(m.x); } else { p(0); } return 0; } // +, 0, - 混合 debug("+, 0, - 混合"); VI C; rep(i, SZ(P) / 2) { ll a = P[2 * i]; ll b = P[2 * i + 1]; C.push_back(a * b); } rep(i, SZ(M) / 2) { ll a = M[2 * i]; ll b = M[2 * i + 1]; C.push_back(a * b); } if (K % 2 == 0) { RSORT(C); mint m = 1; rep(i, K / 2) { m *= C[i]; } p(m.x); return 0; } // K%2==1 && 混合 // 1つは自由度があるので、0以上には必ずできる if (SZ(P) + SZ(M) / 2 * 2 >= K) { // プラスが可能 debug("プラスが可能"); vector<PII> V; rep(i, SZ(P)) { V.push_back(MP(P[i], -1)); // 符号注意(ソート都合) } rep(i, SZ(M)) { V.push_back(MP(-M[i], 1)); // 絶対値で入れる } sort(ALL(V), greater<PII>()); debug(V); mint m = 1; ll sign = 1; ll plus = 0; // count ll minus = 0; // count rep(i, K) { m *= V[i].first; sign *= -V[i].second; if (V[i].second < 0) { plus++; } else { minus++; } } if (sign > 0) { p(m.x); return 0; } debug("調整が必要"); // 負の数を 1 つ取り除き、非負の数を 1 つ加える if (plus < SZ(P) && minus < SZ(M) && plus > 0 && minus > 0) { // 2つの調整が可能(比較が必要) debug("TODO"); if (P[plus] * P[plus - 1] >= -M[minus - 1] * -M[minus]) { m *= P[plus]; m /= -M[minus - 1]; } else { m *= -M[minus]; m /= P[plus - 1]; } } else if (plus < SZ(P) && minus > 0) { debug("plan A"); // 正を1つふやし、負を1つへらす m /= -M[minus - 1]; m *= P[plus]; } else if (minus < SZ(M) && plus > 0) { debug("plan B", plus, minus); // 負を1つふやし、正を1つへらす m /= P[plus - 1]; debug(P[plus - 1]); m *= -M[minus]; debug(M[minus]); } else { p(0); return 0; // assert(1==2); debug("???"); debug(plus, minus); } p(m.x); return 0; } else { // 雑 debug("雑"); p(0); } return 0; }
replace
405
406
405
408
0
p02616
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // #define int long long #define DEBUG(x) cout << '>' << #x << ':' << x << endl; #define REP(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define FORD(i, a, b) for (int i = (a); i >= (b); --i) inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } inline int msbp(int x) { return 31 - __builtin_clz(x); } inline int msb(int x) { return 1 << msbp(x); } typedef long long ll; typedef pair<int, int> pii; // const ll INF = 0x3f3f3f3f3f3f3f3fLL; const int INF = 0x3f3f3f3f; // const int INF = INT_MAX; // const int nINF = INT_MIN; // const ll INF = LLONG_MAX; // const ll nINF = LLONG_MIN; ///////////////////////////////////////////////////////////////////// const int N = 2e5 + 10, M = 1e9 + 7; ll mod(ll x) { return (x % M + M) % M; } int add(ll a, ll b) { return mod(mod(a) + mod(b)); } int mult(ll a, ll b) { return mod(mod(a) * mod(b)); } int n, k, a[N], ans = 1; vector<int> pos, neg; signed main() { ios::sync_with_stdio(false); // cout << fixed << setprecision(7); cin >> n >> k; REP(i, n) cin >> a[i]; REP(i, n) { if (a[i] > 0) { pos.push_back(a[i]); } else { neg.push_back(a[i]); } } if (pos.size()) { // we have a choice on number of positive numbers. if (k & 1) { // choose the biggest positive number first sort(pos.begin(), pos.end()); ans = pos.back(); pos.pop_back(); --k; } vector<ll> all; sort(pos.begin(), pos.end(), greater<int>()); sort(neg.begin(), neg.end()); for (int i = 0; i + 1 < pos.size(); i += 2) all.push_back((ll)pos[i] * pos[i + 1]); for (int i = 0; i + 1 < neg.size(); i += 2) all.push_back((ll)neg[i] * neg[i + 1]); if ((pos.size() & 1) && (neg.size() & 1)) all.push_back((ll)pos.back() * neg.back()); sort(all.begin(), all.end(), greater<ll>()); REP(i, k / 2) { ans = mult(ans, all[i]); } cout << ans << endl; } else { sort(neg.begin(), neg.end(), greater<int>()); if (k & 1) { REP(i, k) ans = mult(ans, neg[i]); } else { FORD(i, neg.size() - 1, neg.size() - k) ans = mult(ans, neg[i]); } cout << ans << endl; } return 0; } // Easy things to check: // - LONG LONGS (WA) // - const int N is correct (WA, RTE) CHECK IF IT SHOULD BE 2*N!!!! // - .size()-k underflow (WA, RTE, TLE) // - small n edge cases (WA) // Rare mistakes made in the past: // - division by 0 (WA) // - negative arithmetic, ceiling division, modulo (WA) // - setprecision (WA) // - INF not big enough using ll (WA) // - setting max to 0 instead of -INF/min to 0 instead of INF (WA) // - outputting debug (WA) // - allocating too much memory (locRTE, MLE) // - stack size (locRTE) // - round announcements (WA) // - multiset::erase (WA) // - forgetting to rename recursive call when copy/pasting recursive function // (WA) // - not clearing DS between test cases EVEN FOR INPUT (WA, RTE, TLE, MLE)
#include <bits/stdc++.h> using namespace std; // #define int long long #define DEBUG(x) cout << '>' << #x << ':' << x << endl; #define REP(i, n) for (int i = 0; i < (n); ++i) #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define FORD(i, a, b) for (int i = (a); i >= (b); --i) inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } inline int msbp(int x) { return 31 - __builtin_clz(x); } inline int msb(int x) { return 1 << msbp(x); } typedef long long ll; typedef pair<int, int> pii; // const ll INF = 0x3f3f3f3f3f3f3f3fLL; const int INF = 0x3f3f3f3f; // const int INF = INT_MAX; // const int nINF = INT_MIN; // const ll INF = LLONG_MAX; // const ll nINF = LLONG_MIN; ///////////////////////////////////////////////////////////////////// const int N = 2e5 + 10, M = 1e9 + 7; ll mod(ll x) { return (x % M + M) % M; } int add(ll a, ll b) { return mod(mod(a) + mod(b)); } int mult(ll a, ll b) { return mod(mod(a) * mod(b)); } int n, k, a[N], ans = 1; vector<int> pos, neg; signed main() { ios::sync_with_stdio(false); // cout << fixed << setprecision(7); cin >> n >> k; REP(i, n) cin >> a[i]; REP(i, n) { if (a[i] > 0) { pos.push_back(a[i]); } else { neg.push_back(a[i]); } } if (pos.size()) { // we have a choice on number of positive numbers. if (k & 1) { // choose the biggest positive number first sort(pos.begin(), pos.end()); ans = pos.back(); pos.pop_back(); --k; } vector<ll> all; sort(pos.begin(), pos.end(), greater<int>()); sort(neg.begin(), neg.end()); for (int i = 0; i + 1 < pos.size(); i += 2) all.push_back((ll)pos[i] * pos[i + 1]); for (int i = 0; i + 1 < neg.size(); i += 2) all.push_back((ll)neg[i] * neg[i + 1]); if ((pos.size() & 1) && (neg.size() & 1)) all.push_back((ll)pos.back() * neg.back()); sort(all.begin(), all.end(), greater<ll>()); REP(i, k / 2) { ans = mult(ans, all[i]); } cout << ans << endl; } else { sort(neg.begin(), neg.end()); if (k & 1) reverse(neg.begin(), neg.end()); REP(i, k) ans = mult(ans, neg[i]); cout << ans << endl; } return 0; } // Easy things to check: // - LONG LONGS (WA) // - const int N is correct (WA, RTE) CHECK IF IT SHOULD BE 2*N!!!! // - .size()-k underflow (WA, RTE, TLE) // - small n edge cases (WA) // Rare mistakes made in the past: // - division by 0 (WA) // - negative arithmetic, ceiling division, modulo (WA) // - setprecision (WA) // - INF not big enough using ll (WA) // - setting max to 0 instead of -INF/min to 0 instead of INF (WA) // - outputting debug (WA) // - allocating too much memory (locRTE, MLE) // - stack size (locRTE) // - round announcements (WA) // - multiset::erase (WA) // - forgetting to rename recursive call when copy/pasting recursive function // (WA) // - not clearing DS between test cases EVEN FOR INPUT (WA, RTE, TLE, MLE)
replace
64
70
64
68
0
p02616
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define REP(i, N) for (int i = 0; i < (int)N; i++) #define FOR(i, a, b) for (int i = a; i < (int)b; i++) #define ALL(x) (x).begin(), (x).end() #define INF (1 << 30) #define LLINF (1LL << 62) #define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__) constexpr int MOD = 1000000007; using ll = long long; using Pii = pair<int, int>; using Pll = pair<ll, ll>; inline int popcount(ll x) { return __builtin_popcountll(x); } inline int div2num(ll x) { return __builtin_ctzll(x); } inline bool bit(ll x, int b) { return (x >> b) & 1; } template <class T> string to_string(T s); template <class S, class T> string to_string(pair<S, T> p); string to_string(string s) { return s; } string to_string(const char s[]) { return to_string(string(s)); } template <class T> string to_string(T v) { if (v.empty()) return "{}"; string ret = "{"; for (auto x : v) ret += to_string(x) + ","; ret.back() = '}'; return ret; } template <class S, class T> string to_string(pair<S, T> p) { return "{" + to_string(p.first) + ":" + to_string(p.second) + "}"; } void debug() { cerr << endl; } template <class Head, class... Tail> void debug(Head head, Tail... tail) { cerr << to_string(head) << " "; debug(tail...); } struct IO { #ifdef _WIN32 inline char getchar_unlocked() { return getchar(); } inline void putchar_unlocked(char c) { putchar(c); } #endif std::string separator = " "; template <class T> inline void read(T &x) { char c; do { c = getchar_unlocked(); } while (c != '-' && (c < '0' || '9' < c)); bool minus = 0; if (c == '-') { minus = 1; c = getchar_unlocked(); } x = 0; while ('0' <= c && c <= '9') { x *= 10; x += c - '0'; c = getchar_unlocked(); } if (minus) x = -x; } inline void read(std::string &x) { char c; do { c = getchar_unlocked(); } while (c == ' ' || c == '\n'); x.clear(); do { x += c; c = getchar_unlocked(); } while (c != ' ' && c != '\n' && c != EOF); } template <class T> inline void read(std::vector<T> &v) { for (auto &x : v) read(x); } template <class S, class T> inline void read(std::pair<S, T> &p) { read(p.first); read(p.second); } template <class Head, class... Tail> inline void read(Head &head, Tail &...tail) { read(head); read(tail...); } template <class T> inline void write(T x) { char buf[32]; int p = 0; if (x < 0) { x = -x; putchar_unlocked('-'); } if (x == 0) putchar_unlocked('0'); while (x > 0) { buf[p++] = (x % 10) + '0'; x /= 10; } while (p) { putchar_unlocked(buf[--p]); } } inline void write(std::string x) { for (char c : x) putchar_unlocked(c); } inline void write(const char s[]) { for (int i = 0; s[i] != 0; ++i) putchar_unlocked(s[i]); } template <class T> inline void write(std::vector<T> v) { if (v.empty()) return; for (auto itr = v.begin(); itr + 1 != v.end(); ++itr) { write(*itr); write(separator); } write(v.back()); } template <class Head, class... Tail> inline void write(Head head, Tail... tail) { write(head); write(separator); write(tail...); } template <class Head, class... Tail> inline void writeln(Head head, Tail... tail) { write(head, tail...); write("\n"); } void set_separator(std::string s) { separator = s; } } io; struct Prime { int n; vector<int> table; vector<int> primes; Prime(int _n = 100000) { n = _n + 1; table.resize(n, -1); table[0] = 0; table[1] = -1; for (int i = 2; i * i < n; ++i) { if (table[i] == -1) { for (int j = i * i; j < n; j += i) { table[j] = i; } } } } void enumerate_primes() { primes.clear(); for (int i = 2; i < n; ++i) { if (table[i] == -1) primes.push_back(i); } } vector<pair<long long, int>> prime_factor(long long x) { map<long long, int> mp; long long div = 2; int p = 0; while (n <= x && div * div <= x) { if (x % div == 0) { mp[div]++; x /= div; } else { if (p + 1 < primes.size()) { div = primes[++p]; } else { div++; } } } if (x < n) { while (table[x] != -1) { mp[table[x]]++; x /= table[x]; } } if (x > 1) mp[x]++; vector<pair<long long, int>> ret; for (auto p : mp) ret.push_back(p); return ret; } }; template <int MOD = 1000000007> struct Math { vector<long long> fact, factinv, inv; Math(int n = 100000) { fact.resize(n + 1); factinv.resize(n + 1); inv.resize(n + 1); fact[0] = fact[1] = 1; factinv[0] = factinv[1] = 1; inv[1] = 1; for (int i = 2; i <= n; ++i) { fact[i] = fact[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; factinv[i] = factinv[i - 1] * inv[i] % MOD; } } long long C(int n, int r) { if (n < r || n < 0 || r < 0) { return 0; } else { return fact[n] * (factinv[r] * factinv[n - r] % MOD) % MOD; } } long long P(int n, int r) { if (n < r || n < 0 || r < 0) { return 0; } else { return fact[n] * factinv[n - r] % MOD; } } long long H(int n, int r) { return C(n + r - 1, r); } }; struct UnionFind { vector<int> data; vector<vector<int>> groups; UnionFind(int n) : data(n, -1) {} int root(int v) { return data[v] < 0 ? v : data[v] = root(data[v]); } bool unite(int u, int v) { if ((u = root(u)) == (v = root(v))) { return 1; } else { if (-data[u] < -data[v]) swap(u, v); data[u] += data[v]; data[v] = u; return 0; } } int size(int v) { return -data[root(v)]; } void make_groups() { map<int, vector<int>> mp; for (int i = 0; i < data.size(); ++i) mp[root(i)].push_back(i); groups.clear(); for (auto p : mp) groups.push_back(p.second); } }; namespace phc { long long modpow(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % MOD; a = a * a % MOD; n >>= 1; } return res; } long long modinv(long long a) { long long b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= MOD; if (u < 0) u += MOD; return u; } long long gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return a * b / gcd(a, b); } } // namespace phc template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int get_mod() { return mod; } }; using modint = ModInt<MOD>; constexpr int dy[4] = {-1, 0, 1, 0}, dx[4] = {0, -1, 0, 1}; int main() { ll N, K; io.read(N, K); ll zero = 0; vector<ll> A(N), pos, neg; io.read(A); sort(ALL(A), greater<ll>()); REP(i, N) { if (A[i] == 0) zero++; else if (A[i] > 0) pos.push_back(A[i]); else neg.push_back(A[i]); } modint ans = 1; if (K == 1) { ans *= A[0]; } else if (N == K) { REP(i, N) ans *= A[i]; } else { if (pos.size() + neg.size() < K) { ans *= 0; } else if (K % 2 == 1 && neg.size() == N) { sort(ALL(neg), greater<ll>()); REP(i, K) ans *= neg[i]; } else { sort(ALL(pos), greater<ll>()); sort(ALL(neg)); vector<modint> cum1(pos.size() + 1, 1), cum2(neg.size() + 1, 1); REP(i, pos.size()) cum1[i + 1] = cum1[i] * pos[i]; REP(i, neg.size()) cum2[i + 1] = cum2[i] * neg[i]; int j = (K - pos.size() + 1) / 2 * 2; ans = cum1[K - j] * cum2[j]; while (j + 2 <= neg.size() && 0 <= (K - (j + 2))) { j += 2; int i = K - j; if (pos[i] * pos[i + 1] > neg[j - 2] * neg[j - 1]) break; ans = cum1[i] * cum2[j]; } } } io.writeln(ans.x); return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstdio> #include <deque> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define REP(i, N) for (int i = 0; i < (int)N; i++) #define FOR(i, a, b) for (int i = a; i < (int)b; i++) #define ALL(x) (x).begin(), (x).end() #define INF (1 << 30) #define LLINF (1LL << 62) #define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__) constexpr int MOD = 1000000007; using ll = long long; using Pii = pair<int, int>; using Pll = pair<ll, ll>; inline int popcount(ll x) { return __builtin_popcountll(x); } inline int div2num(ll x) { return __builtin_ctzll(x); } inline bool bit(ll x, int b) { return (x >> b) & 1; } template <class T> string to_string(T s); template <class S, class T> string to_string(pair<S, T> p); string to_string(string s) { return s; } string to_string(const char s[]) { return to_string(string(s)); } template <class T> string to_string(T v) { if (v.empty()) return "{}"; string ret = "{"; for (auto x : v) ret += to_string(x) + ","; ret.back() = '}'; return ret; } template <class S, class T> string to_string(pair<S, T> p) { return "{" + to_string(p.first) + ":" + to_string(p.second) + "}"; } void debug() { cerr << endl; } template <class Head, class... Tail> void debug(Head head, Tail... tail) { cerr << to_string(head) << " "; debug(tail...); } struct IO { #ifdef _WIN32 inline char getchar_unlocked() { return getchar(); } inline void putchar_unlocked(char c) { putchar(c); } #endif std::string separator = " "; template <class T> inline void read(T &x) { char c; do { c = getchar_unlocked(); } while (c != '-' && (c < '0' || '9' < c)); bool minus = 0; if (c == '-') { minus = 1; c = getchar_unlocked(); } x = 0; while ('0' <= c && c <= '9') { x *= 10; x += c - '0'; c = getchar_unlocked(); } if (minus) x = -x; } inline void read(std::string &x) { char c; do { c = getchar_unlocked(); } while (c == ' ' || c == '\n'); x.clear(); do { x += c; c = getchar_unlocked(); } while (c != ' ' && c != '\n' && c != EOF); } template <class T> inline void read(std::vector<T> &v) { for (auto &x : v) read(x); } template <class S, class T> inline void read(std::pair<S, T> &p) { read(p.first); read(p.second); } template <class Head, class... Tail> inline void read(Head &head, Tail &...tail) { read(head); read(tail...); } template <class T> inline void write(T x) { char buf[32]; int p = 0; if (x < 0) { x = -x; putchar_unlocked('-'); } if (x == 0) putchar_unlocked('0'); while (x > 0) { buf[p++] = (x % 10) + '0'; x /= 10; } while (p) { putchar_unlocked(buf[--p]); } } inline void write(std::string x) { for (char c : x) putchar_unlocked(c); } inline void write(const char s[]) { for (int i = 0; s[i] != 0; ++i) putchar_unlocked(s[i]); } template <class T> inline void write(std::vector<T> v) { if (v.empty()) return; for (auto itr = v.begin(); itr + 1 != v.end(); ++itr) { write(*itr); write(separator); } write(v.back()); } template <class Head, class... Tail> inline void write(Head head, Tail... tail) { write(head); write(separator); write(tail...); } template <class Head, class... Tail> inline void writeln(Head head, Tail... tail) { write(head, tail...); write("\n"); } void set_separator(std::string s) { separator = s; } } io; struct Prime { int n; vector<int> table; vector<int> primes; Prime(int _n = 100000) { n = _n + 1; table.resize(n, -1); table[0] = 0; table[1] = -1; for (int i = 2; i * i < n; ++i) { if (table[i] == -1) { for (int j = i * i; j < n; j += i) { table[j] = i; } } } } void enumerate_primes() { primes.clear(); for (int i = 2; i < n; ++i) { if (table[i] == -1) primes.push_back(i); } } vector<pair<long long, int>> prime_factor(long long x) { map<long long, int> mp; long long div = 2; int p = 0; while (n <= x && div * div <= x) { if (x % div == 0) { mp[div]++; x /= div; } else { if (p + 1 < primes.size()) { div = primes[++p]; } else { div++; } } } if (x < n) { while (table[x] != -1) { mp[table[x]]++; x /= table[x]; } } if (x > 1) mp[x]++; vector<pair<long long, int>> ret; for (auto p : mp) ret.push_back(p); return ret; } }; template <int MOD = 1000000007> struct Math { vector<long long> fact, factinv, inv; Math(int n = 100000) { fact.resize(n + 1); factinv.resize(n + 1); inv.resize(n + 1); fact[0] = fact[1] = 1; factinv[0] = factinv[1] = 1; inv[1] = 1; for (int i = 2; i <= n; ++i) { fact[i] = fact[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; factinv[i] = factinv[i - 1] * inv[i] % MOD; } } long long C(int n, int r) { if (n < r || n < 0 || r < 0) { return 0; } else { return fact[n] * (factinv[r] * factinv[n - r] % MOD) % MOD; } } long long P(int n, int r) { if (n < r || n < 0 || r < 0) { return 0; } else { return fact[n] * factinv[n - r] % MOD; } } long long H(int n, int r) { return C(n + r - 1, r); } }; struct UnionFind { vector<int> data; vector<vector<int>> groups; UnionFind(int n) : data(n, -1) {} int root(int v) { return data[v] < 0 ? v : data[v] = root(data[v]); } bool unite(int u, int v) { if ((u = root(u)) == (v = root(v))) { return 1; } else { if (-data[u] < -data[v]) swap(u, v); data[u] += data[v]; data[v] = u; return 0; } } int size(int v) { return -data[root(v)]; } void make_groups() { map<int, vector<int>> mp; for (int i = 0; i < data.size(); ++i) mp[root(i)].push_back(i); groups.clear(); for (auto p : mp) groups.push_back(p.second); } }; namespace phc { long long modpow(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % MOD; a = a * a % MOD; n >>= 1; } return res; } long long modinv(long long a) { long long b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= MOD; if (u < 0) u += MOD; return u; } long long gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return a * b / gcd(a, b); } } // namespace phc template <int mod> struct ModInt { int x; ModInt() : x(0) {} ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {} ModInt &operator+=(const ModInt &p) { if ((x += p.x) >= mod) x -= mod; return *this; } ModInt &operator-=(const ModInt &p) { if ((x += mod - p.x) >= mod) x -= mod; return *this; } ModInt &operator*=(const ModInt &p) { x = (int)(1LL * x * p.x % mod); return *this; } ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; } ModInt operator-() const { return ModInt(-x); } ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; } ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; } ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; } ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; } bool operator==(const ModInt &p) const { return x == p.x; } bool operator!=(const ModInt &p) const { return x != p.x; } ModInt inverse() const { int a = x, b = mod, u = 1, v = 0, t; while (b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return ModInt(u); } ModInt pow(int64_t n) const { ModInt ret(1), mul(x); while (n > 0) { if (n & 1) ret *= mul; mul *= mul; n >>= 1; } return ret; } friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; } friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt<mod>(t); return (is); } static int get_mod() { return mod; } }; using modint = ModInt<MOD>; constexpr int dy[4] = {-1, 0, 1, 0}, dx[4] = {0, -1, 0, 1}; int main() { ll N, K; io.read(N, K); ll zero = 0; vector<ll> A(N), pos, neg; io.read(A); sort(ALL(A), greater<ll>()); REP(i, N) { if (A[i] == 0) zero++; else if (A[i] > 0) pos.push_back(A[i]); else neg.push_back(A[i]); } modint ans = 1; if (K == 1) { ans *= A[0]; } else if (N == K) { REP(i, N) ans *= A[i]; } else { if (pos.size() + neg.size() < K) { ans *= 0; } else if (K % 2 == 1 && neg.size() == N) { sort(ALL(neg), greater<ll>()); REP(i, K) ans *= neg[i]; } else { sort(ALL(pos), greater<ll>()); sort(ALL(neg)); vector<modint> cum1(pos.size() + 1, 1), cum2(neg.size() + 1, 1); REP(i, pos.size()) cum1[i + 1] = cum1[i] * pos[i]; REP(i, neg.size()) cum2[i + 1] = cum2[i] * neg[i]; int j = max(0, (int)((K - (int)pos.size() + 1) / 2 * 2)); ans = cum1[K - j] * cum2[j]; while (j + 2 <= neg.size() && 0 <= (K - (j + 2))) { j += 2; int i = K - j; if (pos[i] * pos[i + 1] > neg[j - 2] * neg[j - 1]) break; ans = cum1[i] * cum2[j]; } } } io.writeln(ans.x); return 0; }
replace
413
414
413
414
0
p02616
C++
Runtime Error
#define _USE_MATH_DEFINES // #include <bits/stdc++.h> #include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <deque> #include <iomanip> #include <ios> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; const ll MOD = 1000000007; vector<ll> pos; vector<ll> neg; int zero = 0; void solve(ll N, ll K, std::vector<ll> A) { REP(i, N) { if (A[i] > 0) pos.push_back(A[i]); else if (A[i] < 0) neg.push_back(A[i]); else zero++; } if ((N - zero > K && pos.size() > 0) || (N - zero == K && neg.size() % 2 == 0) || (pos.size() == 0 && K % 2 == 0)) { ll result = 1; ll must_pos = max(K - K / 2 * 2, K - (ll)neg.size() / 2 * 2); sort(pos.begin(), pos.end(), greater<ll>()); sort(neg.begin(), neg.end()); int pos_index = 0, neg_index = 0; for (; pos_index < must_pos; pos_index++) { result *= pos[pos_index]; result %= MOD; } for (int i = (int)must_pos; i < K; i += 2) { if ((int)pos.size() >= pos_index + 2 && (int)neg.size() >= neg_index + 2) { ll pp = pos[pos_index] * pos[pos_index + 1]; ll nn = neg[neg_index] * neg[neg_index + 1]; if (pp > nn) { pp %= MOD; result *= pp; result %= MOD; pos_index += 2; } else { nn %= MOD; result *= nn; result %= MOD; neg_index += 2; } } else if ((int)pos.size() >= pos_index + 2) { result *= pos[pos_index]; result %= MOD; result *= pos[pos_index + 1]; result %= MOD; pos_index += 2; } else { result *= neg[neg_index]; result %= MOD; result *= neg[neg_index + 1]; result %= MOD; neg_index += 2; } } cout << result << endl; } else if (zero) { cout << 0 << endl; } else { ll result = 1; sort(pos.begin(), pos.end()); sort(neg.begin(), neg.end(), greater<ll>()); auto p = pos.begin(); auto n = neg.begin(); REP(i, K) { if ((p == pos.end()) || (n != neg.end() && *p > -(*n))) { result *= -(*n); n++; result %= MOD; } else { result *= *p; p++; result %= MOD; } } cout << MOD - result << endl; } } int main() { ll N; (void)scanf("%lld", &N); ll K; (void)scanf("%lld", &K); std::vector<ll> A(N); for (int i = 0; i < N; i++) { (void)scanf("%lld", &A[i]); } solve(N, K, std::move(A)); return 0; }
#define _USE_MATH_DEFINES // #include <bits/stdc++.h> #include <algorithm> #include <cmath> #include <complex> #include <cstdio> #include <deque> #include <iomanip> #include <ios> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) using ll = long long; const ll MOD = 1000000007; vector<ll> pos; vector<ll> neg; int zero = 0; void solve(ll N, ll K, std::vector<ll> A) { REP(i, N) { if (A[i] > 0) pos.push_back(A[i]); else if (A[i] < 0) neg.push_back(A[i]); else zero++; } if ((N - zero > K && pos.size() > 0) || (N - zero > K && pos.size() == 0 && K % 2 == 0) || (N - zero == K && neg.size() % 2 == 0)) { ll result = 1; ll must_pos = max(K - K / 2 * 2, K - (ll)neg.size() / 2 * 2); sort(pos.begin(), pos.end(), greater<ll>()); sort(neg.begin(), neg.end()); int pos_index = 0, neg_index = 0; for (; pos_index < must_pos; pos_index++) { result *= pos[pos_index]; result %= MOD; } for (int i = (int)must_pos; i < K; i += 2) { if ((int)pos.size() >= pos_index + 2 && (int)neg.size() >= neg_index + 2) { ll pp = pos[pos_index] * pos[pos_index + 1]; ll nn = neg[neg_index] * neg[neg_index + 1]; if (pp > nn) { pp %= MOD; result *= pp; result %= MOD; pos_index += 2; } else { nn %= MOD; result *= nn; result %= MOD; neg_index += 2; } } else if ((int)pos.size() >= pos_index + 2) { result *= pos[pos_index]; result %= MOD; result *= pos[pos_index + 1]; result %= MOD; pos_index += 2; } else { result *= neg[neg_index]; result %= MOD; result *= neg[neg_index + 1]; result %= MOD; neg_index += 2; } } cout << result << endl; } else if (zero) { cout << 0 << endl; } else { ll result = 1; sort(pos.begin(), pos.end()); sort(neg.begin(), neg.end(), greater<ll>()); auto p = pos.begin(); auto n = neg.begin(); REP(i, K) { if ((p == pos.end()) || (n != neg.end() && *p > -(*n))) { result *= -(*n); n++; result %= MOD; } else { result *= *p; p++; result %= MOD; } } cout << MOD - result << endl; } } int main() { ll N; (void)scanf("%lld", &N); ll K; (void)scanf("%lld", &K); std::vector<ll> A(N); for (int i = 0; i < N; i++) { (void)scanf("%lld", &A[i]); } solve(N, K, std::move(A)); return 0; }
replace
38
40
38
40
0