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
p02947
Python
Runtime Error
# -*- coding:utf-8 -*- import math N = int(input()) type_dict = {} for _ in range(N): s = input() counts = ( s.count("a"), s.count("b"), s.count("c"), s.count("d"), s.count("e"), s.count("f"), s.count("g"), s.count("h"), s.count("i"), s.count("j"), s.count("k"), s.count("l"), s.count("m"), s.count("n"), s.count("o"), s.count("p"), s.count("q"), s.count("r"), s.count("s"), s.count("t"), s.count("u"), s.count("v"), s.count("w"), s.count("x"), s.count("y"), s.count("z"), ) if counts in type_dict: type_dict[counts] = type_dict[counts] + 1 else: type_dict[counts] = 1 def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) print(sum([combinations_count(x, 2) for x in type_dict.items() if x > 1]))
# -*- coding:utf-8 -*- import math N = int(input()) type_dict = {} for _ in range(N): s = input() counts = ( s.count("a"), s.count("b"), s.count("c"), s.count("d"), s.count("e"), s.count("f"), s.count("g"), s.count("h"), s.count("i"), s.count("j"), s.count("k"), s.count("l"), s.count("m"), s.count("n"), s.count("o"), s.count("p"), s.count("q"), s.count("r"), s.count("s"), s.count("t"), s.count("u"), s.count("v"), s.count("w"), s.count("x"), s.count("y"), s.count("z"), ) if counts in type_dict: type_dict[counts] = type_dict[counts] + 1 else: type_dict[counts] = 1 def combinations_count(n, r): return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) print(sum([combinations_count(x, 2) for x in type_dict.values() if x > 1]))
replace
47
48
47
48
TypeError: '>' not supported between instances of 'tuple' and 'int'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02947/Python/s779046160.py", line 29, in <module> print(sum([combinations_count(x, 2) for x in type_dict.items() if x > 1])) File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02947/Python/s779046160.py", line 29, in <listcomp> print(sum([combinations_count(x, 2) for x in type_dict.items() if x > 1])) TypeError: '>' not supported between instances of 'tuple' and 'int'
p02947
Python
Runtime Error
from collections import Counter def main(): n = int(input()) cnt = Counter() ans = 0 for i in range(n): s = sorted(input()) if cnt[s] == 0: cnt[s] = 1 else: ans += cnt[s] cnt[s] += 1 print(ans) if __name__ == "__main__": main()
from collections import Counter def main(): n = int(input()) cnt = Counter() ans = 0 for i in range(n): s = "".join(sorted(input())) if cnt[s] == 0: cnt[s] = 1 else: ans += cnt[s] cnt[s] += 1 print(ans) if __name__ == "__main__": main()
replace
8
10
8
9
TypeError: unhashable type: 'list'
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02947/Python/s229077088.py", line 20, in <module> main() File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02947/Python/s229077088.py", line 11, in main if cnt[s] == 0: TypeError: unhashable type: 'list'
p02947
Python
Time Limit Exceeded
def main(): n = int(input()) s = [""] * n ans = 0 for i in range(n): s[i] = SortString(input()) s.sort() for i in range(n - 1): for j in range(i + 1, n): if s[i] == s[j]: ans += 1 else: break print(ans) def SortString(text): return "".join(sorted(list(text))) if __name__ == "__main__": main()
def main(): n = int(input()) s = [""] * n ans = 0 for i in range(n): s[i] = SortString(input()) sDictionary = {} for i in range(n): if sDictionary.get(s[i]): ans += sDictionary.get(s[i]) sDictionary[s[i]] += 1 else: sDictionary[s[i]] = 1 print(ans) def SortString(text): return "".join(sorted(list(text))) if __name__ == "__main__": main()
replace
6
13
6
13
TLE
p02947
Python
Runtime Error
N = int(input()) ans = 0 S = {} for i in range(N): s = "".join(sorted(input())) if s not in S.keys(): S[s] = 0 continue print(S) S[s] += 1 ans += S[s] print(ans)
N = int(input()) ans = 0 S = {} for i in range(N): s = "".join(sorted(input())) if s not in S.keys(): S[s] = 0 continue S[s] += 1 ans += S[s] print(ans)
delete
8
9
8
8
0
p02947
Python
Runtime Error
#!/usr/bin/env python3 acc = [0] * 11 for i in range(10): acc[i + 1] = acc[i] + (i + 1) n = int(input()) s = [input() for _ in range(n)] dic = {} for i in range(n): srt = "".join(sorted(s[i])) dic[srt] = dic[srt] + 1 if srt in dic else 1 ans = 0 for v in dic.values(): ans += acc[v - 1] print(ans)
#!/usr/bin/env python3 acc = [0] * (10**5 + 1) for i in range(10**5): acc[i + 1] = acc[i] + (i + 1) n = int(input()) s = [input() for _ in range(n)] dic = {} for i in range(n): srt = "".join(sorted(s[i])) dic[srt] = dic[srt] + 1 if srt in dic else 1 ans = 0 for v in dic.values(): ans += acc[v - 1] print(ans)
replace
1
3
1
3
0
p02947
Python
Time Limit Exceeded
n = int(input()) SET = set() dict = {} ans = 0 for i in range(n): s = list(input()) s.sort() s = str(s) if s in SET: if s in dict: dict[s] += 1 else: dict[s] = 1 SET.add(s) for i in dict.values(): ans += i * (i + 1) // 2 print(ans)
import sys input = sys.stdin.readline n = int(input()) SET = set() dict = {} ans = 0 for i in range(n): s = list(input()) s.sort() s = str(s) if s in SET: if s in dict: dict[s] += 1 else: dict[s] = 1 SET.add(s) for i in dict.values(): ans += i * (i + 1) // 2 print(ans)
insert
0
0
0
4
TLE
p02947
Python
Time Limit Exceeded
x = [] cnt = 0 for _ in range(int(input())): a = sorted(input()) cnt += x.count(a) x.append(a) print(cnt)
import collections n = int(input()) x = ["".join(sorted(input())) for _ in range(n)] a = collections.Counter(x) print(sum(i * ~-i // 2 for i in a.values()))
replace
0
7
0
6
TLE
p02947
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; #define lb lower_bound #define ub upper_bound #define pb push_back #define popb pop_back #define mem(a, b) memset(a, b, sizeof(a)) #define i first #define j second #define inf 2e9 #define MOD 1000000007 #define M 100007 void FAST() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); } void solve() {} bool cmp(string s, string t) { int x = s.compare(t); if (x <= 0) return 1; return 0; } int main() { FAST(); ll n; cin >> n; string arr[n + 1]; for (int i = 0; i < n; ++i) { cin >> arr[i]; sort(arr[i].begin(), arr[i].end()); } sort(arr, arr + n, cmp); ll ans = 0; int i = 0; while (i < n) { int j = i + 1; while (j < n && arr[i].compare(arr[j]) == 0) { ++j; } // cout<<i<<" "<<j<<"\n"; ans += ((j - i) * 1LL * (j - i - 1)) / 2; i = j; } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; #define lb lower_bound #define ub upper_bound #define pb push_back #define popb pop_back #define mem(a, b) memset(a, b, sizeof(a)) #define i first #define j second #define inf 2e9 #define MOD 1000000007 #define M 100007 void FAST() { std::ios_base::sync_with_stdio(false); cin.tie(NULL); } void solve() {} bool cmp(string s, string t) { int x = s.compare(t); if (x <= 0) return 1; return 0; } int main() { FAST(); ll n; cin >> n; string arr[n + 1]; for (int i = 0; i < n; ++i) { cin >> arr[i]; sort(arr[i].begin(), arr[i].end()); } sort(arr, arr + n); ll ans = 0; int i = 0; while (i < n) { int j = i + 1; while (j < n && arr[i].compare(arr[j]) == 0) { ++j; } // cout<<i<<" "<<j<<"\n"; ans += ((j - i) * 1LL * (j - i - 1)) / 2; i = j; } cout << ans << "\n"; return 0; }
replace
36
37
36
37
0
p02947
C++
Runtime Error
// #pragma GCC optimize(3) #include <algorithm> #include <cassert> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define lowbit(x) x & (-x) typedef long long ll; typedef long double lb; typedef unsigned long long ull; const double PI = acos(-1.0); const int maxn = 1000; int read(); int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); std::vector<string> v(maxn); map<string, int> mp; string str; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> str; sort(str.begin(), str.end()); v.at(i) = str; mp[str]++; } ll ans = 0; for (int i = 0; i < n; i++) { string s = v.at(i); if (mp[s] > 0) ans += mp[s] - 1; mp[s]--; } cout << ans << endl; return 0; } inline int read() { int x = 0, w = 0; char ch = 0; while (!isdigit(ch)) { w |= (ch == '-'); ch = getchar(); } while (isdigit(ch)) { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); } return w ? -x : x; }
// #pragma GCC optimize(3) #include <algorithm> #include <cassert> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define lowbit(x) x & (-x) typedef long long ll; typedef long double lb; typedef unsigned long long ull; const double PI = acos(-1.0); const int maxn = 100005; int read(); int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); std::vector<string> v(maxn); map<string, int> mp; string str; int n; cin >> n; for (int i = 0; i < n; i++) { cin >> str; sort(str.begin(), str.end()); v.at(i) = str; mp[str]++; } ll ans = 0; for (int i = 0; i < n; i++) { string s = v.at(i); if (mp[s] > 0) ans += mp[s] - 1; mp[s]--; } cout << ans << endl; return 0; } inline int read() { int x = 0, w = 0; char ch = 0; while (!isdigit(ch)) { w |= (ch == '-'); ch = getchar(); } while (isdigit(ch)) { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getchar(); } return w ? -x : x; }
replace
25
26
25
26
0
p02947
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #if __has_include("print.hpp") #include "print.hpp" #endif #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define MOD 1000000007 typedef long long ll; typedef pair<int, int> p; struct UnionFind { // 要素に対応する値は自分の根。根は要素数の-1倍したものを代入する。 // 根ならそのグループの要素数(負)が、子であれば親の番号が入る。初期値-1。 vector<int> uni; UnionFind() { uni = vector<int>(100100, -1); } // 頂点aの所属するグループを調べる。 int root(int a) { // uni[a]が負の値なら親はa自身 if (uni[a] < 0) return a; // 正の値であれば、親ルートを調べ戻り値で根に直接つなぐ。 else { uni[a] = root(uni[a]); return uni[a]; // return uni[a] = root(uni[a]); } } // 頂点aとbをつなぐ、もともと同じグループの場合falseを返す。 bool connect(int a, int b) { a = root(a); b = root(b); if (a == b) return false; // aを大きなグループにしたいので、逆であれば入れ替える。 if (uni[a] > uni[b]) { int hoge = a; a = b; b = hoge; } // aとbを結合し、bをaの親とする。 uni[a] += uni[b]; uni[b] = a; return true; } // 頂点a, bが同じグループか bool isConnect(int a, int b) { return root(a) == root(b); } // 頂点aを含むグループの頂点数を調べる int size(int a) { return -uni[root(a)]; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<map<char, int>> v(n); for (int i = 0; i < n; i++) { string tmp; cin >> tmp; for (auto a : tmp) { v[i][a]++; } } ll res = 0; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (v[i] == v[j]) { res++; } } } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; #if __has_include("print.hpp") #include "print.hpp" #endif #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define MOD 1000000007 typedef long long ll; typedef pair<int, int> p; struct UnionFind { // 要素に対応する値は自分の根。根は要素数の-1倍したものを代入する。 // 根ならそのグループの要素数(負)が、子であれば親の番号が入る。初期値-1。 vector<int> uni; UnionFind() { uni = vector<int>(100100, -1); } // 頂点aの所属するグループを調べる。 int root(int a) { // uni[a]が負の値なら親はa自身 if (uni[a] < 0) return a; // 正の値であれば、親ルートを調べ戻り値で根に直接つなぐ。 else { uni[a] = root(uni[a]); return uni[a]; // return uni[a] = root(uni[a]); } } // 頂点aとbをつなぐ、もともと同じグループの場合falseを返す。 bool connect(int a, int b) { a = root(a); b = root(b); if (a == b) return false; // aを大きなグループにしたいので、逆であれば入れ替える。 if (uni[a] > uni[b]) { int hoge = a; a = b; b = hoge; } // aとbを結合し、bをaの親とする。 uni[a] += uni[b]; uni[b] = a; return true; } // 頂点a, bが同じグループか bool isConnect(int a, int b) { return root(a) == root(b); } // 頂点aを含むグループの頂点数を調べる int size(int a) { return -uni[root(a)]; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<map<char, int>> v(n); for (int i = 0; i < n; i++) { string tmp; cin >> tmp; for (auto a : tmp) { v[i][a]++; } } ll res = 0; map<map<char, int>, int> count; for (int i = 0; i < n; i++) { res += count[v[i]]; count[v[i]]++; } cout << res << endl; }
replace
76
82
76
80
TLE
p02947
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; char a[10]; vector<string> s; string t; long long n, i, j, ans = 0; int main() { cin >> n; for (j = 0; j < n; j++) { for (i = 0; i < 10; i++) { cin >> a[i]; } sort(a, a + 10); t = a; s.push_back(t); // cout << s; /*for (i = 0; i < 10; i++){ cout << a[i]; }*/ } sort(s.begin(), s.end()); // cout << s[0] << endl; j = 0; for (i = 0; i < n - 1; i++) { while (j < n && (s[i] == s[j + 1] || j < i)) { j++; } if (s[i] == s[j]) ans += j - i; if (i == j) j++; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; char a[10]; vector<string> s; string t; long long n, i, j, ans = 0; int main() { cin >> n; for (j = 0; j < n; j++) { for (i = 0; i < 10; i++) { cin >> a[i]; } sort(a, a + 10); t = a; s.push_back(t); // cout << s; /*for (i = 0; i < 10; i++){ cout << a[i]; }*/ } sort(s.begin(), s.end()); // cout << s[0] << endl; j = 0; for (i = 0; i < n - 1; i++) { while (j < n - 1 && (s[i] == s[j + 1] || j < i)) { j++; } if (s[i] == s[j]) ans += j - i; if (i == j) j++; } cout << ans << endl; return 0; }
replace
25
26
25
26
0
p02947
C++
Time Limit Exceeded
#define _USE_MATH_DEFINES #include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long LL; typedef vector<int> VI; typedef vector<double> VD; typedef vector<LL> VLL; typedef vector<string> VS; typedef vector<bool> VB; typedef vector<vector<int>> VVI; typedef vector<vector<bool>> VVB; typedef vector<vector<double>> VVD; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define all(a) (a).begin(), (a).end() const int MOD = 1000000007; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } int main() { int n; cin >> n; VS s(n); rep(i, n) cin >> s.at(i); rep(i, n) { sort(all(s.at(i))); } LL ans = 0; rep(i, n) { for (int j = i + 1; j < n; j++) { if (s.at(i) == s.at(j)) ans++; } } cout << ans << endl; return 0; }
#define _USE_MATH_DEFINES #include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long LL; typedef vector<int> VI; typedef vector<double> VD; typedef vector<LL> VLL; typedef vector<string> VS; typedef vector<bool> VB; typedef vector<vector<int>> VVI; typedef vector<vector<bool>> VVB; typedef vector<vector<double>> VVD; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define all(a) (a).begin(), (a).end() const int MOD = 1000000007; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } int main() { int n; cin >> n; VS s(n); rep(i, n) cin >> s.at(i); rep(i, n) { sort(all(s.at(i))); } LL ans = 0; map<string, int> mp; rep(i, n) { mp[s.at(i)]++; } for (auto itr = mp.begin(); itr != mp.end(); itr++) { LL m = itr->second; ans += m * (m - 1) / 2; } cout << ans << endl; return 0; }
replace
52
57
52
57
TLE
p02947
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <math.h> using namespace std; int main(void) { int n; long long ans = 0; cin >> n; string s[n]; for (int i = 0; i < n; i++) { cin >> s[i]; sort(s[i].begin(), s[i].end()); } for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (s[i] == s[j]) ans++; } } cout << ans; }
#include <bits/stdc++.h> #include <math.h> using namespace std; int main(void) { int n; long long ans = 0; cin >> n; string s[n]; for (int i = 0; i < n; i++) { cin >> s[i]; sort(s[i].begin(), s[i].end()); } sort(s, s + n); long long x = 0; for (int i = 1; i < n; i++) { if (s[i - 1] == s[i]) { x++; if (i == n - 1) { ans += (x * (x + 1)) / 2; break; } } else { ans += (x * (x + 1)) / 2; x = 0; } } cout << ans; }
replace
13
17
13
25
TLE
p02947
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { int N; cin >> N; vector<string> s(N); rep(i, N) cin >> s[i]; int ans = 0; rep(k, N) { rep(i, 10) { if (s[1][i] == s[k][i]) { s[k].erase(s[k].begin() + i); } } if (sizeof(s[k]) == 0) { ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { int n; cin >> n; map<string, int> mp; rep(i, n) { string s; cin >> s; sort(s.begin(), s.end()); mp[s]++; } ll ans = 0; for (auto &p : mp) { int s = p.second; ans += (ll)s * (s - 1) / 2; } cout << ans << endl; return 0; }
replace
6
20
6
19
-11
p02947
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; // 総数を1000000007(素数)で割った余り const long long mod = 1e9 + 7; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; #define ull unsigned long long #define ld long double #define vi vector<int> #define vll vector<ll> #define vc vector<char> #define vs vector<string> #define vpii vector<pii> #define vpll vector<pll> #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++) #define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++) #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define RSORT(x) sort(rall(x)); #define pb push_back #define mp make_pair #define INF (1e9) #define PI (acos(-1)) #define EPS (1e-7) ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; } ull lcm(ull a, ull b) { return a / gcd(a, b) * b; } int main() { int n; cin >> n; vs s(n); rep(i, n) cin >> s[i]; vector<map<char, int>> sm(n); rep(i, n) { rep(j, 10) sm[i][s[i][j]]++; } int ans = 0; rep(i, n - 1) for (int j = i + 1; j < n; ++j) { if (sm[i] == sm[j]) ++ans; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // 総数を1000000007(素数)で割った余り const long long mod = 1e9 + 7; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; #define ull unsigned long long #define ld long double #define vi vector<int> #define vll vector<ll> #define vc vector<char> #define vs vector<string> #define vpii vector<pii> #define vpll vector<pll> #define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++) #define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++) #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--) #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--) #define sz(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define RSORT(x) sort(rall(x)); #define pb push_back #define mp make_pair #define INF (1e9) #define PI (acos(-1)) #define EPS (1e-7) ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; } ull lcm(ull a, ull b) { return a / gcd(a, b) * b; } int main() { int n; cin >> n; map<string, int> sm; rep(i, n) { string s; cin >> s; sort(all(s)); sm[s]++; } auto sigma = [&](int n) { ll ans = 0; rep1(i, n) ans += i; return ans; }; ll ans = 0; for (pair<string, int> num : sm) { ans += sigma(num.second - 1); } cout << ans << endl; return 0; }
replace
43
51
43
58
TLE
p02947
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif int n; cin >> n; string s[n]; ll sum = 0; map<string, ll> mp; for (int i = 0; i < n; i++) { cin >> s[i]; sort(s[i].begin(), s[i].end()); if (mp[s[i]]) { sum += mp[s[i]]; } mp[s[i]]++; } cout << sum << endl; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; string s[n]; ll sum = 0; map<string, ll> mp; for (int i = 0; i < n; i++) { cin >> s[i]; sort(s[i].begin(), s[i].end()); if (mp[s[i]]) { sum += mp[s[i]]; } mp[s[i]]++; } cout << sum << endl; return 0; }
delete
7
11
7
7
-11
p02947
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; typedef pair<int, int> P; int main(void) { int n; cin >> n; vector<string> s(n); rep(i, n) cin >> s.at(i); rep(i, n) { sort(s.at(i).begin(), s.at(i).end()); } int ans = 0; rep(i, n - 1) { for (int j = i + 1; j < n; j++) { if (s.at(i) == s.at(j)) ans++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; typedef pair<int, int> P; int main(void) { int n; cin >> n; map<string, int> mp; rep(i, n) { string s; cin >> s; sort(s.begin(), s.end()); mp[s]++; } ll ans = 0; for (auto &p : mp) { ll s = p.second; ans += s * (s - 1) / 2; } cout << ans << endl; return 0; }
replace
9
18
9
20
TLE
p02947
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { ll n; cin >> n; vector<string> s(n); rep(i, n) { cin >> s[i]; sort(s[i].begin(), s[i].end()); } sort(s.begin(), s.end()); int c = 0; int ans = 0; for (int i = 0; i < n; i++) { if (s[i] != s[i - 1]) { ans = ans + (c * (c + 1)) / 2; c = 0; } else { c++; } } ans = ans + (c * (c + 1)) / 2; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { ll n; cin >> n; vector<string> s(n); rep(i, n) { cin >> s[i]; sort(s[i].begin(), s[i].end()); } sort(s.begin(), s.end()); ll c = 0; ll ans = 0; rep(i, n - 1) { if (s[i] != s[i + 1]) { ans = ans + (c * (c + 1)) / 2; c = 0; } else { c++; } } ans = ans + (c * (c + 1)) / 2; cout << ans << endl; return 0; }
replace
14
18
14
18
0
p02947
C++
Runtime Error
// Garg's Code #include <bits/stdc++.h> using namespace std; #define set set<ll> #define ll long long #define ldb long double; #define pa pair<ll, ll> // #define map map < ll, ll > #define vec vector<ll> #define pb push_back #define po pop_back #define mp make_pair #define mt make_tuple #define F first #define S second #define f(i, x, n) for (ll i = x; i < n; i++) #define unique_sort(x) \ sort(all(x)), x.resize(distance(x.begin(), unique(all(x)))) #define all(c) c.begin(), c.end() #define str string #define edl "\n" #define add insert #define cot continue #define fast() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10; #define llong 1e9 + 7 #define lsmall -1e9 + 7 const double PI = acos(-1); const ll LINF = LLONG_MAX; int main() { fast(); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll n, ans = 0; cin >> n; vector<string> v; map<string, ll> m; string s; f(i, 0, n) { cin >> s; sort(s.begin(), s.end()); // cout << s << endl; v.pb(s); m[s] = 0; } f(i, 0, n) { m[v[i]] += 1; // cout << m[v[i]] << " "; } map<string, ll>::iterator j; for (j = m.begin(); j != m.end(); j++) { // cout << j->second << " "; ll p = j->second; ans += p * (p - 1) / 2; } cout << ans; return 0; }
// Garg's Code #include <bits/stdc++.h> using namespace std; #define set set<ll> #define ll long long #define ldb long double; #define pa pair<ll, ll> // #define map map < ll, ll > #define vec vector<ll> #define pb push_back #define po pop_back #define mp make_pair #define mt make_tuple #define F first #define S second #define f(i, x, n) for (ll i = x; i < n; i++) #define unique_sort(x) \ sort(all(x)), x.resize(distance(x.begin(), unique(all(x)))) #define all(c) c.begin(), c.end() #define str string #define edl "\n" #define add insert #define cot continue #define fast() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10; #define llong 1e9 + 7 #define lsmall -1e9 + 7 const double PI = acos(-1); const ll LINF = LLONG_MAX; int main() { fast(); ll n, ans = 0; cin >> n; vector<string> v; map<string, ll> m; string s; f(i, 0, n) { cin >> s; sort(s.begin(), s.end()); // cout << s << endl; v.pb(s); m[s] = 0; } f(i, 0, n) { m[v[i]] += 1; // cout << m[v[i]] << " "; } map<string, ll>::iterator j; for (j = m.begin(); j != m.end(); j++) { // cout << j->second << " "; ll p = j->second; ans += p * (p - 1) / 2; } cout << ans; return 0; }
delete
36
40
36
36
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02947
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<string> s(n); for (int i = 0; i < n; i++) { cin >> s[i]; sort(s[i].begin(), s[i].end()); } sort(s.begin(), s.end()); int count = 0; long long int ans = 0; // for (int i = 0; i < n; i++) { if (s[i - 1] == s[i]) { count++; ans += count; } else count = 0; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<string> s(n); for (int i = 0; i < n; i++) { cin >> s[i]; sort(s[i].begin(), s[i].end()); } sort(s.begin(), s.end()); int count = 0; long long int ans = 0; // for (int i = 1; i < n; i++) { if (s[i - 1] == s[i]) { count++; ans += count; } else count = 0; } cout << ans << endl; return 0; }
replace
25
26
25
26
0
p02947
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; #define INF LONG_MAX #define MOD 1000000007 #define rng(a) a.begin(), a.end() #define rrng(a) a.end(), a.begin() #define int ll signed main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vector<string> s(N); for (int i = 0; i < N; i++) cin >> s[i]; for (int i = 0; i < N; i++) sort(rng(s[i])); sort(rng(s)); int ans = 0; for (int i = 0; i < N; i++) { while (s[i] == s[i + 1]) { ans += i; i++; } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; #define INF LONG_MAX #define MOD 1000000007 #define rng(a) a.begin(), a.end() #define rrng(a) a.end(), a.begin() #define int ll signed main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vector<string> s(N); for (int i = 0; i < N; i++) cin >> s[i]; for (int i = 0; i < N; i++) sort(rng(s[i])); sort(rng(s)); int ans = 0; for (int i = 0; i < N; i++) { int now = i; while (i + 1 < N && s[i] == s[i + 1]) { ans += i - now + 1; i++; } } cout << ans << endl; return 0; }
replace
27
29
27
30
0
p02947
C++
Runtime Error
#include <bits/stdc++.h> #define INF 1e18 #define int long long #define Rep(i, a, n) for (int i = (a); i < (n); i++) #define rep(i, n) Rep(i, 0, n) #define all(a) (a).begin(), (a).end() using namespace std; typedef pair<int, int> P; typedef pair<int, P> PP; const int mod = 1000000007; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<string> s(n); rep(i, n) cin >> s[i]; rep(i, n) sort(all(s[i])); sort(all(s)); int ans = 0, cnt = 1; rep(i, n) { if (s[i] == s[i + 1]) cnt++; else { ans += (cnt * (cnt - 1)) / 2; cnt = 1; } } cout << ans << endl; }
#include <bits/stdc++.h> #define INF 1e18 #define int long long #define Rep(i, a, n) for (int i = (a); i < (n); i++) #define rep(i, n) Rep(i, 0, n) #define all(a) (a).begin(), (a).end() using namespace std; typedef pair<int, int> P; typedef pair<int, P> PP; const int mod = 1000000007; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<string> s(n); rep(i, n) cin >> s[i]; rep(i, n) sort(all(s[i])); sort(all(s)); s.push_back("HOGE"); int ans = 0, cnt = 1; rep(i, n) { if (s[i] == s[i + 1]) cnt++; else { ans += (cnt * (cnt - 1)) / 2; cnt = 1; } } cout << ans << endl; }
insert
21
21
21
22
0
p02947
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define mod 1000000007 #define f(i, a, b) for (ll i = a; i < b; i++) #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define ii pair<ll, ll> #define vii vector<ii> #define F first #define S second #define pb push_back #define mp make_pair #define MAX 1e9 ll modpow(ll base, ll exp, ll modulus) { base %= modulus; ll result = 1; while (exp > 0) { if (exp & 1) result = (result * base) % modulus; base = (base * base) % modulus; exp >>= 1; } return result; } const ld pi = acos(-1); int main() { IOS; ll n; cin >> n; vector<string> v; f(i, 0, n) { string s; cin >> s; sort(s.begin(), s.end()); v.pb(s); } sort(v.begin(), v.end()); ll cnt = 1, ans = 0; // f(i,0,v.size())cout<<v[i]<<" "; f(i, 1, v.size()) { if (v[i] == v[i - 1]) while (v[i] == v[i - 1]) { cnt++; i++; } ans += (cnt * (cnt - 1)) / 2; cnt = 1; // cout<<ans<<" "; } cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define mod 1000000007 #define f(i, a, b) for (ll i = a; i < b; i++) #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define ii pair<ll, ll> #define vii vector<ii> #define F first #define S second #define pb push_back #define mp make_pair #define MAX 1e9 ll modpow(ll base, ll exp, ll modulus) { base %= modulus; ll result = 1; while (exp > 0) { if (exp & 1) result = (result * base) % modulus; base = (base * base) % modulus; exp >>= 1; } return result; } const ld pi = acos(-1); int main() { IOS; ll n; cin >> n; vector<string> v; f(i, 0, n) { string s; cin >> s; sort(s.begin(), s.end()); v.pb(s); } sort(v.begin(), v.end()); ll cnt = 1, ans = 0; // f(i,0,v.size())cout<<v[i]<<" "; f(i, 1, v.size()) { if (v[i] == v[i - 1]) while (i < v.size() && v[i] == v[i - 1]) { cnt++; i++; } ans += (cnt * (cnt - 1)) / 2; cnt = 1; // cout<<ans<<" "; } cout << ans; return 0; }
replace
47
48
47
48
0
p02947
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> typedef int ll; using namespace __gnu_pbds; using namespace std; #define pb push_back #define mp make_pair #define ff first #define ss second #define len(v) ((int)v.size()) #define all(v) v.begin(), v.end() #define oset \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define orz \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define inp \ freopen("input.txt", "r", stdin); \ freopen("out.txt", "w", stdout); ll mod1 = 1e9 + 7; void io() { ios_base::sync_with_stdio(false); cin.tie(NULL); // cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif } int main() { orz; inp; int n, i, j, k; cin >> n; map<string, int> mp; string s; uint64_t count = 0; for (int i = 0; i < n; i++) { cin >> s; sort(s.begin(), s.end()); count += mp[s]; mp[s]++; } cout << count; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> typedef int ll; using namespace __gnu_pbds; using namespace std; #define pb push_back #define mp make_pair #define ff first #define ss second #define len(v) ((int)v.size()) #define all(v) v.begin(), v.end() #define oset \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define orz \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define inp \ freopen("input.txt", "r", stdin); \ freopen("out.txt", "w", stdout); ll mod1 = 1e9 + 7; void io() { ios_base::sync_with_stdio(false); cin.tie(NULL); // cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif } int main() { orz; // inp; int n, i, j, k; cin >> n; map<string, int> mp; string s; uint64_t count = 0; for (int i = 0; i < n; i++) { cin >> s; sort(s.begin(), s.end()); count += mp[s]; mp[s]++; } cout << count; }
replace
35
36
35
36
TLE
p02947
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define pb push_back #define all(v) v.begin(), v.end() #define fi first #define se second #define bigger (char)toupper #define smaller (char)tolower using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vii; typedef long long ll; typedef unsigned long long ull; int main() { ll N, K; cin >> N >> K; vector<ll> h(N); for (ll i = 0; i < N; i++) cin >> h.at(i); sort(h.begin(), h.end()); ll mini = h.at(K - 1); ll maxi = h.at(N - K); ll A = mini - h.at(0); ll B = h.at(N - 1) - maxi; cout << min(A, B) << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define pb push_back #define all(v) v.begin(), v.end() #define fi first #define se second #define bigger (char)toupper #define smaller (char)tolower using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vii; typedef long long ll; typedef unsigned long long ull; int main() { int N; cin >> N; map<string, ll> mp; rep(i, N) { string w; cin >> w; sort(all(w)); mp[w]++; } ll answer = 0; for (auto p : mp) { ll a = p.se; answer += a * (a - 1) / 2; } cout << answer << endl; }
replace
16
27
16
31
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 18446744073709551615) >= this->size() (which is 3)
p02947
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); ++i) int main() { int N; cin >> N; vector<string> s(N); rep(i, N) { cin >> s[i]; sort(s[i].begin(), s[i].end()); } // sort済みの文字列をソートする sort(s.begin(), s.end()); ll ans = 0; for (int i = 0; i < N; i++) { ll cnt = 0; for (int j = i + 1; j < N; j++) { if (s[i] == s[j]) { cnt++; ans += cnt; } else { i = j - 1; // loopを抜けたあとi++されるので-1して帳尻を合わせる break; } } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, n) for (int i = 0; i < (n); ++i) int main() { int N; cin >> N; vector<string> s(N); rep(i, N) { cin >> s[i]; sort(s[i].begin(), s[i].end()); } // sort済みの文字列をソートする sort(s.begin(), s.end()); ll ans = 0; for (int i = 0; i < N; i++) { ll cnt = 0; for (int j = i + 1; j < N; j++) { if (s[i] == s[j]) { cnt++; ans += cnt; if (j == N - 1) { i = N - 1; } } else { i = j - 1; // loopを抜けたあとi++されるので-1して帳尻を合わせる break; } } } cout << ans << endl; return 0; }
insert
22
22
22
25
TLE
p02947
C++
Runtime Error
#include <bits/stdc++.h> #define int long long #define boost() \ ios_base ::sync_with_stdio(0); \ cin.tie(); \ cout.tie(); \ cout << fixed; \ cout << setprecision(15); \ srand(time(NULL)) #define all(x) x.begin(), x.end() using namespace std; vector<string> s; int n; signed main() { cin >> n; for (int i = 0; i < n; i++) { string cur; cin >> cur; sort(all(cur)); s.push_back(cur); } sort(all(s)); int res = 0; int i = 0, j = 0; while (i < n && j < n) { while (s[i] == s[j]) j++; int x = j - i; res += (x * (x - 1)) / 2; i = j; } cout << res << endl; return 0; }
#include <bits/stdc++.h> #define int long long #define boost() \ ios_base ::sync_with_stdio(0); \ cin.tie(); \ cout.tie(); \ cout << fixed; \ cout << setprecision(15); \ srand(time(NULL)) #define all(x) x.begin(), x.end() using namespace std; vector<string> s; int n; signed main() { cin >> n; for (int i = 0; i < n; i++) { string cur; cin >> cur; sort(all(cur)); s.push_back(cur); } sort(all(s)); int res = 0; int i = 0, j = 0; while (i < n && j < n) { while (j < n && s[i] == s[j]) j++; int x = j - i; res += (x * (x - 1)) / 2; i = j; } cout << res << endl; return 0; }
replace
27
28
27
28
0
p02947
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> #include <vector> void strsort(std::string &s) { std::vector<char> tmp; for (int i = 0; i < s.size(); i++) tmp.push_back(s[i]); std::sort(tmp.begin(), tmp.end()); for (int i = 0; i < s.size(); i++) s[i] = tmp[i]; } int main() { int N; std::cin >> N; std::vector<std::string> s(N); for (int i = 0; i < N; i++) { std::cin >> s[i]; strsort(s[i]); } std::sort(s.begin(), s.end()); long long count = 0; std::vector<long long> vcount; for (int i = 0; i < N; i++) { count++; if (i == N || (i != N && s[i] != s[i + 1])) { vcount.push_back(count); count = 0; } } long long ans = 0; for (auto &&itr = vcount.begin(); itr != vcount.end(); itr++) { long long c = (*itr); ans += c * (c - 1) / 2; } std::cout << ans << std::endl; }
#include <algorithm> #include <iostream> #include <string> #include <vector> void strsort(std::string &s) { std::vector<char> tmp; for (int i = 0; i < s.size(); i++) tmp.push_back(s[i]); std::sort(tmp.begin(), tmp.end()); for (int i = 0; i < s.size(); i++) s[i] = tmp[i]; } int main() { int N; std::cin >> N; std::vector<std::string> s(N); for (int i = 0; i < N; i++) { std::cin >> s[i]; strsort(s[i]); } std::sort(s.begin(), s.end()); long long count = 0; std::vector<long long> vcount; for (int i = 0; i < N; i++) { count++; if (i == N - 1 || (i != N - 1 && s[i] != s[i + 1])) { vcount.push_back(count); count = 0; } } long long ans = 0; for (auto &&itr = vcount.begin(); itr != vcount.end(); itr++) { long long c = (*itr); ans += c * (c - 1) / 2; } std::cout << ans << std::endl; }
replace
28
29
28
29
0
p02947
C++
Runtime Error
#include <algorithm> #include <iostream> #include <stdio.h> #include <string.h> #include <vector> #define Max 2 * 100002 using namespace std; vector<string> vec; int main() { int n, i; string s; scanf("%d", &n); for (i = 0; i < n; i++) { cin >> s; sort(s.begin(), s.end()); vec.push_back(s); } sort(vec.begin(), vec.end()); long long int ans = 0, val = 0; for (i = 0; i < n; i++) { if (vec[i] == vec[i + 1]) val++; else { ans += (val * (val + 1)) / 2; val = 0; } } if (val > 0) ans += (val * (val + 1)) / 2; printf("%lld\n", ans); return 0; }
#include <algorithm> #include <iostream> #include <stdio.h> #include <string.h> #include <vector> #define Max 2 * 100002 using namespace std; vector<string> vec; int main() { int n, i; string s; scanf("%d", &n); for (i = 0; i < n; i++) { cin >> s; sort(s.begin(), s.end()); vec.push_back(s); } sort(vec.begin(), vec.end()); long long int ans = 0, val = 0; for (i = 0; i < n - 1; i++) { if (vec[i] == vec[i + 1]) val++; else { ans += (val * (val + 1)) / 2; val = 0; } } if (val > 0) ans += (val * (val + 1)) / 2; printf("%lld\n", ans); return 0; }
replace
25
26
25
26
0
p02947
C++
Runtime Error
#include <bits/stdc++.h> typedef long long int ll; using namespace std; const ll N = 2000009; const ll p = 31; const ll m = 1e9 + 7; const ll inf = 1e14; ll mod = 1e9 + 7; ll powm(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; } vector<ll> g[N]; ll score[N]; void dfs(ll v, ll p) { score[v] += score[p]; for (auto u : g[v]) { if (u == p) continue; dfs(u, v); } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll t = 1; // cin>>t; while (t--) { ll n; cin >> n; map<vector<ll>, ll> a; for (int i = 0; i < n; i++) { string s; cin >> s; vector<ll> ct(26, 0); for (int i = 0; i < 10; i++) { ct[s[i] - 'a']++; } a[ct]++; } ll ans = 0; map<vector<ll>, ll>::iterator i; for (i = a.begin(); i != a.end(); i++) { ll temp = i->second * (i->second - 1); temp = temp / 2; ans += temp; } cout << ans; } }
#include <bits/stdc++.h> typedef long long int ll; using namespace std; const ll N = 2000009; const ll p = 31; const ll m = 1e9 + 7; const ll inf = 1e14; ll mod = 1e9 + 7; ll powm(ll a, ll b) { ll res = 1; while (b) { if (b & 1) res = (res * a) % mod; a = (a * a) % mod; b >>= 1; } return res; } vector<ll> g[N]; ll score[N]; void dfs(ll v, ll p) { score[v] += score[p]; for (auto u : g[v]) { if (u == p) continue; dfs(u, v); } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif ll t = 1; // cin>>t; while (t--) { ll n; cin >> n; map<vector<ll>, ll> a; for (int i = 0; i < n; i++) { string s; cin >> s; vector<ll> ct(26, 0); for (int i = 0; i < 10; i++) { ct[s[i] - 'a']++; } a[ct]++; } ll ans = 0; map<vector<ll>, ll>::iterator i; for (i = a.begin(); i != a.end(); i++) { ll temp = i->second * (i->second - 1); temp = temp / 2; ans += temp; } cout << ans; } }
replace
33
37
33
37
-11
p02947
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> #include <math.h> using namespace std; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int64_t cx(int64_t i) { int64_t res = 1; while (i > 1) { res = res * i; i--; } return res; } int main() { int64_t N; cin >> N; map<string, int64_t> d; for (int64_t i = 0; i < N; i++) { string s; cin >> s; sort(s.begin(), s.end()); if (d.count(s) > 0) { d[s] = d[s] + 1; } else { d[s] = 1; } } int64_t sum_count = 0; for (auto c : d) { if (c.second > 2) { sum_count += cx(c.second) / (cx(c.second - 2) * 2); } else if (c.second == 2) { sum_count += 1; } } cout << sum_count << endl; return 0; }
#include <bits/stdc++.h> #include <iostream> #include <math.h> using namespace std; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int64_t cx(int64_t i) { int64_t res = 1; while (i > 1) { res = res * i; i--; } return res; } int main() { int64_t N; cin >> N; map<string, int64_t> d; for (int64_t i = 0; i < N; i++) { string s; cin >> s; sort(s.begin(), s.end()); if (d.count(s) > 0) { d[s] = d[s] + 1; } else { d[s] = 1; } } int64_t sum_count = 0; for (auto c : d) { if (c.second > 2) { int64_t i = c.second; while (i > 1) { sum_count += i - 1; i--; } } else if (c.second == 2) { sum_count += 1; } } cout << sum_count << endl; return 0; }
replace
47
48
47
52
0
p02947
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <string> using ll = long long; #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int n; cin >> n; map<string, int> x; rep(i, n) { string s; cin >> s; sort(s.begin(), s.end()); bool flag = true; for (auto itr = x.begin(); itr != x.end(); itr++) { if (s == itr->first) { itr->second++; flag = false; break; } } if (flag) x[s] = 1; } ll ans = 0; for (auto itr = x.begin(); itr != x.end(); itr++) { ll n = itr->second; ans += n * (n - 1) / 2; } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <map> #include <string> using ll = long long; #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; int main() { int n; cin >> n; map<string, int> x; rep(i, n) { string s; cin >> s; sort(s.begin(), s.end()); auto itr = x.find(s); if (itr != x.end()) itr->second++; else x[s] = 1; } ll ans = 0; for (auto itr = x.begin(); itr != x.end(); itr++) { ll n = itr->second; ans += n * (n - 1) / 2; } cout << ans << endl; return 0; }
replace
17
26
17
21
TLE
p02947
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <complex> #include <cstdlib> #include <functional> #include <iostream> #include <map> #include <numeric> #include <set> #include <string> #include <vector> using namespace std; using Int = long long; Int INF = 1LL << 60; const Int MOD = 1000000007; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Int N; cin >> N; vector<string> s(N); for (Int i = 0; i < N; i++) { cin >> s[i]; sort(s[i].begin(), s[i].end()); } sort(s.begin(), s.end()); Int ans = 0; string tmep; for (Int i = 0; i < N - 1; i++) { for (Int j = i + 1; j < N; j++) { if (s[i] == s[j]) ans++; else break; } } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <complex> #include <cstdlib> #include <functional> #include <iostream> #include <map> #include <numeric> #include <set> #include <string> #include <vector> using namespace std; using Int = long long; Int INF = 1LL << 60; const Int MOD = 1000000007; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); Int N; cin >> N; vector<string> s(N); for (Int i = 0; i < N; i++) { cin >> s[i]; sort(s[i].begin(), s[i].end()); } sort(s.begin(), s.end()); Int ans = 0; Int i = 0; while (i < N - 1) { Int start = i; Int end = 0; i++; while ((i < N) && (s[start] == s[i])) { end = i; i++; } Int j = end - start; while (j > 0) { ans += j; j--; } } cout << ans << endl; }
replace
34
41
34
50
TLE
p02947
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { int N; cin >> N; vector<string> S(N); for (int i = 0; i < N; i++) { cin >> S[i]; } for (int i = 0; i < N; i++) { sort(S[i].begin(), S[i].end()); } sort(S.begin(), S.end()); ll ans = 0; ll index = 0; while (index < N) { string head = S[index]; ll move = 1; while (S[index + move] == head && index + move < N) { move++; } ans += move * (move - 1) / 2; index += move; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { int N; cin >> N; vector<string> S(N); for (int i = 0; i < N; i++) { cin >> S[i]; } for (int i = 0; i < N; i++) { sort(S[i].begin(), S[i].end()); } sort(S.begin(), S.end()); ll ans = 0; ll index = 0; while (index < N) { string head = S[index]; ll move = 1; while (index + move < N && S[index + move] == head) { move++; } ans += move * (move - 1) / 2; index += move; } cout << ans << endl; return 0; }
replace
26
27
26
27
0
p02947
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define rev(i, n) for (int i = n; i >= 0; i--) #define Rep(i, m, n) for (int i = m; i < n; i++) #define repeatrev(i, m, n) for (int i = m; i >= n; i--) #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define ll long long #define pb(a) push_back(a) #define INF 999999999 #define itn int #define FORR(i, a, b) for (int i = (b)-1; i >= (a); --i) using namespace std; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef pair<int, P> PP; typedef pair<ll, LP> LPP; typedef priority_queue<int> Pr; const int MOD = 9999973; int dy[] = {0, 0, 1, -1, 0}; int dx[] = {1, -1, 0, 0, 0}; // 二項係数の計算をしたい時用 const int MAX = 5100000; unsigned long long fac[MAX], finv[MAX], inv[MAX]; unsigned ll kaijyo(ll n) { if (n == 0) return 1; return n * kaijyo(n - 1); } unsigned ll ansans(ll n, ll k) { return kaijyo(n) / kaijyo(n - k) / kaijyo(k); } ll fact[MAX], fact_inv[MAX]; // 繰り返し二乗法 ll power(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } ll comb(ll n, ll r) { return (fact[n] * fact_inv[r]) * fact_inv[n - r]; } // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { ios::sync_with_stdio(false); cin.tie(0); COMinit(); int n; cin >> n; int offset; offset = 'a'; int a[n][29]; rep(i, n) { rep(j, 29) a[i][j] = 0; } rep(i, n) { string s; cin >> s; rep(j, 10) { a[i][s[j] - offset]++; } } unsigned ll ans = 0; map<string, int> dict; rep(i, n) { int g = 0; int hh = 0; string s = " "; int place = 0; rep(j, 26) { int gg = 0; gg = a[i][j]; while (gg != 0) { s[hh] = (char)(offset + j); hh++; // cout << s[i] << endl; // s[i] = SS; gg--; } } // cout << s << endl; dict[s]++; } /* if(g == 0){ } } rep(i, n - 1){ Rep(j, i + 1, n){ int g = 0; rep(s, 29){ if(a[i][s] != a[j][s]) g = 1; } if(g == 0){ //cout << i << " " << j << endl; ans ++; } } }*/ for (auto i = dict.begin(); i != dict.end(); ++i) { int ggg = i->second; // cout << i->first << " " << ggg << endl; // cout << ggg << endl; if (ggg >= 2) ans += ansans(ggg, 2); } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define rev(i, n) for (int i = n; i >= 0; i--) #define Rep(i, m, n) for (int i = m; i < n; i++) #define repeatrev(i, m, n) for (int i = m; i >= n; i--) #define SORT(v, n) sort(v, v + n); #define VSORT(v) sort(v.begin(), v.end()); #define ll long long #define pb(a) push_back(a) #define INF 999999999 #define itn int #define FORR(i, a, b) for (int i = (b)-1; i >= (a); --i) using namespace std; typedef pair<int, int> P; typedef pair<ll, ll> LP; typedef pair<int, P> PP; typedef pair<ll, LP> LPP; typedef priority_queue<int> Pr; const int MOD = 9999973; int dy[] = {0, 0, 1, -1, 0}; int dx[] = {1, -1, 0, 0, 0}; // 二項係数の計算をしたい時用 const int MAX = 5100000; unsigned long long fac[MAX], finv[MAX], inv[MAX]; unsigned ll kaijyo(ll n) { if (n == 0) return 1; return n * kaijyo(n - 1); } unsigned ll ansans(ll n, ll k) { return kaijyo(n) / kaijyo(n - k) / kaijyo(k); } ll fact[MAX], fact_inv[MAX]; // 繰り返し二乗法 ll power(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } ll comb(ll n, ll r) { return (fact[n] * fact_inv[r]) * fact_inv[n - r]; } // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (int i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { ios::sync_with_stdio(false); cin.tie(0); COMinit(); int n; cin >> n; int offset; offset = 'a'; int a[n][29]; rep(i, n) { rep(j, 29) a[i][j] = 0; } rep(i, n) { string s; cin >> s; rep(j, 10) { a[i][s[j] - offset]++; } } unsigned ll ans = 0; map<string, int> dict; rep(i, n) { int g = 0; int hh = 0; string s = " "; int place = 0; rep(j, 26) { int gg = 0; gg = a[i][j]; while (gg != 0) { s[hh] = (char)(offset + j); hh++; // cout << s[i] << endl; // s[i] = SS; gg--; } } // cout << s << endl; dict[s]++; } /* if(g == 0){ } } rep(i, n - 1){ Rep(j, i + 1, n){ int g = 0; rep(s, 29){ if(a[i][s] != a[j][s]) g = 1; } if(g == 0){ //cout << i << " " << j << endl; ans ++; } } }*/ for (auto i = dict.begin(); i != dict.end(); ++i) { int ggg = i->second; // cout << i->first << " " << ggg << endl; // cout << ggg << endl; if (ggg >= 2) { if (ggg % 2 == 0) { unsigned ll ffff = ggg / 2; ans += ffff * (ggg - 1); } else { unsigned ll ffff = (ggg - 1) / 2; ans += ffff * (ggg); } // ans += ggg * (ggg - 1) / 2; } } cout << ans << endl; }
replace
131
133
131
141
-11
p02947
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; i++) #define all(v) v.begin(), v.end() typedef long long ll; int main() { int n; cin >> n; vector<string> s(n); rep(i, n) cin >> s[i]; rep(i, n) sort(all(s[i])); sort(all(s)); ll res = 0; int i = 0; while (i < n) { ll count = 0; while (i < n) { if (s[i] != s[i + 1]) break; count++; i++; } res += count * (count + 1) / 2; i++; } cout << res << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)n; i++) #define all(v) v.begin(), v.end() typedef long long ll; int main() { int n; cin >> n; vector<string> s(n); rep(i, n) cin >> s[i]; rep(i, n) sort(all(s[i])); sort(all(s)); ll res = 0; int i = 0; while (i < n) { ll count = 0; while (i < n - 1) { if (s[i] != s[i + 1]) break; count++; i++; } res += count * (count + 1) / 2; i++; } cout << res << endl; }
replace
18
19
18
19
0
p02947
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define FOR(i, x, n) for (ll i = x; i < n; i++) #define pb push_back #define pf push_front #define ll long long #define hii cout << "hii" << endl #define pii pair<int, int> #define pll pair<ll, ll> #define int ll #define mpp make_pair #define endl '\n' #define ff first #define ss second #define vi vector<int> #define all(s) s.begin(), s.end() #define si size() #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <class Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << endl; } template <class Arg1, class... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *sep = strchr(names + 1, ','); cerr.write(names, sep - names) << " : " << arg1 << " "; __f(sep + 1, args...); } const int N = 1e5 + 5; void solve() { map<string, int> mp; int t; cin >> t; while (t--) { string input; cin >> input; sort(all(input)); mp[input]++; } int ret = 0; for (auto x : mp) { ret += (x.second * (x.second - 1)) / 2; } cout << ret << endl; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t = 1; // cin >> t; while (t--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, x, n) for (ll i = x; i < n; i++) #define pb push_back #define pf push_front #define ll long long #define hii cout << "hii" << endl #define pii pair<int, int> #define pll pair<ll, ll> #define int ll #define mpp make_pair #define endl '\n' #define ff first #define ss second #define vi vector<int> #define all(s) s.begin(), s.end() #define si size() #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <class Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << endl; } template <class Arg1, class... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *sep = strchr(names + 1, ','); cerr.write(names, sep - names) << " : " << arg1 << " "; __f(sep + 1, args...); } const int N = 1e5 + 5; void solve() { map<string, int> mp; int t; cin >> t; while (t--) { string input; cin >> input; sort(all(input)); mp[input]++; } int ret = 0; for (auto x : mp) { ret += (x.second * (x.second - 1)) / 2; } cout << ret << endl; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); /*#ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif*/ int t = 1; // cin >> t; while (t--) solve(); return 0; }
replace
53
57
53
57
TLE
p02947
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <list> #include <map> #include <string> #include <vector> using namespace std; #define loop(i, first, end) for (int i = (first); i < (end); i++) #define uint unsigned int #define ull unsigned long long #define ll long long #define vint vector<int> #define vuint vector<unsigned int> #define vull vector<ull> #define vll vector<ll> #define init(type, var) \ type var; \ cin >> var; #define vinit(vtype, var, n) \ vtype var(n); \ loop(i, 0, n) cin >> var[i]; const ull MOD = 1000000007ULL; const ull INF = (ull)(-1LL); int main(void) { init(ull, n); vinit(vector<string>, s, n); loop(i, 0, s.size()) { sort(s[i].begin(), s[i].end()); } sort(s.begin(), s.end()); ull count = 0; loop(i, 0, s.size()) { loop(j, i + 1, s.size()) { if (s[i] != s[j]) break; count++; } } cout << count << endl; return 0; }
#include <algorithm> #include <iostream> #include <list> #include <map> #include <string> #include <vector> using namespace std; #define loop(i, first, end) for (int i = (first); i < (end); i++) #define uint unsigned int #define ull unsigned long long #define ll long long #define vint vector<int> #define vuint vector<unsigned int> #define vull vector<ull> #define vll vector<ll> #define init(type, var) \ type var; \ cin >> var; #define vinit(vtype, var, n) \ vtype var(n); \ loop(i, 0, n) cin >> var[i]; const ull MOD = 1000000007ULL; const ull INF = (ull)(-1LL); int main(void) { init(ull, n); vinit(vector<string>, s, n); loop(i, 0, s.size()) { sort(s[i].begin(), s[i].end()); } sort(s.begin(), s.end()); ull count = 0; for (int i = 0; i < s.size();) { ull _c; for (_c = 1; i + _c < s.size() && s[i + _c] == s[i]; _c++) ; count += (_c * (_c - 1) / 2); i += _c; } cout << count << endl; return 0; }
replace
32
38
32
38
TLE
p02947
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> #include <string> using namespace std; int main() { int N; cin >> N; string s[N + 1]; for (int i = 0; i < N; i++) cin >> s[i]; string aToZ = "abcdefghijklmnopqrstuvwxyz"; map<string, long> anagram_group; // 文字カウント(24桁の文字にして0~Aまでの文字で各文字の数を表現) for (int i = 0; i < N; i++) { string chrCount = string(24, '0'); string targetStr = s[i]; for (int j = 0; j < 10; j++) { /* cout << targetStr[j] << endl; cout << aToZ.find(targetStr[j]) << endl; cout << chrCount[aToZ.find(targetStr[j])] << endl; cout << "----" << endl; */ char c = chrCount[aToZ.find(targetStr[j])]; if ('c' == '9') { chrCount[aToZ.find(targetStr[j])] = 'A'; } else { chrCount[aToZ.find(targetStr[j])] = to_string(std::stoi(string(1, c)) + 1)[0]; } } if (anagram_group.count(chrCount) == 0) { anagram_group[chrCount] = 1L; } else { anagram_group[chrCount]++; } } long result = 0; auto begin = anagram_group.begin(), end = anagram_group.end(); for (auto iter = begin; iter != end; iter++) { long value = iter->second; if (value > 1L) { result += (value * (value - 1L)) / 2L; } } cout << result << endl; return 0; }
#include <algorithm> #include <iostream> #include <map> #include <string> using namespace std; int main() { int N; cin >> N; string s[N + 1]; for (int i = 0; i < N; i++) cin >> s[i]; string aToZ = "abcdefghijklmnopqrstuvwxyz"; map<string, long> anagram_group; // 文字カウント(24桁の文字にして0~Aまでの文字で各文字の数を表現) for (int i = 0; i < N; i++) { string chrCount = string(26, '0'); string targetStr = s[i]; for (int j = 0; j < 10; j++) { /* cout << targetStr[j] << endl; cout << aToZ.find(targetStr[j]) << endl; cout << chrCount[aToZ.find(targetStr[j])] << endl; cout << "----" << endl; */ char c = chrCount[aToZ.find(targetStr[j])]; if ('c' == '9') { chrCount[aToZ.find(targetStr[j])] = 'A'; } else { chrCount[aToZ.find(targetStr[j])] = to_string(std::stoi(string(1, c)) + 1)[0]; } } if (anagram_group.count(chrCount) == 0) { anagram_group[chrCount] = 1L; } else { anagram_group[chrCount]++; } } long result = 0; auto begin = anagram_group.begin(), end = anagram_group.end(); for (auto iter = begin; iter != end; iter++) { long value = iter->second; if (value > 1L) { result += (value * (value - 1L)) / 2L; } } cout << result << endl; return 0; }
replace
20
21
20
21
0
p02947
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const bool DEBUG = false; int N; vector<string> s; void input() { cin >> N; s = vector<string>(N); for (size_t i = 0; i < N; i++) cin >> s[i]; } int main(int argc, char const *argv[]) { input(); for (size_t i = 0; i < N; i++) sort(s[i].begin(), s[i].end()); sort(s.begin(), s.end()); long long total = 0, count = 1; for (size_t i = 0; i < N; i++) { if ((s[i] != s[i + 1]) || i == (N - 1)) { total += (count * (count - 1)) / 2; count = 1; } else { count++; } } cout << total << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const bool DEBUG = false; int N; vector<string> s; void input() { cin >> N; s = vector<string>(N); for (size_t i = 0; i < N; i++) cin >> s[i]; } int main(int argc, char const *argv[]) { input(); for (size_t i = 0; i < N; i++) sort(s[i].begin(), s[i].end()); sort(s.begin(), s.end()); long long total = 0, count = 1; for (size_t i = 0; i < N; i++) { if (i == (N - 1) || (s[i] != s[i + 1])) { total += (count * (count - 1)) / 2; count = 1; } else { count++; } } cout << total << endl; return 0; }
replace
24
25
24
25
0
p02947
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n; cin >> n; vector<string> s(n); for (int i = 0; i < n; i++) { cin >> s.at(i); sort(s.at(i).begin(), s.at(i).end()); } ll ans = 0; for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { if (s.at(i) == s.at(j)) ans++; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int n; cin >> n; vector<string> s(n); for (int i = 0; i < n; i++) { cin >> s.at(i); sort(s.at(i).begin(), s.at(i).end()); } ll ans = 0; sort(s.begin(), s.end()); map<string, int> m; for (int i = 0; i < n; i++) { if (m.count(s.at(i))) { ans += m.at(s.at(i)); m[s.at(i)] += 1; } else { m[s.at(i)] = 1; } } cout << ans << endl; }
replace
13
17
13
21
TLE
p02947
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; vector<string> s; int main() { int N; long len = 1; long count = 0; string in; cin >> N; for (int i = 0; i < N; i++) { cin >> in; sort(in.begin(), in.begin() + in.size()); s.push_back(in); } sort(s.begin(), s.end()); for (int i = 0; i < N; i++) { if (s[i] == s[i + 1]) len++; else { count += len * (len - 1) / 2; len = 1; } } count += len * (len - 1) / 2; cout << count << endl; return 0; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; vector<string> s; int main() { int N; long len = 1; long count = 0; string in; cin >> N; for (int i = 0; i < N; i++) { cin >> in; sort(in.begin(), in.begin() + in.size()); s.push_back(in); } sort(s.begin(), s.end()); for (int i = 0; i < N - 1; i++) { if (s[i] == s[i + 1]) len++; else { count += len * (len - 1) / 2; len = 1; } } count += len * (len - 1) / 2; cout << count << endl; return 0; }
replace
21
22
21
22
0
p02947
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define all(v) v.begin(), v.end() #define INF (int)1e16 #define speed \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.flush() #define MOD (int)(1e9 + 7) #define fi first #define se second #define sq(a) a *a #define ld long double #define Error(x) cout << #x << " = " << (x) << endl; #define Error2(a, b) \ cout << "( " << #a << " , " << #b << " ) = ( " << (a) << " , " << (b) \ << " )\n"; #define Error3(a, b, c) \ cout << "(" << #a << " , " << #b << " , " << #c << " ) = ( " << (a) << " , " \ << (b) << " , " << (c) << ")\n"; #define Error4(a, b, c, d) \ cout << "(" << #a << " , " << #b << " , " << #c << " , " << #d << " ) = \ ( " \ << (a) << " , " << (b) << " , " << (c) << " , " << (d) << ")\n"; #define popcount __builtin_popcountll #define ign cin.ignore(numeric_limits<streamsize>::max(), '\n') #define PI acos(-1.0) int abso(int a) { return a > 0 ? a : (-a); } int cdiv(int a, int b) { return a / b + ((a % b) > 0); } int mul(int a, int b) { int res = 0; while (b) { if (b & 1) res = (res + a) % MOD; a = (a + a) % MOD; b = b / 2; } return res; } int bexp(int a, int b) { int res = 1; while (b) { if (b & 1) res = mul(res, a); a = mul(a, a); b = b / 2; } return res; } int inv(int a) { return bexp(a, MOD - 2); } int power(int a, int b) { int res = 1; while (b) { if (b & 1) res = res * a; a = a * a; b = b >> 1; } return res; } void solve() { int n; cin >> n; string arr[n + 1]; map<string, int> mp; for (int i = 1; i <= n; i++) { cin >> arr[i]; sort(arr[i].begin(), arr[i].end()); mp[arr[i]]++; } int ans = 0; for (auto it : mp) { ans = ans + ((it.second) * (it.second - 1)) / 2; } cout << ans << "\n"; } signed main() { speed; #ifndef ONLINE_JUDGE freopen("C:\\Users\\anuj\\CLionProjects\\untitled\\input.txt", "r", stdin); freopen("C:\\Users\\anuj\\CLionProjects\\untitled\\output.txt", "w", stdout); #endif int t = 1; // cin>>t; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define all(v) v.begin(), v.end() #define INF (int)1e16 #define speed \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.flush() #define MOD (int)(1e9 + 7) #define fi first #define se second #define sq(a) a *a #define ld long double #define Error(x) cout << #x << " = " << (x) << endl; #define Error2(a, b) \ cout << "( " << #a << " , " << #b << " ) = ( " << (a) << " , " << (b) \ << " )\n"; #define Error3(a, b, c) \ cout << "(" << #a << " , " << #b << " , " << #c << " ) = ( " << (a) << " , " \ << (b) << " , " << (c) << ")\n"; #define Error4(a, b, c, d) \ cout << "(" << #a << " , " << #b << " , " << #c << " , " << #d << " ) = \ ( " \ << (a) << " , " << (b) << " , " << (c) << " , " << (d) << ")\n"; #define popcount __builtin_popcountll #define ign cin.ignore(numeric_limits<streamsize>::max(), '\n') #define PI acos(-1.0) int abso(int a) { return a > 0 ? a : (-a); } int cdiv(int a, int b) { return a / b + ((a % b) > 0); } int mul(int a, int b) { int res = 0; while (b) { if (b & 1) res = (res + a) % MOD; a = (a + a) % MOD; b = b / 2; } return res; } int bexp(int a, int b) { int res = 1; while (b) { if (b & 1) res = mul(res, a); a = mul(a, a); b = b / 2; } return res; } int inv(int a) { return bexp(a, MOD - 2); } int power(int a, int b) { int res = 1; while (b) { if (b & 1) res = res * a; a = a * a; b = b >> 1; } return res; } void solve() { int n; cin >> n; string arr[n + 1]; map<string, int> mp; for (int i = 1; i <= n; i++) { cin >> arr[i]; sort(arr[i].begin(), arr[i].end()); mp[arr[i]]++; } int ans = 0; for (auto it : mp) { ans = ans + ((it.second) * (it.second - 1)) / 2; } cout << ans << "\n"; } signed main() { speed; int t = 1; // cin>>t; while (t--) { solve(); } }
delete
85
89
85
85
0
p02947
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using lint = long long int; using pint = pair<int, int>; using plint = pair<lint, lint>; #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((lint)(x).size()) #define POW2(n) (1LL << (n)) #define FOR(i, begin, end) \ for (int i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define eprintf(...) 42 #endif int main() { lint n; cin >> n; lint ans = 0, tmp = 1; vector<string> s(n); REP(i, n) { cin >> s[i]; sort(ALL(s[i])); } sort(ALL(s)); REP(i, n - 1) {} REP(i, n) { if (s[i] == s[i + 1]) { tmp += 1; } else { ans += tmp * (tmp - 1) / 2; tmp = 1; } // cout << s[i]<< tmp << "\n"; } ans += tmp * (tmp - 1) / 2; cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; using lint = long long int; using pint = pair<int, int>; using plint = pair<lint, lint>; #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((lint)(x).size()) #define POW2(n) (1LL << (n)) #define FOR(i, begin, end) \ for (int i = (begin), i##_end_ = (end); i < i##_end_; i++) #define IFOR(i, begin, end) \ for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--) #define REP(i, n) FOR(i, 0, n) #define IREP(i, n) IFOR(i, 0, n) #ifdef LOCAL #define eprintf(...) fprintf(stderr, __VA_ARGS__) #else #define eprintf(...) 42 #endif int main() { lint n; cin >> n; lint ans = 0, tmp = 1; vector<string> s(n); REP(i, n) { cin >> s[i]; sort(ALL(s[i])); } sort(ALL(s)); REP(i, n - 1) {} REP(i, n - 1) { if (s[i] == s[i + 1]) { tmp += 1; } else { ans += tmp * (tmp - 1) / 2; tmp = 1; } // cout << s[i]<< tmp << "\n"; } ans += tmp * (tmp - 1) / 2; cout << ans << "\n"; return 0; }
replace
37
38
37
38
0
p02947
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<string> all(n); for (int i = 0; i < n; i++) cin >> all.at(i); int count = 0; int i = 0; while (i < n) { string test = all.at(i); for (int k = i + 1; k < n; k++) { string cover = all.at(k); for (int j = 0; j < 10; j++) { for (int l = 0; l < cover.size(); l++) { if (test.at(j) == cover.at(l)) { cover.erase(l, 1); break; } } if (cover.size() == 0) count++; } } i++; } cout << count << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; map<string, int> mp; for (int i = 0; i < n; i++) { string s; cin >> s; sort(s.begin(), s.end()); mp[s]++; } long long count = 0; for (auto &x : mp) { long long i = x.second; count += i * (i - 1) / 2; } cout << count << endl; }
replace
7
28
7
18
TLE
p02947
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a); i < (int)(b); ++i) #define endl "\n" typedef long long ll; typedef string str; const double pi = 3.14159265358979323846; const long long inf = 1LL << 60; typedef pair<int, int> P; const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; int ctoi(const char c) { if ('0' <= c && c <= '9') return (c - '0'); return -1; } vector<int> input(int n) { vector<int> vec(n); for (int i = 0; i < n; i++) { cin >> vec.at(i); } return vec; } vector<vector<int>> matinput(int n, int m) { vector<vector<int>> table(n, vector<int>(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> table.at(i).at(j); } } return table; } void matoutput(vector<vector<int>> table) { for (int i = 0; i < int(table.size()); i++) { for (int j = 0; j < int(table.at(0).size()); j++) { cout << table.at(i).at(j) << " "; } cout << endl; } } long long perm(int n, int r) { if (n < r) { cout << "error" << endl; return 0; } long long perm = 1; for (int i = n; i > n - r; i--) { perm *= i; } return perm; } long long comb(int n, int r) { if (n < r) { cout << "error" << endl; return 0; } long long comb = perm(n, r); for (int i = r; i > 0; i--) { comb /= i; } return comb; } long long fact(int n) { long long fact = 1; for (int i = n; i > 0; i--) { fact *= i; } return fact; } int gcd(int a, int b) { if (a % b == 0) { return (b); } else { return (gcd(b, a % b)); } } int lcm(int a, int b) { return a * b / gcd(a, b); } bool isprime(int n) { if (n < 2) return false; else if (n == 2) return true; else if (n % 2 == 0) return false; for (int i = 3; i <= sqrt(n); i += 2) { if (n % i == 0) { return false; } } return true; } vector<long long> divisors(long long N) { vector<long long> res; for (long long i = 1; i * i <= N; ++i) { if (N % i == 0) { res.push_back(i); // 重複しないならば i の相方である N/i も push if (N / i != i) res.push_back(N / i); } } // 小さい順に並び替える sort(res.begin(), res.end()); return res; /*long long N; cin >> N; vector<long long> res = divisors(N); for (int i = 0; i < res.size(); ++i) { cout << res[i] << " "; } cout << endl;*/ } 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; } res.push_back({a, ex}); } if (N != 1) res.push_back({N, 1}); return res; } void Yes(bool f) { if (f) { cout << "Yes" << endl; } else { cout << "No" << endl; } } void YES(bool f) { if (f) { cout << "YES" << endl; } else { cout << "NO" << endl; } } bool leapyear(int y) { // 閏年かどうかを判定 if (y % 4 == 0) { if (y % 100 == 0) { if (y % 400 == 0) { return true; } else { return false; } } else { return true; } } else { return false; } } tuple<int, int, int> dayplus(int y, int m, int d) { // 次の日を返す // 31日まである月 if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) { if (d != 31) { d++; return make_tuple(y, m, d); } else { d = 1; if (m == 12) { m = 1; y++; return make_tuple(y, m, d); } else { m++; return make_tuple(y, m, d); } } } // 30日まである月 else if (m == 4 || m == 6 || m == 9 || m == 11) { if (d != 30) { d++; return make_tuple(y, m, d); } else { d = 1; m++; return make_tuple(y, m, d); } } // 2月 else { // 閏年の場合 if (leapyear(y)) { if (d != 29) { d++; return make_tuple(y, m, d); } else { d = 1; m++; return make_tuple(y, m, d); } } // 閏年ではない場合 else { if (d != 28) { d++; return make_tuple(y, m, d); } else { d = 1; m++; return make_tuple(y, m, d); } } } } tuple<int, int, int> monplus(int y, int m, int d) { // 月を一つ先に、日を一日にする d = 1; if (m == 12) { m = 1; y++; return make_tuple(y, m, d); } else { m++; return make_tuple(y, m, d); } } bool in(vector<int> a, int x) { if (find(a.begin(), a.end(), x) != a.end()) { return true; } else { return false; } } int count_bool(vector<bool> flag) { int count = 0; for (int i = 0; i < int(flag.size()); i++) { if (flag[i]) { count++; } } return count; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { int n; cin >> n; vector<str> s(n); rep(i, 0, n) { cin >> s[i]; sort(s[i].begin(), s[i].end()); } ll ans = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (s[i] == s[j]) { ans++; } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a); i < (int)(b); ++i) #define endl "\n" typedef long long ll; typedef string str; const double pi = 3.14159265358979323846; const long long inf = 1LL << 60; typedef pair<int, int> P; const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1}; int ctoi(const char c) { if ('0' <= c && c <= '9') return (c - '0'); return -1; } vector<int> input(int n) { vector<int> vec(n); for (int i = 0; i < n; i++) { cin >> vec.at(i); } return vec; } vector<vector<int>> matinput(int n, int m) { vector<vector<int>> table(n, vector<int>(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> table.at(i).at(j); } } return table; } void matoutput(vector<vector<int>> table) { for (int i = 0; i < int(table.size()); i++) { for (int j = 0; j < int(table.at(0).size()); j++) { cout << table.at(i).at(j) << " "; } cout << endl; } } long long perm(int n, int r) { if (n < r) { cout << "error" << endl; return 0; } long long perm = 1; for (int i = n; i > n - r; i--) { perm *= i; } return perm; } long long comb(int n, int r) { if (n < r) { cout << "error" << endl; return 0; } long long comb = perm(n, r); for (int i = r; i > 0; i--) { comb /= i; } return comb; } long long fact(int n) { long long fact = 1; for (int i = n; i > 0; i--) { fact *= i; } return fact; } int gcd(int a, int b) { if (a % b == 0) { return (b); } else { return (gcd(b, a % b)); } } int lcm(int a, int b) { return a * b / gcd(a, b); } bool isprime(int n) { if (n < 2) return false; else if (n == 2) return true; else if (n % 2 == 0) return false; for (int i = 3; i <= sqrt(n); i += 2) { if (n % i == 0) { return false; } } return true; } vector<long long> divisors(long long N) { vector<long long> res; for (long long i = 1; i * i <= N; ++i) { if (N % i == 0) { res.push_back(i); // 重複しないならば i の相方である N/i も push if (N / i != i) res.push_back(N / i); } } // 小さい順に並び替える sort(res.begin(), res.end()); return res; /*long long N; cin >> N; vector<long long> res = divisors(N); for (int i = 0; i < res.size(); ++i) { cout << res[i] << " "; } cout << endl;*/ } 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; } res.push_back({a, ex}); } if (N != 1) res.push_back({N, 1}); return res; } void Yes(bool f) { if (f) { cout << "Yes" << endl; } else { cout << "No" << endl; } } void YES(bool f) { if (f) { cout << "YES" << endl; } else { cout << "NO" << endl; } } bool leapyear(int y) { // 閏年かどうかを判定 if (y % 4 == 0) { if (y % 100 == 0) { if (y % 400 == 0) { return true; } else { return false; } } else { return true; } } else { return false; } } tuple<int, int, int> dayplus(int y, int m, int d) { // 次の日を返す // 31日まである月 if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) { if (d != 31) { d++; return make_tuple(y, m, d); } else { d = 1; if (m == 12) { m = 1; y++; return make_tuple(y, m, d); } else { m++; return make_tuple(y, m, d); } } } // 30日まである月 else if (m == 4 || m == 6 || m == 9 || m == 11) { if (d != 30) { d++; return make_tuple(y, m, d); } else { d = 1; m++; return make_tuple(y, m, d); } } // 2月 else { // 閏年の場合 if (leapyear(y)) { if (d != 29) { d++; return make_tuple(y, m, d); } else { d = 1; m++; return make_tuple(y, m, d); } } // 閏年ではない場合 else { if (d != 28) { d++; return make_tuple(y, m, d); } else { d = 1; m++; return make_tuple(y, m, d); } } } } tuple<int, int, int> monplus(int y, int m, int d) { // 月を一つ先に、日を一日にする d = 1; if (m == 12) { m = 1; y++; return make_tuple(y, m, d); } else { m++; return make_tuple(y, m, d); } } bool in(vector<int> a, int x) { if (find(a.begin(), a.end(), x) != a.end()) { return true; } else { return false; } } int count_bool(vector<bool> flag) { int count = 0; for (int i = 0; i < int(flag.size()); i++) { if (flag[i]) { count++; } } return count; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { int n; cin >> n; vector<str> s(n); rep(i, 0, n) { cin >> s[i]; sort(s[i].begin(), s[i].end()); } ll ans = 0; sort(s.begin(), s.end()); for (int i = 1; i < n; i++) { int cnt = 1; while (s[i - 1] == s[i]) { cnt++; i++; } if (cnt > 1) ans += comb(cnt, 2); } cout << ans << endl; }
replace
268
275
268
278
TLE
p02947
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; long long factorial(long long n) { if (n == 0) { return 1; } long long ans = 1; for (int i = 1; i <= n; i++) { ans *= i; } return ans; } long long combination(long long n, long long k) { if (n < k) { return 0; } else if (n == k) { return 1; } return factorial(n) / (factorial(k) * factorial(n - k)); } int main() { int n; cin >> n; vector<string> strs; strs.reserve(n); for (int i = 0; i < n; i++) { string str; cin >> str; sort(str.begin(), str.end()); strs.push_back(str); } sort(strs.begin(), strs.end()); vector<long long> ns; string str = strs[0]; long long count = 0; for (int i = 0; i < strs.size(); i++) { if (str == strs[i]) { count++; } else { ns.push_back(count); str = strs[i]; count = 1; } } ns.push_back(count); long long ans = 0; for (int i = 0; i < ns.size(); i++) { ans += combination(ns[i], 2); } cout << ans; }
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; long long factorial(long long n) { if (n == 0) { return 1; } long long ans = 1; for (int i = 1; i <= n; i++) { ans *= i; } return ans; } long long combination(long long n, long long k) { if (n < k) { return 0; } else if (n == k) { return 1; } long long numerator = 1; long long denominator = factorial(k); for (int i = 0; i < k; i++) { numerator *= (n - i); } return numerator / denominator; } int main() { int n; cin >> n; vector<string> strs; strs.reserve(n); for (int i = 0; i < n; i++) { string str; cin >> str; sort(str.begin(), str.end()); strs.push_back(str); } sort(strs.begin(), strs.end()); vector<long long> ns; string str = strs[0]; long long count = 0; for (int i = 0; i < strs.size(); i++) { if (str == strs[i]) { count++; } else { ns.push_back(count); str = strs[i]; count = 1; } } ns.push_back(count); long long ans = 0; for (int i = 0; i < ns.size(); i++) { ans += combination(ns[i], 2); } cout << ans; }
replace
24
25
24
30
0
p02947
C++
Runtime Error
#include <algorithm> #include <iostream> #include <numeric> #include <vector> using namespace std; int main() { int N; cin >> N; vector<string> s; string t; for (int i = 0; i < N; i++) { cin >> t; s.push_back(t); } for (int i = 0; i < N; i++) { std::sort(s[i].begin(), s[i].end()); } std::sort(s.begin(), s.end()); long long count = 0; long long conv = 1; for (int i = 0; i < N; i++) { if (s[i] == s[i + 1]) { conv++; } else { if (conv >= 2) { count += (conv * (conv - 1) / 2); } conv = 1; } } cout << count << endl; }
#include <algorithm> #include <iostream> #include <numeric> #include <vector> using namespace std; int main() { int N; cin >> N; vector<string> s; string t; for (int i = 0; i < N; i++) { cin >> t; s.push_back(t); } s.push_back("{{{{{{{{{{"); for (int i = 0; i < N; i++) { std::sort(s[i].begin(), s[i].end()); } std::sort(s.begin(), s.end()); long long count = 0; long long conv = 1; for (int i = 0; i < N; i++) { if (s[i] == s[i + 1]) { conv++; } else { if (conv >= 2) { count += (conv * (conv - 1) / 2); } conv = 1; } } cout << count << endl; }
insert
17
17
17
18
0
p02947
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> #include <string> int main(void) { int n; std::cin >> n; std::map<std::string, int> mp; for (int i = 0; i < n; i++) { std::string s; std::cin >> s; std::sort(s.begin(), s.end()); mp.at(s)++; } long long ans = 0; for (auto &p : mp) { int temp = p.second; ans += (long long)temp * (temp - 1) / 2; } std::cout << ans << std::endl; return 0; }
#include <algorithm> #include <iostream> #include <map> #include <string> int main(void) { int n; std::cin >> n; std::map<std::string, int> mp; for (int i = 0; i < n; i++) { std::string s; std::cin >> s; std::sort(s.begin(), s.end()); mp[s]++; } long long ans = 0; for (auto &p : mp) { int temp = p.second; ans += (long long)temp * (temp - 1) / 2; } std::cout << ans << std::endl; return 0; }
replace
15
16
15
16
-6
terminate called after throwing an instance of 'std::out_of_range' what(): map::at
p02948
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; using ll = long long; const int INF = 1001001001; #define rep(i, n) for (int i = 0; i < (n); ++i) int main() { ll n, m; cin >> n >> m; vector<vector<ll>> day(m + 1); priority_queue<ll> today; rep(i, n) { ll a, b; cin >> a >> b; day[m - a + 1].push_back(b); } ll result = 0; for (ll i = m; i >= 1; i--) { if (!day[i].empty()) { for (auto x : day[i]) { today.push(x); } } if (!today.empty()) { result += today.top(); today.pop(); } } cout << result << endl; }
#include <algorithm> #include <cmath> #include <cstdio> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; using ll = long long; const int INF = 1001001001; #define rep(i, n) for (int i = 0; i < (n); ++i) int main() { ll n, m; cin >> n >> m; vector<vector<ll>> day(m + 1); priority_queue<ll> today; rep(i, n) { ll a, b; cin >> a >> b; if (m - a + 1 < 1) continue; day[m - a + 1].push_back(b); } ll result = 0; for (ll i = m; i >= 1; i--) { if (!day[i].empty()) { for (auto x : day[i]) { today.push(x); } } if (!today.empty()) { result += today.top(); today.pop(); } } cout << result << endl; }
insert
26
26
26
28
0
p02948
C++
Runtime Error
#include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <type_traits> #include <utility> #include <vector> using namespace std; typedef long long ll; #define rep(i, N) for (ll(i) = 0; (i) < (N); (i)++) const int mod = 1000000007; int main() { int n, m; cin >> n >> m; vector<vector<int>> jobs(m); rep(i, n) { int a, b; cin >> a >> b; if (a > m) continue; jobs[m - a].push_back(b); } priority_queue<int> q; ll ans = 0; for (int i = m; i >= 0; --i) { for (int b : jobs[i]) { q.push(b); } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; }
#include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <type_traits> #include <utility> #include <vector> using namespace std; typedef long long ll; #define rep(i, N) for (ll(i) = 0; (i) < (N); (i)++) const int mod = 1000000007; int main() { int n, m; cin >> n >> m; vector<vector<int>> jobs(m); rep(i, n) { int a, b; cin >> a >> b; if (a > m) continue; jobs[m - a].push_back(b); } priority_queue<int> q; ll ans = 0; for (int i = m - 1; i >= 0; --i) { for (int b : jobs[i]) { q.push(b); } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; }
replace
35
36
35
36
-11
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define mod 1000000007 typedef long long ll; using namespace std; int main(void) { int n, m; cin >> n >> m; vector<int> p[m + 1]; rep(i, n) { int a, b; cin >> a >> b; p[a].push_back(b); } // rep(i,n) cout << p[i].second << " " << p[i].first << endl; priority_queue<int> que; ll ans = 0; for (int i = 1; i <= m; i++) { for (int j = 0; j < p[i].size(); j++) { que.push(p[i][j]); } if (!que.empty()) { ans += que.top(); que.pop(); } } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define mod 1000000007 typedef long long ll; using namespace std; int main(void) { int n, m; cin >> n >> m; vector<int> p[100005]; rep(i, n) { int a, b; cin >> a >> b; p[a].push_back(b); } // rep(i,n) cout << p[i].second << " " << p[i].first << endl; priority_queue<int> que; ll ans = 0; for (int i = 1; i <= m; i++) { for (int j = 0; j < p[i].size(); j++) { que.push(p[i][j]); } if (!que.empty()) { ans += que.top(); que.pop(); } } cout << ans << endl; }
replace
8
9
8
9
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; void solve() { priority_queue<int> q; int n, m; cin >> n >> m; vector<vector<int>> v(m + 1); int a, b; rep(i, n) { cin >> a >> b; v[a].push_back(b); } ll ans = 0; for (int i = 0; i <= m; ++i) { if (v[i].empty()) { q.push(0); } else { for (int j : v[i]) q.push(j); } ans += q.top(); q.pop(); } cout << ans << endl; } int main() { solve(); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; void solve() { priority_queue<int> q; int n, m; cin >> n >> m; vector<vector<int>> v(m + 1); int a, b; rep(i, n) { cin >> a >> b; if (a < m + 1) { v[a].push_back(b); } } ll ans = 0; for (int i = 0; i <= m; ++i) { if (v[i].empty()) { q.push(0); } else { for (int j : v[i]) q.push(j); } ans += q.top(); q.pop(); } cout << ans << endl; } int main() { solve(); return 0; }
replace
13
14
13
16
0
p02948
C++
Runtime Error
// #include <bits/stdc++.h> #include <algorithm> #include <iostream> #include <array> #include <bitset> #include <complex> #include <cstring> #include <deque> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <valarray> #include <vector> #include <cassert> #include <chrono> #include <cmath> #include <functional> #include <iomanip> #include <numeric> #include <random> #include <memory> using namespace std; #define int long long typedef long long ll; typedef unsigned long long ull; // typedef unsigned __int128 HASH; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ull, ull> pullull; typedef pair<ll, int> plli; typedef pair<double, int> pdi; typedef pair<long double, int> pdbi; typedef pair<int, pii> pipii; typedef pair<ll, pll> plpll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<pii> vpii; typedef vector<vector<int>> mat; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, a, b) for (int i = (a); i < (b); i++) #define rrep(i, n) for (int i = (n); i > 0; i--) #define rrep2(i, a, b) for (int i = (a); i > b; i--) #define pb push_back #define fi first #define se second #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() const ll hmod1 = 999999937; const ll hmod2 = 1000000000 + 9; const int INF = 1 << 30; const ll INFLL = 1LL << 62; const long double EPS = 1e-12; const ll mod = 1000000000 + 7; // const ll mod = 998244353; const int dx4[4] = {1, 0, -1, 0}; const int dy4[4] = {0, 1, 0, -1}; const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1}; const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1}; const long double pi = 3.141592653589793; #define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod #define inside(y, x, h, w) \ (0 <= (y) && (y) < (h) && 0 <= (x) && (x) < (w)) ? true : false // debug #define DEBUG #define DUMPOUT cerr #ifdef DEBUG #define dump(...) \ DUMPOUT << #__VA_ARGS__ << " :[" << __FUNCTION__ << ":" << __LINE__ << "]" \ << endl; \ DUMPOUT << " "; \ dump_func(__VA_ARGS__) #else #define dump(...) #endif void dump_func() { DUMPOUT << endl; }; template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) == 0) DUMPOUT << " "; else DUMPOUT << ", "; dump_func(std::move(tail)...); } // ostream template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) { os << "["; for (int i = 0; i < vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "]"; return os; } template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { os << "["; for (auto itr = map_var.begin(); itr != map_var.end(); itr++) { os << "(" << itr->first << ", " << itr->second << ")"; itr++; if (itr != map_var.end()) os << ", "; itr--; } os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) { os << "["; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) { os << *itr; ++itr; if (itr != set_var.end()) os << ", "; itr--; } os << "]"; return os; } int n, m; vector<vector<int>> v(10000 + 5); signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m; rep(i, n) { int a, b; cin >> a >> b; v[a].push_back(b); } // rep(i, n) cerr << v[i].fi << " " << v[i].se << endl; int ans = 0; priority_queue<int> pq; rrep2(day, m - 1, -1) { for (auto x : v[m - day]) { pq.push(x); } if (pq.empty()) continue; ans += pq.top(); pq.pop(); } cout << ans << endl; }
// #include <bits/stdc++.h> #include <algorithm> #include <iostream> #include <array> #include <bitset> #include <complex> #include <cstring> #include <deque> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <valarray> #include <vector> #include <cassert> #include <chrono> #include <cmath> #include <functional> #include <iomanip> #include <numeric> #include <random> #include <memory> using namespace std; #define int long long typedef long long ll; typedef unsigned long long ull; // typedef unsigned __int128 HASH; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ull, ull> pullull; typedef pair<ll, int> plli; typedef pair<double, int> pdi; typedef pair<long double, int> pdbi; typedef pair<int, pii> pipii; typedef pair<ll, pll> plpll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<vi> vvi; typedef vector<vvi> vvvi; typedef vector<pii> vpii; typedef vector<vector<int>> mat; #define rep(i, n) for (int i = 0; i < (n); i++) #define rep2(i, a, b) for (int i = (a); i < (b); i++) #define rrep(i, n) for (int i = (n); i > 0; i--) #define rrep2(i, a, b) for (int i = (a); i > b; i--) #define pb push_back #define fi first #define se second #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() const ll hmod1 = 999999937; const ll hmod2 = 1000000000 + 9; const int INF = 1 << 30; const ll INFLL = 1LL << 62; const long double EPS = 1e-12; const ll mod = 1000000000 + 7; // const ll mod = 998244353; const int dx4[4] = {1, 0, -1, 0}; const int dy4[4] = {0, 1, 0, -1}; const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1}; const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1}; const long double pi = 3.141592653589793; #define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod #define inside(y, x, h, w) \ (0 <= (y) && (y) < (h) && 0 <= (x) && (x) < (w)) ? true : false // debug #define DEBUG #define DUMPOUT cerr #ifdef DEBUG #define dump(...) \ DUMPOUT << #__VA_ARGS__ << " :[" << __FUNCTION__ << ":" << __LINE__ << "]" \ << endl; \ DUMPOUT << " "; \ dump_func(__VA_ARGS__) #else #define dump(...) #endif void dump_func() { DUMPOUT << endl; }; template <class Head, class... Tail> void dump_func(Head &&head, Tail &&...tail) { DUMPOUT << head; if (sizeof...(Tail) == 0) DUMPOUT << " "; else DUMPOUT << ", "; dump_func(std::move(tail)...); } // ostream template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) { os << "["; for (int i = 0; i < vec.size(); i++) os << vec[i] << (i + 1 == vec.size() ? "" : ", "); os << "]"; return os; } template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { os << "["; for (auto itr = map_var.begin(); itr != map_var.end(); itr++) { os << "(" << itr->first << ", " << itr->second << ")"; itr++; if (itr != map_var.end()) os << ", "; itr--; } os << "]"; return os; } template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) { os << "["; for (auto itr = set_var.begin(); itr != set_var.end(); itr++) { os << *itr; ++itr; if (itr != set_var.end()) os << ", "; itr--; } os << "]"; return os; } int n, m; vector<vector<int>> v(100000 + 5); signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m; rep(i, n) { int a, b; cin >> a >> b; v[a].push_back(b); } // rep(i, n) cerr << v[i].fi << " " << v[i].se << endl; int ans = 0; priority_queue<int> pq; rrep2(day, m - 1, -1) { for (auto x : v[m - day]) { pq.push(x); } if (pq.empty()) continue; ans += pq.top(); pq.pop(); } cout << ans << endl; }
replace
149
150
149
150
0
p02948
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; vector<vector<int>> ab(N, vector<int>(2)); for (int i = 0; i < N; i++) { cin >> ab[i][0] >> ab[i][1]; } sort(ab.begin(), ab.end()); priority_queue<int> pq; int s = 0; int sum = 0; for (int i = 1; i < M + 1; i++) { for (int j = s; j < N; j++) { if (ab[j][0] == i) { pq.push(ab[j][1]); s++; } } if (!pq.empty()) { sum += pq.top(); pq.pop(); } } cout << sum << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; vector<vector<int>> ab(N, vector<int>(2)); for (int i = 0; i < N; i++) { cin >> ab[i][0] >> ab[i][1]; } sort(ab.begin(), ab.end()); priority_queue<int> pq; int s = 0; int sum = 0; for (int i = 1; i < M + 1; i++) { for (int j = s; j < N; j++) { if (ab[j][0] == i) { pq.push(ab[j][1]); s++; } else { break; } } if (!pq.empty()) { sum += pq.top(); pq.pop(); } } cout << sum << endl; }
insert
19
19
19
21
TLE
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second #define pii pair<int, int> #define eb emplace_back #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep3(i, l, n) for (int i = l; i < (n); ++i) #define sz(v) (int)v.size() const int inf = 1e9 + 7; const ll INF = 1e18; const int mod = 1000000007; #define abs(x) (x >= 0 ? x : -(x)) #define lb(v, x) (int)(lower_bound(all(v), x) - v.begin()) #define ub(v, x) (int)(upper_bound(all(v), x) - v.begin()) template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; } template <typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; } ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; } template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (auto &vi : vec) os << vi << " "; return os; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.F << " " << p.S; return os; } template <typename T> inline istream &operator>>(istream &is, vector<T> &v) { rep(j, sz(v)) is >> v[j]; return is; } template <class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; } void solve(); int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(10); int T; // cin >> T; T = 1; while (T--) { solve(); } } void solve() { // 締め切りに近い方から, 最大の選んでく int n, m; cin >> n >> m; vector<vector<int>> x(m + 1); rep(i, n) { int a, b; cin >> a >> b; x[a].eb(b); } ll ans = 0; priority_queue<int> q; rep3(i, 1, m + 1) { // 猶予 for (int j : x[i]) q.push(j); if (sz(q) == 0) continue; ans += q.top(); q.pop(); } cout << ans << endl; return; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define F first #define S second #define pii pair<int, int> #define eb emplace_back #define all(v) v.begin(), v.end() #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep3(i, l, n) for (int i = l; i < (n); ++i) #define sz(v) (int)v.size() const int inf = 1e9 + 7; const ll INF = 1e18; const int mod = 1000000007; #define abs(x) (x >= 0 ? x : -(x)) #define lb(v, x) (int)(lower_bound(all(v), x) - v.begin()) #define ub(v, x) (int)(upper_bound(all(v), x) - v.begin()) template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; } template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; } template <typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; } ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; } template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (auto &vi : vec) os << vi << " "; return os; } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.F << " " << p.S; return os; } template <typename T> inline istream &operator>>(istream &is, vector<T> &v) { rep(j, sz(v)) is >> v[j]; return is; } template <class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; } void solve(); int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(10); int T; // cin >> T; T = 1; while (T--) { solve(); } } void solve() { // 締め切りに近い方から, 最大の選んでく int n, m; cin >> n >> m; vector<vector<int>> x(m + 1); rep(i, n) { int a, b; cin >> a >> b; if (a > m) continue; x[a].eb(b); } ll ans = 0; priority_queue<int> q; rep3(i, 1, m + 1) { // 猶予 for (int j : x[i]) q.push(j); if (sz(q) == 0) continue; ans += q.top(); q.pop(); } cout << ans << endl; return; }
insert
88
88
88
90
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef long double LD; typedef unsigned long long ULL; #ifdef _LOCAL struct Tester { Tester() { freopen("sample.in", "r", stdin); } ~Tester() { fprintf(stderr, "\nTime: %d ms\n", int(1000.0 * clock() / CLOCKS_PER_SEC)); } } _tester; #endif const int INF = 0x3F3F3F3F; const LL INFLL = 0x3F3F3F3F3F3F3F3FLL; const int N = 2550; struct aP { int a, b; aP() {} aP(int a, int b) : a(a), b(b) {} bool operator<(const aP &c) const { if (a == c.a) return b > c.b; return a > c.a; } }; struct bP { int a, b; bP() {} bP(int a, int b) : a(a), b(b) {} bool operator<(const bP &c) const { if (b == c.b) return a > c.a; return b > c.b; } }; priority_queue<aP> input; priority_queue<bP> already; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { int a, b; scanf("%d%d", &a, &b); input.push(aP(m - a, b)); } while (!input.empty()) { if (input.top().a >= (int)already.size()) { // printf("[%d,%d]\n", input.top().a, input.top().b); already.push(bP(input.top().a, input.top().b)); } else if (input.top().a == (int)already.size() - 1 && input.top().b > already.top().b) { // printf("[%d,%d]->[%d,%d]\n", already.top().a, already.top().b, // input.top().a, input.top().b); already.pop(); already.push(bP(input.top().a, input.top().b)); } input.pop(); } LL ans = 0; while (!already.empty()) { ans += 1LL * already.top().b; already.pop(); } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef long double LD; typedef unsigned long long ULL; #ifdef _LOCAL struct Tester { Tester() { freopen("sample.in", "r", stdin); } ~Tester() { fprintf(stderr, "\nTime: %d ms\n", int(1000.0 * clock() / CLOCKS_PER_SEC)); } } _tester; #endif const int INF = 0x3F3F3F3F; const LL INFLL = 0x3F3F3F3F3F3F3F3FLL; const int N = 2550; struct aP { int a, b; aP() {} aP(int a, int b) : a(a), b(b) {} bool operator<(const aP &c) const { if (a == c.a) return b > c.b; return a > c.a; } }; struct bP { int a, b; bP() {} bP(int a, int b) : a(a), b(b) {} bool operator<(const bP &c) const { if (b == c.b) return a > c.a; return b > c.b; } }; priority_queue<aP> input; priority_queue<bP> already; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { int a, b; scanf("%d%d", &a, &b); input.push(aP(m - a, b)); } while (!input.empty()) { if (input.top().a >= (int)already.size()) { // printf("[%d,%d]\n", input.top().a, input.top().b); already.push(bP(input.top().a, input.top().b)); } else if ((int)already.size() - 1 >= 0 && input.top().a == (int)already.size() - 1 && input.top().b > already.top().b) { // printf("[%d,%d]->[%d,%d]\n", already.top().a, already.top().b, // input.top().a, input.top().b); already.pop(); already.push(bP(input.top().a, input.top().b)); } input.pop(); } LL ans = 0; while (!already.empty()) { ans += 1LL * already.top().b; already.pop(); } printf("%lld\n", ans); return 0; }
replace
57
58
57
59
0
p02948
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; using Graph = vector<vector<int>>; int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; #define INF 100000000000 #define MAX 200001 #define MOD 1000000007 ll fac[MAX], finv[MAX], inv[MAX]; const int MX = 1000005; int main() { int N, M; cin >> N >> M; vector<P> AB(N); priority_queue<int> que; for (int i = 0; i < N; i++) { int a, b; cin >> a >> b; AB[i] = {a, b}; } sort(AB.begin(), AB.end()); int idx = 0; int day = 1; int ans = 0; while (day != M + 1) { int cnt = 0; for (int i = idx; i < N; i++) { if (AB[i].first <= day) { cnt++; que.push(AB[i].second); } } idx += cnt; day++; if (!que.empty()) { ans += que.top(); que.pop(); } } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; using Graph = vector<vector<int>>; int dx[] = {0, 1, 0, -1}; int dy[] = {1, 0, -1, 0}; #define INF 100000000000 #define MAX 200001 #define MOD 1000000007 ll fac[MAX], finv[MAX], inv[MAX]; const int MX = 1000005; int main() { int N, M; cin >> N >> M; vector<P> AB(N); priority_queue<int> que; for (int i = 0; i < N; i++) { int a, b; cin >> a >> b; AB[i] = {a, b}; } sort(AB.begin(), AB.end()); int idx = 0; int day = 1; int ans = 0; while (day != M + 1) { int cnt = 0; for (int i = idx; i < N; i++) { if (AB[i].first <= day) { cnt++; que.push(AB[i].second); } else break; } idx += cnt; day++; if (!que.empty()) { ans += que.top(); que.pop(); } } cout << ans << endl; }
replace
43
44
43
45
TLE
p02948
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <vector> using namespace std; typedef long long int ll; #define rep(i, a, n) for (ll i = a; i < (ll)(n); i++) long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; } long long LCM(long long a, long long b) { return a / GCD(a, b) * b; } int main() { int n, m; cin >> n >> m; vector<vector<int>> money(10001); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; if (a <= m) money[a].push_back(b); } int ans = 0; priority_queue<int> q; for (int i = 1; i <= m; i++) { for (int j = 0; j < money[i].size(); j++) q.push(money[i][j]); if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; return 0; }
#include <algorithm> #include <cstdio> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <vector> using namespace std; typedef long long int ll; #define rep(i, a, n) for (ll i = a; i < (ll)(n); i++) long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; } long long LCM(long long a, long long b) { return a / GCD(a, b) * b; } int main() { int n, m; cin >> n >> m; vector<vector<int>> money(100001); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; if (a <= m) money[a].push_back(b); } int ans = 0; priority_queue<int> q; for (int i = 1; i <= m; i++) { for (int j = 0; j < money[i].size(); j++) q.push(money[i][j]); if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; return 0; }
replace
17
18
17
18
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define int int64_t using namespace std; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; priority_queue<int> q; vector<vector<int>> v(m + 1); for (int i = 0; i < n; ++i) { int a, b; cin >> a >> b; v[a].emplace_back(b); } int ret = 0; for (int i = 1; i <= m; ++i) { for (int k : v[i]) { q.emplace(k); } if (!q.empty()) { ret += q.top(); q.pop(); } } cout << ret; return 0; }
#include <bits/stdc++.h> #define int int64_t using namespace std; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m; cin >> n >> m; priority_queue<int> q; vector<vector<int>> v(m + 1); for (int i = 0; i < n; ++i) { int a, b; cin >> a >> b; if (a <= m) v[a].emplace_back(b); } int ret = 0; for (int i = 1; i <= m; ++i) { for (int k : v[i]) { q.emplace(k); } if (!q.empty()) { ret += q.top(); q.pop(); } } cout << ret; return 0; }
replace
15
16
15
17
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define M 100005 struct D { int x, y; bool operator<(D a) const { return y == a.y ? x < a.x : y > a.y; } } A[M]; int n, m, F[M]; int gf(int x) { return x == F[x] ? x : F[x] = gf(F[x]); } int main() { cin >> n >> m; for (int i = 1; i <= n; ++i) scanf("%d%d", &A[i].x, &A[i].y); for (int i = 1; i <= m; ++i) F[i] = i; sort(A + 1, A + n + 1); long long ans = 0; for (int i = 1; i <= n; ++i) { int p = m - A[i].x + 1; int fa = gf(p); if (fa) ans += A[i].y, F[fa] = fa - 1; } printf("%lld", ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define M 100005 struct D { int x, y; bool operator<(D a) const { return y == a.y ? x < a.x : y > a.y; } } A[M]; int n, m, F[M]; int gf(int x) { return x == F[x] ? x : F[x] = gf(F[x]); } int main() { cin >> n >> m; for (int i = 1; i <= n; ++i) scanf("%d%d", &A[i].x, &A[i].y); for (int i = 1; i <= m; ++i) F[i] = i; sort(A + 1, A + n + 1); long long ans = 0; for (int i = 1; i <= n; ++i) { int p = m - A[i].x + 1; if (p <= 0) continue; int fa = gf(p); if (fa) ans += A[i].y, F[fa] = fa - 1; } printf("%lld", ans); return 0; }
insert
19
19
19
21
0
p02948
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; int main() { int n, m; cin >> n >> m; vector<pair<ll, ll>> a(max(n, m) + 10, {1000000, 0}); for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; } auto compare = [](auto const &l, auto const &r) { if (l.first != r.first) { return l.first < r.first; } else if (l.second != r.second) { return l.second > r.second; } else { return true; } }; sort(a.begin(), a.end(), compare); auto compare2 = [](auto l, auto r) { return l.second < r.second; }; priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, decltype(compare2)> que{ compare2}; ll ans = 0; auto itr = a.begin(); for (int i = 0; i < m; i++) { while (itr != a.end() && (*itr).first < i + 2) { que.push(*itr); itr++; } if (que.empty()) { continue; } ans += que.top().second; que.pop(); } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; using ll = long long; int main() { int n, m; cin >> n >> m; vector<pair<ll, ll>> a(max(n, m) + 10, {1000000, 0}); for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; } auto compare = [](auto const &l, auto const &r) { if (l.first != r.first) { return l.first < r.first; } else if (l.second != r.second) { return l.second > r.second; } else { return false; } }; sort(a.begin(), a.end(), compare); auto compare2 = [](auto l, auto r) { return l.second < r.second; }; priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, decltype(compare2)> que{ compare2}; ll ans = 0; auto itr = a.begin(); for (int i = 0; i < m; i++) { while (itr != a.end() && (*itr).first < i + 2) { que.push(*itr); itr++; } if (que.empty()) { continue; } ans += que.top().second; que.pop(); } cout << ans << endl; return 0; }
replace
27
28
27
28
0
p02948
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; typedef uint64_t ull; typedef pair<int, int> P; constexpr double EPS = 1e-9; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) template <typename T> struct BinaryIndexedTree { vector<T> data; int sz; BinaryIndexedTree(int n) { sz = n + 1; data.assign(sz, 0); } void add(int i, T x) { ++i; while (i < sz) { data[i] += x; i += i & -i; } } // [0, i] の区間和 T sum(int i) { T res = 0; ++i; while (i > 0) { res += data[i]; i -= i & -i; } return res; } T sum(int l, int r) { return sum(r - 1) - sum(l - 1); } // val 以上を満たす 0-indexed の位置を返す int lower_bound(T val) { // if(val <= 0) return -1; int res = 0; int n = 1; while (n < sz) n <<= 1; for (int k = n >> 1; k > 0; k >>= 1) { if (res + k < sz && data[res + k] < val) { val -= data[res + k]; res += k; } } return res; // 1-indexed であれば、res + 1 を返す } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector<P> table(n); for (int i = 0; i < n; ++i) { int a, b; cin >> a >> b; table[i] = P(a, b); } sort(table.begin(), table.end(), [](const P &p1, const P &p2) { if (p1.second == p2.second) { return p1.first < p2.first; } return p1.second > p2.second; }); BinaryIndexedTree<int> bit(m + 5); for (int i = 1; i <= m; ++i) bit.add(i, 1); int ans = 0; for (int i = 0; i < n; ++i) { int sum = bit.sum(m) - bit.sum(table[i].first - 1); if (sum == 0) continue; int p = bit.lower_bound(bit.sum(table[i].first - 1) + 1); bit.add(p, -1); ans += table[i].second; } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <vector> using namespace std; typedef long long ll; typedef uint64_t ull; typedef pair<int, int> P; constexpr double EPS = 1e-9; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) template <typename T> struct BinaryIndexedTree { vector<T> data; int sz; BinaryIndexedTree(int n) { sz = n + 1; data.assign(sz, 0); } void add(int i, T x) { ++i; while (i < sz) { data[i] += x; i += i & -i; } } // [0, i] の区間和 T sum(int i) { T res = 0; ++i; while (i > 0) { res += data[i]; i -= i & -i; } return res; } T sum(int l, int r) { return sum(r - 1) - sum(l - 1); } // val 以上を満たす 0-indexed の位置を返す int lower_bound(T val) { // if(val <= 0) return -1; int res = 0; int n = 1; while (n < sz) n <<= 1; for (int k = n >> 1; k > 0; k >>= 1) { if (res + k < sz && data[res + k] < val) { val -= data[res + k]; res += k; } } return res; // 1-indexed であれば、res + 1 を返す } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vector<P> table(n); for (int i = 0; i < n; ++i) { int a, b; cin >> a >> b; table[i] = P(a, b); } sort(table.begin(), table.end(), [](const P &p1, const P &p2) { if (p1.second == p2.second) { return p1.first < p2.first; } return p1.second > p2.second; }); BinaryIndexedTree<int> bit(m + 5); for (int i = 1; i <= m; ++i) bit.add(i, 1); int ans = 0; for (int i = 0; i < n; ++i) { if (table[i].first > m) continue; int sum = bit.sum(m) - bit.sum(table[i].first - 1); if (sum == 0) continue; int p = bit.lower_bound(bit.sum(table[i].first - 1) + 1); bit.add(p, -1); ans += table[i].second; } cout << ans << endl; }
insert
106
106
106
108
0
p02948
C++
Time Limit Exceeded
#include <bits/stdc++.h> typedef long long int ll; typedef long double ld; #define sync \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define input(arr, n) \ for (ll i1 = 0; i1 < n; i1++) \ cin >> arr[i1] #define pb(x) push_back(x) #define si(a) scanf("%lld", &a) #define pi(a) printf("%lld", a) #define mod 1000000007 #define f first #define s second #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> // #pragma GCC optimize("O3") // recursions\ #pragma comment(linker, "/stack:200000000") // loops #pragma GCC optimize("unroll-loops") using namespace __gnu_pbds; #define ordered_set \ tree<ll, null_type, greater_equal<ll>, rb_tree_tag, \ tree_order_statistics_node_update> // s.order_of_key(val) // *s.find_by_order(ind) using namespace std; int main() { sync; ll n, m; cin >> n >> m; multiset<pair<ll, ll>> ms; set<ll> days; for (ll i = 0; i < n; i++) { ll x, y; cin >> x >> y; if (x <= m) { ms.insert({y, -x}); } } for (ll i = 1; i <= m; i++) days.insert(i); ll ans = 0; multiset<pair<ll, ll>>::iterator it; set<ll>::iterator day; while (days.size() > 0 && ms.size() > 0) { it = ms.end(); it--; ll val = -(it->second); day = lower_bound(days.begin(), days.end(), val); if (day != days.end()) { ans += it->first; days.erase(day); } ms.erase(it); } cout << ans; }
#include <bits/stdc++.h> typedef long long int ll; typedef long double ld; #define sync \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define input(arr, n) \ for (ll i1 = 0; i1 < n; i1++) \ cin >> arr[i1] #define pb(x) push_back(x) #define si(a) scanf("%lld", &a) #define pi(a) printf("%lld", a) #define mod 1000000007 #define f first #define s second #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> // #pragma GCC optimize("O3") // recursions\ #pragma comment(linker, "/stack:200000000") // loops #pragma GCC optimize("unroll-loops") using namespace __gnu_pbds; #define ordered_set \ tree<ll, null_type, greater_equal<ll>, rb_tree_tag, \ tree_order_statistics_node_update> // s.order_of_key(val) // *s.find_by_order(ind) using namespace std; int main() { sync; ll n, m; cin >> n >> m; multiset<pair<ll, ll>> ms; set<ll> days; for (ll i = 0; i < n; i++) { ll x, y; cin >> x >> y; if (x <= m) { ms.insert({y, -x}); } } for (ll i = 1; i <= m; i++) days.insert(i); ll ans = 0; multiset<pair<ll, ll>>::iterator it; set<ll>::iterator day; while (days.size() > 0 && ms.size() > 0) { it = ms.end(); it--; ll val = -(it->second); day = days.lower_bound(val); if (day != days.end()) { ans += it->first; days.erase(day); } ms.erase(it); } cout << ans; }
replace
50
51
50
51
TLE
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define ld double #define ull unsigned long long #define ll long long #define pii pair<int, int> #define iiii pair<int, pii> #define mp make_pair #define INF 1000000000 #define MOD 1000000007 #define rep(i, x) for (int(i) = 0; (i) < (x); (i)++) inline int getint() { int x = 0, p = 1; char c = getchar(); while (c <= 32) c = getchar(); if (c == 45) p = -p, c = getchar(); while (c > 32) x = x * 10 + c - 48, c = getchar(); return x * p; } using namespace std; // ruogu const int N = 1e5 + 5; int n, m, a[N]; vector<int> v[N]; priority_queue<int> pq; // int main() { n = getint(); m = getint() + 1; rep(i, n) { int x = getint(); a[i] = getint(); v[m - x].push_back(a[i]); } int res = 0; for (int i = m; i >= 1; i--) { rep(j, v[i].size()) pq.push(v[i][j]); if (pq.size()) { res += pq.top(); pq.pop(); } } cout << res << endl; return 0; }
#include <bits/stdc++.h> #define ld double #define ull unsigned long long #define ll long long #define pii pair<int, int> #define iiii pair<int, pii> #define mp make_pair #define INF 1000000000 #define MOD 1000000007 #define rep(i, x) for (int(i) = 0; (i) < (x); (i)++) inline int getint() { int x = 0, p = 1; char c = getchar(); while (c <= 32) c = getchar(); if (c == 45) p = -p, c = getchar(); while (c > 32) x = x * 10 + c - 48, c = getchar(); return x * p; } using namespace std; // ruogu const int N = 1e5 + 5; int n, m, a[N]; vector<int> v[N]; priority_queue<int> pq; // int main() { n = getint(); m = getint() + 1; rep(i, n) { int x = getint(); a[i] = getint(); if (m - x > 0) v[m - x].push_back(a[i]); } int res = 0; for (int i = m; i >= 1; i--) { rep(j, v[i].size()) pq.push(v[i][j]); if (pq.size()) { res += pq.top(); pq.pop(); } } cout << res << endl; return 0; }
replace
34
35
34
36
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define ll long long #define lld long double #define ALL(x) x.begin(), x.end() using namespace std; int main() { int n, m; cin >> n >> m; vector<int> a(n, 0), b(n, 0); map<int, int> mp; priority_queue<pair<int, int>> p; priority_queue<int> pq; rep(i, n) { cin >> a[i] >> b[i]; if (a[i] <= m) { p.push({-a[i], b[i]}); } } ll ans = 0; for (int i = 1; i <= m; i++) { while ((-p.top().first <= i) && (!p.empty())) { pq.push(p.top().second); p.pop(); } if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define ll long long #define lld long double #define ALL(x) x.begin(), x.end() using namespace std; int main() { int n, m; cin >> n >> m; vector<int> a(n, 0), b(n, 0); map<int, int> mp; priority_queue<pair<int, int>> p; priority_queue<int> pq; rep(i, n) { cin >> a[i] >> b[i]; if (a[i] <= m) { p.push({-a[i], b[i]}); } } ll ans = 0; for (int i = 1; i <= m; i++) { while ((!p.empty()) && (-p.top().first <= i)) { pq.push(p.top().second); p.pop(); } if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; return 0; }
replace
26
27
26
27
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define ms(x, n) memset(x, n, sizeof(x)); #define rep(i, n) for (int i = 0; i < (int)n; ++i) #define rep1(i, n) for (int i = 1; i <= (int)n; ++i) #define pb push_back #define PI acos(-1.0) #define LONG_LONG_MAX 9223372036854775807 #define LONG_LONG_MIN -9223372036854775808 typedef long long int ll; typedef unsigned long long int ull; using namespace std; const int maxn = 1e5 + 10; int n, m, a, b; vector<int> vec[maxn]; multiset<int> mts; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; rep(i, n) { cin >> a >> b; vec[m - a].pb(b); } ll ans = 0; for (int i = m; i >= 0; --i) { while (!vec[i].empty()) { mts.insert(*prev(vec[i].end())); vec[i].pop_back(); } if (!mts.empty()) { ans += *prev(mts.end()); mts.erase(prev(mts.end())); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define ms(x, n) memset(x, n, sizeof(x)); #define rep(i, n) for (int i = 0; i < (int)n; ++i) #define rep1(i, n) for (int i = 1; i <= (int)n; ++i) #define pb push_back #define PI acos(-1.0) #define LONG_LONG_MAX 9223372036854775807 #define LONG_LONG_MIN -9223372036854775808 typedef long long int ll; typedef unsigned long long int ull; using namespace std; const int maxn = 1e5 + 10; int n, m, a, b; vector<int> vec[maxn]; multiset<int> mts; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> m; rep(i, n) { cin >> a >> b; if (m - a >= 0) vec[m - a].pb(b); } ll ans = 0; for (int i = m; i >= 0; --i) { while (!vec[i].empty()) { mts.insert(*prev(vec[i].end())); vec[i].pop_back(); } if (!mts.empty()) { ans += *prev(mts.end()); mts.erase(prev(mts.end())); } } cout << ans << endl; return 0; }
replace
24
25
24
26
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (n); i++) #define REP2(i, x, n) for (int i = x; i < (n); i++) #define ALL(n) begin(n), end(n) struct cww { cww() { ios::sync_with_stdio(false); cin.tie(0); } } star; const long long INF = numeric_limits<long long>::max(); 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; } int main() { int N, M; cin >> N >> M; vector<vector<int>> Q(10100); REP(i, N) { int A, B; cin >> A >> B; Q[A].push_back(B); } int ans = 0; priority_queue<int> pq; for (int i = 1; i <= M; i++) { REP(j, Q[i].size()) { pq.push(Q[i][j]); } if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (n); i++) #define REP2(i, x, n) for (int i = x; i < (n); i++) #define ALL(n) begin(n), end(n) struct cww { cww() { ios::sync_with_stdio(false); cin.tie(0); } } star; const long long INF = numeric_limits<long long>::max(); 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; } int main() { int N, M; cin >> N >> M; vector<vector<int>> Q(100100); REP(i, N) { int A, B; cin >> A >> B; Q[A].push_back(B); } int ans = 0; priority_queue<int> pq; for (int i = 1; i <= M; i++) { REP(j, Q[i].size()) { pq.push(Q[i][j]); } if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; return 0; }
replace
31
32
31
32
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; #define rep(i, n) for (int i = 0; i < n; ++i) int main() { int n, m; cin >> n >> m; int cnt = 0; vector<vector<int>> w(m); priority_queue<int> que; rep(i, n) { int a, b; cin >> a >> b; if (a > m + 1) continue; w[a].emplace_back(b); } ll ans = 0; for (int i = 1; i < m + 1; i++) { for (auto j : w[i]) { que.push(j); } if (!que.empty()) { ans += que.top(); que.pop(); } } cout << ans; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; #define rep(i, n) for (int i = 0; i < n; ++i) int main() { int n, m; cin >> n >> m; int cnt = 0; vector<vector<int>> w(m + 2); priority_queue<int> que; rep(i, n) { int a, b; cin >> a >> b; if (a > m + 1) continue; w[a].emplace_back(b); } ll ans = 0; for (int i = 1; i < m + 1; i++) { for (auto j : w[i]) { que.push(j); } if (!que.empty()) { ans += que.top(); que.pop(); } } cout << ans; }
replace
11
12
11
12
-11
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) typedef long long ll; using namespace std; int main() { int n, m; cin >> n >> m; vector<int> jobs[m]; rep(i, n) { int a, b; cin >> a >> b; if (a > m) continue; jobs[m - a].push_back(b); } priority_queue<int> p; ll ans = 0; for (int i = m - 1; i >= 0; i++) { for (int j : jobs[i]) { p.push(j); } if (!p.empty()) { ans += p.top(); p.pop(); } } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) typedef long long ll; using namespace std; int main() { int n, m; cin >> n >> m; vector<int> jobs[m]; rep(i, n) { int a, b; cin >> a >> b; if (a > m) continue; jobs[m - a].push_back(b); } priority_queue<int> p; ll ans = 0; for (int i = m - 1; i >= 0; i--) { for (int j : jobs[i]) { p.push(j); } if (!p.empty()) { ans += p.top(); p.pop(); } } cout << ans << endl; }
replace
19
20
19
20
-11
p02948
C++
Runtime Error
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; typedef pair<int, int> P; vector<int> t[100002]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { P p; cin >> p.second >> p.first; t[m - p.second].push_back(p.first); } priority_queue<int, vector<int>, greater<int>> que; for (int i = 0; i < m; i++) { if (t[i].size() == 0) { continue; } for (int j = 0; j < t[i].size(); j++) { que.push(t[i][j]); if (que.size() > i + 1) { que.pop(); } } } int ans = 0; while (!que.empty()) { ans += que.top(); que.pop(); } cout << ans << endl; }
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; typedef pair<int, int> P; vector<int> t[100002]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { P p; cin >> p.second >> p.first; if (m - p.second >= 0) { t[m - p.second].push_back(p.first); } } priority_queue<int, vector<int>, greater<int>> que; for (int i = 0; i < m; i++) { if (t[i].size() == 0) { continue; } for (int j = 0; j < t[i].size(); j++) { que.push(t[i][j]); if (que.size() > i + 1) { que.pop(); } } } int ans = 0; while (!que.empty()) { ans += que.top(); que.pop(); } cout << ans << endl; }
replace
24
25
24
27
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> // include all standard C++ libraries using namespace std; // Loops #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = int(a); i < int(b); ++i) #define _rrep(i, n) rrepi(i, n, 0) #define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__) #define each(xi, x) for (auto &&xi : x) // Note: we can use rep(i,N) or rep(i,from,to) // typedef using ll = long long; template <class T> using vec = vector<T>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using pii = pair<int, int>; // Constants // Shorter repr for frequently used terms #define pb push_back #define eb emplace_back #define mp make_pair #define Fi first #define Se second // Algorithms #define all(x) (x).begin(), (x).end() #define uniq(v) v.erase(unique(all(v)), v.end()) #define perm(c) \ sort(all(c)); \ for (bool c##p = 1; c##p; c##p = next_permutation(all(c))) template <class T> pair<T, size_t> max(vector<T> &x) { auto it = max_element(all(x)); return mp(*it, it - x.begin()); } template <class T> pair<T, size_t> min(vector<T> &x) { auto it = min_element(all(x)); return mp(*it, it - x.begin()); } template <class T> inline bool chmax(T &maxval, const T &newval) { if (maxval < newval) { maxval = newval; return 1; } return 0; } template <class T> inline bool chmin(T &minval, const T &newval) { if (minval > newval) { minval = newval; return 1; } return 0; } // Utilities // Grid world utilities int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; #define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H) inline int in() { int x; cin >> x; return x; } // read int from cin inline ll IN() { ll x; cin >> x; return x; } // read ll from cin // Debug #ifdef LOCAL #include "dump.hpp" #define debug(x) cerr << #x << ": " << x << '\n' #else #define dump(...) #define debug(x) #endif // Paste snippets here!! // int main() { cin.tie(0); ios::sync_with_stdio(false); // Magic for faster cin int n, m; cin >> n >> m; dump(n, m); vector<pii> ba; rep(i, n) { int ai, bi; cin >> ai >> bi; ba.pb(mp(ai, bi)); } sort(all(ba)); // rep(i,n) cerr << ba[i].Fi << " " << ba[i].Se << endl; priority_queue<int> buf; ll money = 0; int j = 0; rep(i, 1, m + 1) { while (ba[j].Fi <= i) { buf.push(ba[j++].Se); } if (buf.empty()) continue; int b = buf.top(); buf.pop(); dump(i, b); money += b; } cout << money << endl; return 0; }
#include <bits/stdc++.h> // include all standard C++ libraries using namespace std; // Loops #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = int(a); i < int(b); ++i) #define _rrep(i, n) rrepi(i, n, 0) #define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i) #define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__) #define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__) #define each(xi, x) for (auto &&xi : x) // Note: we can use rep(i,N) or rep(i,from,to) // typedef using ll = long long; template <class T> using vec = vector<T>; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using pii = pair<int, int>; // Constants // Shorter repr for frequently used terms #define pb push_back #define eb emplace_back #define mp make_pair #define Fi first #define Se second // Algorithms #define all(x) (x).begin(), (x).end() #define uniq(v) v.erase(unique(all(v)), v.end()) #define perm(c) \ sort(all(c)); \ for (bool c##p = 1; c##p; c##p = next_permutation(all(c))) template <class T> pair<T, size_t> max(vector<T> &x) { auto it = max_element(all(x)); return mp(*it, it - x.begin()); } template <class T> pair<T, size_t> min(vector<T> &x) { auto it = min_element(all(x)); return mp(*it, it - x.begin()); } template <class T> inline bool chmax(T &maxval, const T &newval) { if (maxval < newval) { maxval = newval; return 1; } return 0; } template <class T> inline bool chmin(T &minval, const T &newval) { if (minval > newval) { minval = newval; return 1; } return 0; } // Utilities // Grid world utilities int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; #define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H) inline int in() { int x; cin >> x; return x; } // read int from cin inline ll IN() { ll x; cin >> x; return x; } // read ll from cin // Debug #ifdef LOCAL #include "dump.hpp" #define debug(x) cerr << #x << ": " << x << '\n' #else #define dump(...) #define debug(x) #endif // Paste snippets here!! // int main() { cin.tie(0); ios::sync_with_stdio(false); // Magic for faster cin int n, m; cin >> n >> m; dump(n, m); vector<pii> ba; rep(i, n) { int ai, bi; cin >> ai >> bi; ba.pb(mp(ai, bi)); } sort(all(ba)); // rep(i,n) cerr << ba[i].Fi << " " << ba[i].Se << endl; priority_queue<int> buf; ll money = 0; int j = 0; rep(i, 1, m + 1) { while (j < ba.size() && ba[j].Fi <= i) { buf.push(ba[j++].Se); } if (buf.empty()) continue; int b = buf.top(); buf.pop(); dump(i, b); money += b; } cout << money << endl; return 0; }
replace
113
114
113
114
0
p02948
C++
Runtime Error
#include <iostream> #include <map> #include <math.h> #include <queue> #include <vector> std::priority_queue<int> A; std::vector<int> B[10005]; int main() { int N, M; scanf("%d %d", &N, &M); int temp1, temp2; for (int i = 0; i < N; i++) { scanf("%d %d", &temp1, &temp2); B[temp1].push_back(temp2); } long long ans = 0; for (int i = 1; i <= M; i++) { // printf("i=%d\n",i); // printf("size=%lu\n",B[i].size()); for (int j = 0; j < B[i].size(); j++) { A.push(B[i][j]); } if (!A.empty()) { ans += A.top(); A.pop(); } } printf("%lld\n", ans); return 0; }
#include <iostream> #include <map> #include <math.h> #include <queue> #include <vector> std::priority_queue<int> A; std::vector<int> B[100005]; int main() { int N, M; scanf("%d %d", &N, &M); int temp1, temp2; for (int i = 0; i < N; i++) { scanf("%d %d", &temp1, &temp2); B[temp1].push_back(temp2); } long long ans = 0; for (int i = 1; i <= M; i++) { // printf("i=%d\n",i); // printf("size=%lu\n",B[i].size()); for (int j = 0; j < B[i].size(); j++) { A.push(B[i][j]); } if (!A.empty()) { ans += A.top(); A.pop(); } } printf("%lld\n", ans); return 0; }
replace
7
8
7
8
0
p02948
C++
Runtime Error
#include <algorithm> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; const int N = 100001; const int M = 100001; struct S { int a, b; S(int _a, int _b) { a = _a; b = _b; } bool operator<(const S &o) const { return a < o.a; } }; int main() { int n, m; cin >> n >> m; vector<S> sb; int ma = 0; for (int i = 0; i < n; ++i) { int a, b; cin >> a >> b; if (ma < a) ma = a; sb.push_back(S(a, b)); } sort(sb.begin(), sb.end()); long long ans = 0; priority_queue<int> que; int st = 0; for (int i = m - 1; i >= 0; --i) { for (; st < sb.size(); ++st) { if (sb[st].a + i <= m) { que.push(sb[st].b); } else break; } ans += que.top(); que.pop(); } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; const int N = 100001; const int M = 100001; struct S { int a, b; S(int _a, int _b) { a = _a; b = _b; } bool operator<(const S &o) const { return a < o.a; } }; int main() { int n, m; cin >> n >> m; vector<S> sb; int ma = 0; for (int i = 0; i < n; ++i) { int a, b; cin >> a >> b; if (ma < a) ma = a; sb.push_back(S(a, b)); } sort(sb.begin(), sb.end()); long long ans = 0; priority_queue<int> que; int st = 0; for (int i = m - 1; i >= 0; --i) { for (; st < sb.size(); ++st) { if (sb[st].a + i <= m) { que.push(sb[st].b); } else break; } if (que.size() > 0) { ans += que.top(); que.pop(); } } cout << ans << endl; return 0; }
replace
46
48
46
50
-11
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, n) for (int i = (int)(n); i >= 0; i--) #define all(v) v.begin(), v.end() typedef long long ll; int main() { int N, M; cin >> N >> M; vector<pair<int, int>> vec(N); rep(i, N) { cin >> vec[i].first >> vec[i].second; } sort(all(vec)); priority_queue<int> pque; rep(i, N) { pque.push(0); } int count = 0; int ans = 0; for (int i = 1; i <= M; i++) { while (true) { if (count >= N) { break; } else if (vec[count].first != i) { break; } else { pque.push(vec[count].second); count++; } } ans += pque.top(); pque.pop(); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, n) for (int i = (int)(n); i >= 0; i--) #define all(v) v.begin(), v.end() typedef long long ll; int main() { int N, M; cin >> N >> M; vector<pair<int, int>> vec(N); rep(i, N) { cin >> vec[i].first >> vec[i].second; } sort(all(vec)); priority_queue<int> pque; rep(i, 100005) { pque.push(0); } int count = 0; int ans = 0; for (int i = 1; i <= M; i++) { while (true) { if (count >= N) { break; } else if (vec[count].first != i) { break; } else { pque.push(vec[count].second); count++; } } ans += pque.top(); pque.pop(); } cout << ans << endl; }
replace
14
15
14
15
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long unsigned int ll; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) #define rep(i, start, end) for (int i = start; i < (int)(end); ++i) int main() { int n, m; cin >> n >> m; vector<vector<int>> jobs(m); rep(i, 0, n) { int a, b; cin >> a >> b; jobs[a - 1].push_back(b); } priority_queue<int> q; ll ans = 0; rep(i, 0, m) { for (int j : jobs[i]) { q.push(j); } if (q.empty()) continue; ans += q.top(); q.pop(); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long unsigned int ll; #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) #define rep(i, start, end) for (int i = start; i < (int)(end); ++i) int main() { int n, m; cin >> n >> m; vector<vector<int>> jobs(m); rep(i, 0, n) { int a, b; cin >> a >> b; if (m < a) continue; jobs[a - 1].push_back(b); } priority_queue<int> q; ll ans = 0; rep(i, 0, m) { for (int j : jobs[i]) { q.push(j); } if (q.empty()) continue; ans += q.top(); q.pop(); } cout << ans << endl; return 0; }
insert
14
14
14
16
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using VI = vector<int>; using VL = vector<ll>; using VS = vector<string>; using VB = vector<bool>; using VVI = vector<VI>; using VVL = vector<VL>; using PII = std::pair<int, int>; using PLL = std::pair<ll, ll>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define rep3(i, s, n, d) for (int i = (s); i < (int)(n); i += (d)) #define allpt(v) (v).begin(), (v).end() #define allpt_c(v) (v).cbegin(), (v).cend() #define allpt_r(v) (v).rbegin(), (v).rend() const int mod1 = 1e9 + 7, mod2 = 998244353, mod3 = 1e9 + 9; const int mod = mod1; const ll inf = 1e18; const string wsp = " "; const string tb = "\t"; const string rt = "\n"; template <typename T> void show1dvec(const vector<T> &v) { if (v.size() == 0) return; int n = v.size() - 1; rep(i, n) cout << v[i] << wsp; cout << v[n] << rt; return; } template <typename T> void show2dvec(const vector<vector<T>> &v) { int n = v.size(); rep(i, n) show1dvec(v[i]); } template <typename T, typename S> void show1dpair(const vector<pair<T, S>> &v) { int n = v.size(); rep(i, n) cout << v[i].first << wsp << v[i].second << rt; return; } template <typename T, typename S> void pairzip(const vector<pair<T, S>> &v, vector<T> &t, vector<T> &s) { int n = v.size(); rep(i, n) { t.push_back(v[i].first); s.push_back(v[i].second); } return; } template <typename T> void maxvec(vector<T> &v) { T s = v[0]; int n = v.size(); rep(i, n - 1) { if (s > v[i + 1]) { v[i + 1] = s; } s = v[i + 1]; } } template <typename T, typename S> bool myfind(T t, S s) { return find(t.cbegin(), t.cend(), s) != t.cend(); } bool check(int y, int x, int h, int w) { return 0 <= y && y < h && 0 <= x && x < w; } template <typename T> vector<T> cumsum(const vector<T> &v) { T s = 0; vector<T> ret; rep(i, v.size()) { s += v[i]; s %= mod; ret.emplace_back(s); } return ret; } bool iskadomatsu(int a, int b, int c) { return (a != b && b != c && c != a) && ((a > b && b < c) || (a < b && b > c)); } VS split(string s, char c) { VS ret; string part; s += c; rep(i, s.length()) { if (s[i] == c) { ret.emplace_back(part); part = ""; } else if (s[i] != c) { part += s[i]; } } return ret; } string removezero(string &s) { string ret; for (auto z : s) if (z != '0') ret += z; return ret; } ll sumdigit(ll x) { ll ans{0}; while (x > 0) { ans += x % 10; x /= 10; } return ans; } template <typename T, typename S, typename R> ll pow_mod(T p, S q, R mod = 1ll) { ll ret = 1, r = p; while (q) { if (q % 2) ret *= r, ret %= mod; r = (r * r) % mod, q /= 2; } return ret % mod; } void make_frac_tables(VL &frac_list, VL &frac_inv_list) { rep(i, frac_list.size() - 1) { frac_list[i + 1] *= frac_list[i] * (i + 1); frac_list[i + 1] %= mod; frac_inv_list[i + 1] *= frac_inv_list[i] * pow_mod(i + 1, mod - 2, mod); frac_inv_list[i + 1] %= mod; } } ll comb(int a, int b, const VL &frac_list, const VL &frac_inv_list) { if (a < b) return 0; ll ret = frac_list[a]; ret *= frac_inv_list[b]; ret %= mod; ret *= frac_inv_list[a - b]; ret %= mod; return ret; } int main() { cin.tie(0); ios::sync_with_stdio(false); #ifdef DEBUG cout << "DEBUG MODE" << endl; ifstream in("input.txt"); // for debug cin.rdbuf(in.rdbuf()); // for debug #endif int n, m, d, p; ll ans{0}; cin >> n >> m; priority_queue<int> tasks; VVI tasks_a_day(m + 1); rep(i, n) { cin >> d >> p; if (d <= n) tasks_a_day[d].emplace_back(p); } rep(i, m + 1) { for (int z : tasks_a_day[i]) { tasks.push(z); } if (!tasks.empty()) { ans += tasks.top(); tasks.pop(); } } cout << ans << rt; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using VI = vector<int>; using VL = vector<ll>; using VS = vector<string>; using VB = vector<bool>; using VVI = vector<VI>; using VVL = vector<VL>; using PII = std::pair<int, int>; using PLL = std::pair<ll, ll>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define rep3(i, s, n, d) for (int i = (s); i < (int)(n); i += (d)) #define allpt(v) (v).begin(), (v).end() #define allpt_c(v) (v).cbegin(), (v).cend() #define allpt_r(v) (v).rbegin(), (v).rend() const int mod1 = 1e9 + 7, mod2 = 998244353, mod3 = 1e9 + 9; const int mod = mod1; const ll inf = 1e18; const string wsp = " "; const string tb = "\t"; const string rt = "\n"; template <typename T> void show1dvec(const vector<T> &v) { if (v.size() == 0) return; int n = v.size() - 1; rep(i, n) cout << v[i] << wsp; cout << v[n] << rt; return; } template <typename T> void show2dvec(const vector<vector<T>> &v) { int n = v.size(); rep(i, n) show1dvec(v[i]); } template <typename T, typename S> void show1dpair(const vector<pair<T, S>> &v) { int n = v.size(); rep(i, n) cout << v[i].first << wsp << v[i].second << rt; return; } template <typename T, typename S> void pairzip(const vector<pair<T, S>> &v, vector<T> &t, vector<T> &s) { int n = v.size(); rep(i, n) { t.push_back(v[i].first); s.push_back(v[i].second); } return; } template <typename T> void maxvec(vector<T> &v) { T s = v[0]; int n = v.size(); rep(i, n - 1) { if (s > v[i + 1]) { v[i + 1] = s; } s = v[i + 1]; } } template <typename T, typename S> bool myfind(T t, S s) { return find(t.cbegin(), t.cend(), s) != t.cend(); } bool check(int y, int x, int h, int w) { return 0 <= y && y < h && 0 <= x && x < w; } template <typename T> vector<T> cumsum(const vector<T> &v) { T s = 0; vector<T> ret; rep(i, v.size()) { s += v[i]; s %= mod; ret.emplace_back(s); } return ret; } bool iskadomatsu(int a, int b, int c) { return (a != b && b != c && c != a) && ((a > b && b < c) || (a < b && b > c)); } VS split(string s, char c) { VS ret; string part; s += c; rep(i, s.length()) { if (s[i] == c) { ret.emplace_back(part); part = ""; } else if (s[i] != c) { part += s[i]; } } return ret; } string removezero(string &s) { string ret; for (auto z : s) if (z != '0') ret += z; return ret; } ll sumdigit(ll x) { ll ans{0}; while (x > 0) { ans += x % 10; x /= 10; } return ans; } template <typename T, typename S, typename R> ll pow_mod(T p, S q, R mod = 1ll) { ll ret = 1, r = p; while (q) { if (q % 2) ret *= r, ret %= mod; r = (r * r) % mod, q /= 2; } return ret % mod; } void make_frac_tables(VL &frac_list, VL &frac_inv_list) { rep(i, frac_list.size() - 1) { frac_list[i + 1] *= frac_list[i] * (i + 1); frac_list[i + 1] %= mod; frac_inv_list[i + 1] *= frac_inv_list[i] * pow_mod(i + 1, mod - 2, mod); frac_inv_list[i + 1] %= mod; } } ll comb(int a, int b, const VL &frac_list, const VL &frac_inv_list) { if (a < b) return 0; ll ret = frac_list[a]; ret *= frac_inv_list[b]; ret %= mod; ret *= frac_inv_list[a - b]; ret %= mod; return ret; } int main() { cin.tie(0); ios::sync_with_stdio(false); #ifdef DEBUG cout << "DEBUG MODE" << endl; ifstream in("input.txt"); // for debug cin.rdbuf(in.rdbuf()); // for debug #endif int n, m, d, p; ll ans{0}; cin >> n >> m; priority_queue<int> tasks; VVI tasks_a_day(m + 1); rep(i, n) { cin >> d >> p; if (d <= m) tasks_a_day[d].emplace_back(p); } rep(i, m + 1) { for (int z : tasks_a_day[i]) { tasks.push(z); } if (!tasks.empty()) { ans += tasks.top(); tasks.pop(); } } cout << ans << rt; return 0; }
replace
177
178
177
178
0
p02948
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; struct node { int index; int time; int cost; }; struct CustomCompare { bool operator()(const node &l, const node &r) { if (l.cost == r.cost) { return l.time < r.time; } else { return l.cost < r.cost; } } }; bool contains(vector<int> v, int target) { return std::find(v.begin(), v.end(), target) != v.end(); } int main() { int n, m; cin >> n >> m; int a, b; priority_queue<node, vector<node>, CustomCompare> queue[m + 1]; for (int i = 1; i <= n; i++) { cin >> a >> b; node g = {i, a, b}; queue[a].push(g); } long long ans = 0; priority_queue<node, vector<node>, CustomCompare> worklist; for (int i = 1; i <= m; i++) { while (!queue[i].empty()) { worklist.push(queue[i].top()); queue[i].pop(); } if (!worklist.empty()) { node work = worklist.top(); ans += work.cost; worklist.pop(); } } cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; struct node { int index; int time; int cost; }; struct CustomCompare { bool operator()(const node &l, const node &r) { if (l.cost == r.cost) { return l.time < r.time; } else { return l.cost < r.cost; } } }; bool contains(vector<int> v, int target) { return std::find(v.begin(), v.end(), target) != v.end(); } int main() { int n, m; cin >> n >> m; int a, b; priority_queue<node, vector<node>, CustomCompare> queue[m + 1]; for (int i = 1; i <= n; i++) { cin >> a >> b; node g = {i, a, b}; if (a <= m) { queue[a].push(g); } } long long ans = 0; priority_queue<node, vector<node>, CustomCompare> worklist; for (int i = 1; i <= m; i++) { while (!queue[i].empty()) { worklist.push(queue[i].top()); queue[i].pop(); } if (!worklist.empty()) { node work = worklist.top(); ans += work.cost; worklist.pop(); } } cout << ans << endl; return 0; }
replace
39
40
39
42
0
p02948
C++
Runtime Error
#include <algorithm> #include <iostream> #include <queue> #include <utility> #include <vector> using namespace std; typedef long long ll; int main() { ll a, b, n, m, tmp, sum = 0, day, ad; cin >> n >> m; vector<ll> n_list[10001]; day = 0; priority_queue<ll> que; for (int i = 0; i < n; i++) { cin >> a >> b; n_list[a].push_back(b); } for (int i = m - 1; i >= 0; i--) { tmp = m - i; for (int j = 0; j < n_list[tmp].size(); j++) { que.push(n_list[tmp][j]); } if (!que.empty()) { sum += que.top(); que.pop(); } } cout << sum << endl; }
#include <algorithm> #include <iostream> #include <queue> #include <utility> #include <vector> using namespace std; typedef long long ll; int main() { ll a, b, n, m, tmp, sum = 0, day, ad; cin >> n >> m; vector<ll> n_list[100001]; day = 0; priority_queue<ll> que; for (int i = 0; i < n; i++) { cin >> a >> b; n_list[a].push_back(b); } for (int i = m - 1; i >= 0; i--) { tmp = m - i; for (int j = 0; j < n_list[tmp].size(); j++) { que.push(n_list[tmp][j]); } if (!que.empty()) { sum += que.top(); que.pop(); } } cout << sum << endl; }
replace
10
11
10
11
0
p02948
C++
Time Limit Exceeded
#include <iostream> #include <queue> using namespace std; int main() { int N, M; cin >> N >> M; vector<int> v[M]; int A, B; for (int i = 0; i < N; ++i) { cin >> A >> B; if (A > M) continue; v[A - 1].push_back(B); } priority_queue<int> que; int ans = 0; for (int i = 0; i < M; ++i) { for (int x : v[i]) { que.push(x); } if (!que.empty()) { ans += que.top(); que.pop(); } } cout << ans << endl; return 0; }
#include <iostream> #include <queue> using namespace std; int main() { int N, M; cin >> N >> M; vector<vector<int>> v(M); int A, B; for (int i = 0; i < N; ++i) { cin >> A >> B; if (A > M) continue; v[A - 1].push_back(B); } priority_queue<int> que; int ans = 0; for (int i = 0; i < M; ++i) { for (int x : v[i]) { que.push(x); } if (!que.empty()) { ans += que.top(); que.pop(); } } cout << ans << endl; return 0; }
replace
8
9
8
9
TLE
p02948
C++
Runtime Error
//============================================================================ // Name : d.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include <queue> #include <vector> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> a(n), b(n); vector<vector<int>> c(m + 1); for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; c[m - a[i]].push_back(b[i]); } // for(int i=0;i<=m;i++){ // cout<<i<<endl; // for(int j=0;j<c[i].size();j++){ // cout<<c[i][j]<<' '; // }cout<<endl; // } priority_queue<int> q; int ans = 0; for (int i = m; i >= 0; i--) { for (int j = 0; j < c[i].size(); j++) { q.push(c[i][j]); } if (q.size()) { ans += q.top(); q.pop(); } } cout << ans << endl; return 0; }
//============================================================================ // Name : d.cpp // Author : // Version : // Copyright : Your copyright notice // Description : Hello World in C++, Ansi-style //============================================================================ #include <iostream> #include <queue> #include <vector> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> a(n), b(n); vector<vector<int>> c(m + 1); for (int i = 0; i < n; i++) { cin >> a[i] >> b[i]; if (m - a[i] >= 0) { c[m - a[i]].push_back(b[i]); } } // for(int i=0;i<=m;i++){ // cout<<i<<endl; // for(int j=0;j<c[i].size();j++){ // cout<<c[i][j]<<' '; // }cout<<endl; // } priority_queue<int> q; int ans = 0; for (int i = m; i >= 0; i--) { for (int j = 0; j < c[i].size(); j++) { q.push(c[i][j]); } if (q.size()) { ans += q.top(); q.pop(); } } cout << ans << endl; return 0; }
replace
20
21
20
23
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { int n, m; cin >> n >> m; ll ans = 0; vector<vector<int>> table(m + 1, vector<int>()); rep(i, n) { int a, b; cin >> a >> b; table[a].push_back(b); } priority_queue<int> pq; for (int i = 1; i < m + 1; i++) { for (auto ele : table[i]) { pq.push(ele); } if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; int main() { int n, m; cin >> n >> m; ll ans = 0; vector<vector<int>> table(m + 1, vector<int>()); rep(i, n) { int a, b; cin >> a >> b; if (a <= m) table[a].push_back(b); } priority_queue<int> pq; for (int i = 1; i < m + 1; i++) { for (auto ele : table[i]) { pq.push(ele); } if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; return 0; }
replace
13
14
13
15
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define REP(i, m, n) for (int i = (m); i < (int)(n); i++) #define rep(i, n) REP(i, 0, n) #define all(x) (x).begin(), (x).end() #define pb push_back #define mp make_pair typedef long long ll; 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; } int main() { int N, M; cin >> N >> M; vector<int> v[M]; rep(i, N) { int a, b; cin >> a >> b; a--; v[a].pb(b); } priority_queue<int> que; ll ans = 0; rep(i, M) { for (int x : v[i]) { que.push(x); } if (!que.empty()) { ans += que.top(); que.pop(); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define REP(i, m, n) for (int i = (m); i < (int)(n); i++) #define rep(i, n) REP(i, 0, n) #define all(x) (x).begin(), (x).end() #define pb push_back #define mp make_pair typedef long long ll; 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; } int main() { int N, M; cin >> N >> M; vector<int> v[M]; rep(i, N) { int a, b; cin >> a >> b; if (a > M) continue; a--; v[a].pb(b); } priority_queue<int> que; ll ans = 0; rep(i, M) { for (int x : v[i]) { que.push(x); } if (!que.empty()) { ans += que.top(); que.pop(); } } cout << ans << endl; return 0; }
insert
31
31
31
33
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; vector<vector<int>> jobs(M); for (int i = 0; i < N; i++) { int a, b; cin >> a >> b; jobs[M - a].push_back(b); } long long int ans = 0; priority_queue<int> pqueue; for (int i = 1; i <= M; i++) { for (int b : jobs[M - i]) { pqueue.push(b); } if (!pqueue.empty()) { ans += pqueue.top(); pqueue.pop(); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N, M; cin >> N >> M; vector<vector<int>> jobs(M); for (int i = 0; i < N; i++) { int a, b; cin >> a >> b; if (a > M) continue; jobs[M - a].push_back(b); } long long int ans = 0; priority_queue<int> pqueue; for (int i = 1; i <= M; i++) { for (int b : jobs[M - i]) { pqueue.push(b); } if (!pqueue.empty()) { ans += pqueue.top(); pqueue.pop(); } } cout << ans << endl; return 0; }
insert
11
11
11
13
0
p02948
C++
Runtime Error
/*by freesteed*/ #include <bits/stdc++.h> using namespace std; #define rep(i, a, n) for (int i = a; i < n; i++) #define pb push_back #define fill(x, c) memset(x, c, sizeof(x)) #define fi first #define se second #define sz(A) (int)(A.size()) #define all(x) (x).begin(), (x).end() #define caset \ int ___T; \ cin >> ___T; \ for (int cs = 1; cs <= ___T; cs++) #define get_be(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin()) // get_be biger & equal typedef long long ll; typedef pair<int, int> PII; typedef vector<int> VI; const ll mod = 1e9 + 7; const ll oo = 1e9 + 10; const int Max = 1e6 + 10; ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } void solve() { ll n, m, ans = 0; cin >> n >> m; priority_queue<int> q; vector<VI> job(m); // 第i天做job刚好到第m天拿工资 rep(i, 0, n) { int x, y; cin >> x >> y; if (x <= m) { job[m - x].pb(y); } } for (int i = m - 1; i >= 0; i--) { for (int j = 0; j < job[i].size(); j++) q.push(job[i][j]); ans += q.top(); q.pop(); } cout << ans; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); // caset{ solve(); //} return 0; }
/*by freesteed*/ #include <bits/stdc++.h> using namespace std; #define rep(i, a, n) for (int i = a; i < n; i++) #define pb push_back #define fill(x, c) memset(x, c, sizeof(x)) #define fi first #define se second #define sz(A) (int)(A.size()) #define all(x) (x).begin(), (x).end() #define caset \ int ___T; \ cin >> ___T; \ for (int cs = 1; cs <= ___T; cs++) #define get_be(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin()) // get_be biger & equal typedef long long ll; typedef pair<int, int> PII; typedef vector<int> VI; const ll mod = 1e9 + 7; const ll oo = 1e9 + 10; const int Max = 1e6 + 10; ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } void solve() { ll n, m, ans = 0; cin >> n >> m; priority_queue<int> q; vector<VI> job(m); // 第i天做job刚好到第m天拿工资 rep(i, 0, n) { int x, y; cin >> x >> y; if (x <= m) { job[m - x].pb(y); } } for (int i = m - 1; i >= 0; i--) { for (int j = 0; j < job[i].size(); j++) q.push(job[i][j]); if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); // caset{ solve(); //} return 0; }
replace
49
51
49
53
-11
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define hell 1000000007 #define M 1000000007 #define Maxi 10000000000000000 #define lcm(a, b) (a * b) / __gcd(a, b) #define ll long long #define vll vector<ll> #define vi vector<long long> #define pll vector<pair<ll, ll>> #define pb push_back // #define mp make_pair #define all(v) v.begin(), v.end() #define lbnd lower_bound #define ubnd upper_bound #define bs binary_search #define F first #define S second #define rep(i, a, b) for (i = a; i < b; i++) #define parr(a, n) \ for (i = 0; i < n; i++) \ cout << a[i] << " "; \ cout << endl; #define pcont(a) \ for (auto i : a) \ cout << i << " "; \ cout << endl; #define ret(x) return cout << x, 0; #define dbg(x) cout << #x << " is " << x << endl; // #define endl '\n' // Debug // #define trace(x) cerr << #x << ": " << x << endl; #define trace1(x) cerr << #x << ": " << x << endl; #define trace2(x, y) \ cerr << #x << ": " << x << " | " << #y << ": " << y << endl; #define trace3(x, y, z) \ cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl; #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl; #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl; #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, m; cin >> n >> m; // ll ans=0; ll i, j; vector<ll> v[200040]; for (i = 0; i < n; i++) { ll a, b; cin >> a >> b; v[a].pb(b); } // sort(all(v)); priority_queue<ll> pq; for (i = 1; i <= m; i++) { if (v[i].size()) { for (auto j : v[i]) { pq.push(j); } break; } } ll ans; ans = pq.top(); pq.pop(); for (j = i + 1; j <= m; j++) { for (auto i : v[j]) { pq.push(i); } if (pq.size() > 0) { ans += pq.top(); pq.pop(); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define hell 1000000007 #define M 1000000007 #define Maxi 10000000000000000 #define lcm(a, b) (a * b) / __gcd(a, b) #define ll long long #define vll vector<ll> #define vi vector<long long> #define pll vector<pair<ll, ll>> #define pb push_back // #define mp make_pair #define all(v) v.begin(), v.end() #define lbnd lower_bound #define ubnd upper_bound #define bs binary_search #define F first #define S second #define rep(i, a, b) for (i = a; i < b; i++) #define parr(a, n) \ for (i = 0; i < n; i++) \ cout << a[i] << " "; \ cout << endl; #define pcont(a) \ for (auto i : a) \ cout << i << " "; \ cout << endl; #define ret(x) return cout << x, 0; #define dbg(x) cout << #x << " is " << x << endl; // #define endl '\n' // Debug // #define trace(x) cerr << #x << ": " << x << endl; #define trace1(x) cerr << #x << ": " << x << endl; #define trace2(x, y) \ cerr << #x << ": " << x << " | " << #y << ": " << y << endl; #define trace3(x, y, z) \ cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << endl; #define trace4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << endl; #define trace5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl; #define trace6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl; using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, m; cin >> n >> m; // ll ans=0; ll i, j; vector<ll> v[200040]; for (i = 0; i < n; i++) { ll a, b; cin >> a >> b; v[a].pb(b); } // sort(all(v)); priority_queue<ll> pq; for (i = 1; i <= m; i++) { if (v[i].size()) { for (auto j : v[i]) { pq.push(j); } break; } } ll ans; ans = 0; if (pq.size() > 0) { ans = pq.top(); pq.pop(); } for (j = i + 1; j <= m; j++) { for (auto i : v[j]) { pq.push(i); } if (pq.size() > 0) { ans += pq.top(); pq.pop(); } } cout << ans << endl; return 0; }
replace
83
85
83
88
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(i, n) for (ll i = 0; i < n; i++) #define FOR(i, a, b) for (ll i = a; i < b; i++) #define len(v) ll(v.size()) #define fi first #define se second template <class T> void cout_vec(const vector<T> &vec) { for (auto itr : vec) cout << itr << ' '; cout << '\n'; } typedef pair<ll, ll> P; const ll mod = 1e9 + 7; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, m; cin >> n >> m; priority_queue<ll> a; vector<vector<ll>> now(m + 10); rep(i, n) { ll x, y; cin >> x >> y; now[x].push_back(y); } ll ans = 0; for (ll i = 1; i <= m; i++) { for (auto itr : now[i]) a.push(itr); if (!a.empty()) { ans += a.top(); a.pop(); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define rep(i, n) for (ll i = 0; i < n; i++) #define FOR(i, a, b) for (ll i = a; i < b; i++) #define len(v) ll(v.size()) #define fi first #define se second template <class T> void cout_vec(const vector<T> &vec) { for (auto itr : vec) cout << itr << ' '; cout << '\n'; } typedef pair<ll, ll> P; const ll mod = 1e9 + 7; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, m; cin >> n >> m; priority_queue<ll> a; vector<vector<ll>> now(m + 10); rep(i, n) { ll x, y; cin >> x >> y; if (x > m) continue; now[x].push_back(y); } ll ans = 0; for (ll i = 1; i <= m; i++) { for (auto itr : now[i]) a.push(itr); if (!a.empty()) { ans += a.top(); a.pop(); } } cout << ans << endl; }
insert
29
29
29
31
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define REP(i, m, n) for (int i = (m); i < (n); i++) #define rep(i, n) REP(i, 0, n) typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int inf = 1e9 + 7; int main() { int n, m; cin >> n >> m; vector<vector<int>> vv(m + 1); rep(i, n) { int a, b; cin >> a >> b; vv[a].push_back(b); } priority_queue<int> pq; ll ans = 0; rep(i, m) { rep(j, vv[i + 1].size()) pq.push(vv[i + 1][j]); if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define REP(i, m, n) for (int i = (m); i < (n); i++) #define rep(i, n) REP(i, 0, n) typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int inf = 1e9 + 7; int main() { int n, m; cin >> n >> m; vector<vector<int>> vv(m + 1); rep(i, n) { int a, b; cin >> a >> b; if (a <= m) vv[a].push_back(b); } priority_queue<int> pq; ll ans = 0; rep(i, m) { rep(j, vv[i + 1].size()) pq.push(vv[i + 1][j]); if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; }
replace
15
16
15
17
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; int main() { int n, m; cin >> n >> m; vector<vector<int>> jobs(m); rep(i, n) { int a, b; cin >> a >> b; if (a > m) continue; jobs[m - a].push_back(b); } priority_queue<int> q; ll ans = 0; for (int i = m - 1; i >= 0; i--) { for (int b : jobs[i]) { q.push(b); } if (q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; int main() { int n, m; cin >> n >> m; vector<vector<int>> jobs(m); rep(i, n) { int a, b; cin >> a >> b; if (a > m) continue; jobs[m - a].push_back(b); } priority_queue<int> q; ll ans = 0; for (int i = m - 1; i >= 0; i--) { for (int b : jobs[i]) { q.push(b); } if (!q.empty()) { ans += q.top(); q.pop(); } } cout << ans << endl; }
replace
23
24
23
24
-11
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; #define ll long long int priority_queue<int> q; vector<int> v[10001]; int main() { ll N, M; ll a, b; cin >> N >> M; rep(i, N) { cin >> a >> b; v[a].push_back(b); } ll res = 0; for (int i = M; i >= 1; i--) { for (int c : v[M - i + 1]) { q.push(c); } if (!q.empty()) { int x = q.top(); q.pop(); res += x; } } cout << res << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; #define ll long long int priority_queue<int> q; vector<int> v[1000005]; int main() { ll N, M; ll a, b; cin >> N >> M; rep(i, N) { cin >> a >> b; v[a].push_back(b); } ll res = 0; for (int i = M; i >= 1; i--) { for (int c : v[M - i + 1]) { q.push(c); } if (!q.empty()) { int x = q.top(); q.pop(); res += x; } } cout << res << endl; }
replace
6
7
6
7
0
p02948
C++
Runtime Error
#ifdef LOCAL #pragma GCC optimize("O0") #else #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx") #endif #include <algorithm> #include <bitset> #include <cmath> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <tuple> #include <utility> #include <vector> using namespace std; using ll = long long; using VI = vector<int>; using VVI = vector<vector<int>>; using VLL = vector<ll>; using VVLL = vector<vector<ll>>; using VB = vector<bool>; using VVB = vector<vector<bool>>; using PII = pair<int, int>; template <typename T> using minheap = priority_queue<T, vector<T>, greater<T>>; const int INF = 1e9 + 7; const ll INF_LL = (ll)1e18 + 7; #define __overload3(_1, _2, _3, name, ...) name #define rep(...) \ __overload3(__VA_ARGS__, repFromUntil, repUntil, repeat)(__VA_ARGS__) #define repeat(times) repFromUntil(__name##__LINE__, 0, times) #define repUntil(name, times) repFromUntil(name, 0, times) #define repFromUntil(name, from, until) \ for (int name = from, name##__until = (until); name < name##__until; name++) #define repr(...) \ __overload3(__VA_ARGS__, reprFromUntil, reprUntil, repeat)(__VA_ARGS__) #define reprUntil(name, times) reprFromUntil(name, 0, times) #define reprFromUntil(name, from, until) \ for (int name = until - 1, name##__from = (from); name >= name##__from; \ name--) #define EXIT(out) \ do { \ OUT(out); \ exit(0); \ } while (0) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define _1 first #define _2 second #define debug(v) \ do { \ debugos << "L" << __LINE__ << " " << #v << " > "; \ debugos << (v) << newl; \ } while (0) #define debugv(v) \ do { \ debugos << "L" << __LINE__ << " " << #v << " > "; \ for (auto e : (v)) { \ debugos << e << " "; \ } \ debugos << newl; \ } while (0) #define debuga(m, w) \ do { \ debugos << "L" << __LINE__ << " " << #m << " > "; \ for (int x = 0; x < (w); x++) { \ debugos << (m)[x] << " "; \ } \ debugos << newl; \ } while (0) #define debugaa(m, h, w) \ do { \ debugos << "L" << __LINE__ << " " << #m << " > \n"; \ for (int y = 0; y < (h); y++) { \ for (int x = 0; x < (w); x++) { \ debugos << (m)[y][x] << " "; \ } \ debugos << newl; \ } \ } while (0) #define newl "\n" constexpr int dr[] = {1, -1, 0, 0}; // LRUD constexpr int dc[] = {0, 0, 1, -1}; bool inside(int r, int c, int H, int W) { return 0 <= r and r < H and 0 <= c and c < W; } template <typename T> bool chmin(T &var, T x) { if (var > x) { var = x; return true; } else return false; } template <typename T> bool chmax(T &var, T x) { if (var < x) { var = x; return true; } else return false; } template <typename T> struct minT { T operator()(T a, T b) { return min(a, b); } }; template <typename T> struct maxT { T operator()(T a, T b) { return max(a, b); } }; template <typename T> int sgn(T val) { return (T(0) < val) - (val < T(0)); } ll power(ll e, int t, ll mod = INF_LL) { ll res = 1; while (t) { if (t & 1) res = (res * e) % mod; t >>= 1; e = (e * e) % mod; } return res; } template <typename T> T divceil(T, T); template <typename T> T divfloor(T m, T d) { if (sgn(m) * sgn(d) >= 0) return m / d; else return -divceil(abs(m), abs(d)); } template <typename T> T divceil(T m, T d) { if (m >= 0 and d > 0) return (m + d - 1) / d; else if (m < 0 and d < 0) return divceil(-m, -d); else return -divfloor(abs(m), abs(d)); } template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } string operator*(const string &s, int times) { string res = ""; rep(times) res += s; return res; } class MyScanner { public: int offset = 0; template <typename T> void input_integer(T &var) { var = 0; T sign = 1; int cc = getchar(); for (; cc < '0' || '9' < cc; cc = getchar()) if (cc == '-') sign = -1; for (; '0' <= cc && cc <= '9'; cc = getchar()) var = (var << 3) + (var << 1) + cc - '0'; var = var * sign; var += offset; } int c() { char c; while (c = getchar(), c == ' ' or c == '\n') ; return c; } MyScanner &operator>>(char &var) { var = c(); return *this; } MyScanner &operator>>(int &var) { input_integer<int>(var); return *this; } MyScanner &operator>>(ll &var) { input_integer<ll>(var); return *this; } MyScanner &operator>>(string &var) { var = ""; int cc = getchar(); for (; !isvisiblechar(cc); cc = getchar()) ; for (; isvisiblechar(cc); cc = getchar()) var.push_back(cc); return *this; } template <typename T> operator T() { T x; *this >> x; return x; } template <typename T> void operator()(T &t) { *this >> t; } template <typename T, typename... Ts> void operator()(T &t, Ts &...ts) { *this >> t; this->operator()(ts...); } template <typename Iter> void iter(Iter first, Iter last) { while (first != last) *this >> *first, first++; } VI vi(int n) { VI res(n); iter(all(res)); return res; } VVI vvi(int n, int m) { VVI res(n); rep(i, n) res[i] = vi(m); return res; } VLL vll(int n) { VLL res(n); iter(all(res)); return res; } VVLL vvll(int n, int m) { VVLL res(n); rep(i, n) res[i] = vll(m); return res; } template <typename T> vector<T> v(int n) { vector<T> res(n); iter(all(res)); return res; } private: int isvisiblechar(int c) { return 0x21 <= c && c <= 0x7E; } } IN, IN1{-1}; class MyPrinter { public: template <typename T> void output_integer(T var) { if (var == 0) { putchar('0'); return; } if (var < 0) putchar('-'), var = -var; char stack[32]; int stack_p = 0; while (var) stack[stack_p++] = '0' + (var % 10), var /= 10; while (stack_p) putchar(stack[--stack_p]); } MyPrinter &operator<<(char c) { putchar(c); return *this; } MyPrinter &operator<<(double x) { printf("%.10f\n", x); return *this; } template <typename T> MyPrinter &operator<<(T var) { output_integer<T>(var); return *this; } MyPrinter &operator<<(char *str_p) { while (*str_p) putchar(*(str_p++)); return *this; } MyPrinter &operator<<(const char *str_p) { while (*str_p) putchar(*(str_p++)); return *this; } MyPrinter &operator<<(const string &str) { const char *p = str.c_str(); const char *l = p + str.size(); while (p < l) putchar(*p++); return *this; } template <typename T> void operator()(T x) { *this << x << newl; } template <typename T, typename... Ts> void operator()(T x, Ts... xs) { *this << x << " "; this->operator()(xs...); } template <typename Iter> void iter(Iter s, Iter t) { if (s == t) *this << "\n"; else { for (; s != t; s++) { *this << *s << " \n"[next(s, 1) == t]; } } } template <typename Range> void range(const Range &r) { iter(begin(r), end(r)); } } OUT; class DebugPrint { public: template <typename T> DebugPrint &operator<<(const T &v) { #ifdef LOCAL cerr << v; #endif return *this; } } debugos; template <typename T, typename U> ostream &operator<<(ostream &out, pair<T, U> var) { return out << var.first << " " << var.second; } template <typename Tuple, size_t I, size_t N, enable_if_t<I == N> * = nullptr> ostream &tuple_impl(ostream &out, Tuple var) { return out; } template <typename Tuple, size_t I, size_t N, enable_if_t<I != N> * = nullptr> ostream &tuple_impl(ostream &out, Tuple var) { out << get<I>(var) << " "; return tuple_impl<Tuple, I + 1, N>(out, var); } template <typename... Ts> ostream &operator<<(ostream &out, tuple<Ts...> var) { return tuple_impl<tuple<Ts...>, 0, sizeof...(Ts)>(out, var); } template <typename T, typename U> MyPrinter &operator<<(MyPrinter &out, pair<T, U> var) { return out << var.first << " " << var.second; } template <typename Tuple, size_t I, size_t N, enable_if_t<I == N> * = nullptr> MyPrinter &tuple_impl(MyPrinter &out, Tuple var) { return out; } template <typename Tuple, size_t I, size_t N, enable_if_t<I != N> * = nullptr> MyPrinter &tuple_impl(MyPrinter &out, Tuple var) { out << get<I>(var) << " "; return tuple_impl<Tuple, I + 1, N>(out, var); } template <typename... Ts> MyPrinter &operator<<(MyPrinter &out, tuple<Ts...> var) { return tuple_impl<tuple<Ts...>, 0, sizeof...(Ts)>(out, var); } template <typename T, typename U> MyScanner &operator>>(MyScanner &in, pair<T, U> &var) { return in >> var.first >> var.second; } template <typename... Ts> MyScanner &operator>>(MyScanner &in, tuple<Ts...> &var) { return tuple_impl<tuple<Ts...>, 0, sizeof...(Ts)>(in, var); } template <typename Tuple, size_t I, size_t N, enable_if_t<I == N> * = nullptr> MyScanner &tuple_impl(MyScanner &in, Tuple &var) { return in; } template <typename Tuple, size_t I, size_t N, enable_if_t<I != N> * = nullptr> MyScanner &tuple_impl(MyScanner &in, Tuple &var) { in >> get<I>(var); return tuple_impl<Tuple, I + 1, N>(in, var); } int main() { int n = IN, m = IN; auto ab = IN.v<PII>(n); sort(all(ab), [&](auto a, auto b) { return get<1>(a) > get<1>(b); }); VI prev(m); iota(all(prev), 0); ll res = 0; rep(i, n) { int d = m - ab[i]._1; VI st; while (d != -1 and prev[d] != d) { st.push_back(d); d = prev[d]; } debug(ab[i]); debug(d); debugv(st); if (d != -1) res += ab[i]._2, prev[d] = d - 1, d--; for (auto s : st) prev[s] = d; debugv(prev); } OUT(res); }
#ifdef LOCAL #pragma GCC optimize("O0") #else #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx") #endif #include <algorithm> #include <bitset> #include <cmath> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <tuple> #include <utility> #include <vector> using namespace std; using ll = long long; using VI = vector<int>; using VVI = vector<vector<int>>; using VLL = vector<ll>; using VVLL = vector<vector<ll>>; using VB = vector<bool>; using VVB = vector<vector<bool>>; using PII = pair<int, int>; template <typename T> using minheap = priority_queue<T, vector<T>, greater<T>>; const int INF = 1e9 + 7; const ll INF_LL = (ll)1e18 + 7; #define __overload3(_1, _2, _3, name, ...) name #define rep(...) \ __overload3(__VA_ARGS__, repFromUntil, repUntil, repeat)(__VA_ARGS__) #define repeat(times) repFromUntil(__name##__LINE__, 0, times) #define repUntil(name, times) repFromUntil(name, 0, times) #define repFromUntil(name, from, until) \ for (int name = from, name##__until = (until); name < name##__until; name++) #define repr(...) \ __overload3(__VA_ARGS__, reprFromUntil, reprUntil, repeat)(__VA_ARGS__) #define reprUntil(name, times) reprFromUntil(name, 0, times) #define reprFromUntil(name, from, until) \ for (int name = until - 1, name##__from = (from); name >= name##__from; \ name--) #define EXIT(out) \ do { \ OUT(out); \ exit(0); \ } while (0) #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define _1 first #define _2 second #define debug(v) \ do { \ debugos << "L" << __LINE__ << " " << #v << " > "; \ debugos << (v) << newl; \ } while (0) #define debugv(v) \ do { \ debugos << "L" << __LINE__ << " " << #v << " > "; \ for (auto e : (v)) { \ debugos << e << " "; \ } \ debugos << newl; \ } while (0) #define debuga(m, w) \ do { \ debugos << "L" << __LINE__ << " " << #m << " > "; \ for (int x = 0; x < (w); x++) { \ debugos << (m)[x] << " "; \ } \ debugos << newl; \ } while (0) #define debugaa(m, h, w) \ do { \ debugos << "L" << __LINE__ << " " << #m << " > \n"; \ for (int y = 0; y < (h); y++) { \ for (int x = 0; x < (w); x++) { \ debugos << (m)[y][x] << " "; \ } \ debugos << newl; \ } \ } while (0) #define newl "\n" constexpr int dr[] = {1, -1, 0, 0}; // LRUD constexpr int dc[] = {0, 0, 1, -1}; bool inside(int r, int c, int H, int W) { return 0 <= r and r < H and 0 <= c and c < W; } template <typename T> bool chmin(T &var, T x) { if (var > x) { var = x; return true; } else return false; } template <typename T> bool chmax(T &var, T x) { if (var < x) { var = x; return true; } else return false; } template <typename T> struct minT { T operator()(T a, T b) { return min(a, b); } }; template <typename T> struct maxT { T operator()(T a, T b) { return max(a, b); } }; template <typename T> int sgn(T val) { return (T(0) < val) - (val < T(0)); } ll power(ll e, int t, ll mod = INF_LL) { ll res = 1; while (t) { if (t & 1) res = (res * e) % mod; t >>= 1; e = (e * e) % mod; } return res; } template <typename T> T divceil(T, T); template <typename T> T divfloor(T m, T d) { if (sgn(m) * sgn(d) >= 0) return m / d; else return -divceil(abs(m), abs(d)); } template <typename T> T divceil(T m, T d) { if (m >= 0 and d > 0) return (m + d - 1) / d; else if (m < 0 and d < 0) return divceil(-m, -d); else return -divfloor(abs(m), abs(d)); } template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } string operator*(const string &s, int times) { string res = ""; rep(times) res += s; return res; } class MyScanner { public: int offset = 0; template <typename T> void input_integer(T &var) { var = 0; T sign = 1; int cc = getchar(); for (; cc < '0' || '9' < cc; cc = getchar()) if (cc == '-') sign = -1; for (; '0' <= cc && cc <= '9'; cc = getchar()) var = (var << 3) + (var << 1) + cc - '0'; var = var * sign; var += offset; } int c() { char c; while (c = getchar(), c == ' ' or c == '\n') ; return c; } MyScanner &operator>>(char &var) { var = c(); return *this; } MyScanner &operator>>(int &var) { input_integer<int>(var); return *this; } MyScanner &operator>>(ll &var) { input_integer<ll>(var); return *this; } MyScanner &operator>>(string &var) { var = ""; int cc = getchar(); for (; !isvisiblechar(cc); cc = getchar()) ; for (; isvisiblechar(cc); cc = getchar()) var.push_back(cc); return *this; } template <typename T> operator T() { T x; *this >> x; return x; } template <typename T> void operator()(T &t) { *this >> t; } template <typename T, typename... Ts> void operator()(T &t, Ts &...ts) { *this >> t; this->operator()(ts...); } template <typename Iter> void iter(Iter first, Iter last) { while (first != last) *this >> *first, first++; } VI vi(int n) { VI res(n); iter(all(res)); return res; } VVI vvi(int n, int m) { VVI res(n); rep(i, n) res[i] = vi(m); return res; } VLL vll(int n) { VLL res(n); iter(all(res)); return res; } VVLL vvll(int n, int m) { VVLL res(n); rep(i, n) res[i] = vll(m); return res; } template <typename T> vector<T> v(int n) { vector<T> res(n); iter(all(res)); return res; } private: int isvisiblechar(int c) { return 0x21 <= c && c <= 0x7E; } } IN, IN1{-1}; class MyPrinter { public: template <typename T> void output_integer(T var) { if (var == 0) { putchar('0'); return; } if (var < 0) putchar('-'), var = -var; char stack[32]; int stack_p = 0; while (var) stack[stack_p++] = '0' + (var % 10), var /= 10; while (stack_p) putchar(stack[--stack_p]); } MyPrinter &operator<<(char c) { putchar(c); return *this; } MyPrinter &operator<<(double x) { printf("%.10f\n", x); return *this; } template <typename T> MyPrinter &operator<<(T var) { output_integer<T>(var); return *this; } MyPrinter &operator<<(char *str_p) { while (*str_p) putchar(*(str_p++)); return *this; } MyPrinter &operator<<(const char *str_p) { while (*str_p) putchar(*(str_p++)); return *this; } MyPrinter &operator<<(const string &str) { const char *p = str.c_str(); const char *l = p + str.size(); while (p < l) putchar(*p++); return *this; } template <typename T> void operator()(T x) { *this << x << newl; } template <typename T, typename... Ts> void operator()(T x, Ts... xs) { *this << x << " "; this->operator()(xs...); } template <typename Iter> void iter(Iter s, Iter t) { if (s == t) *this << "\n"; else { for (; s != t; s++) { *this << *s << " \n"[next(s, 1) == t]; } } } template <typename Range> void range(const Range &r) { iter(begin(r), end(r)); } } OUT; class DebugPrint { public: template <typename T> DebugPrint &operator<<(const T &v) { #ifdef LOCAL cerr << v; #endif return *this; } } debugos; template <typename T, typename U> ostream &operator<<(ostream &out, pair<T, U> var) { return out << var.first << " " << var.second; } template <typename Tuple, size_t I, size_t N, enable_if_t<I == N> * = nullptr> ostream &tuple_impl(ostream &out, Tuple var) { return out; } template <typename Tuple, size_t I, size_t N, enable_if_t<I != N> * = nullptr> ostream &tuple_impl(ostream &out, Tuple var) { out << get<I>(var) << " "; return tuple_impl<Tuple, I + 1, N>(out, var); } template <typename... Ts> ostream &operator<<(ostream &out, tuple<Ts...> var) { return tuple_impl<tuple<Ts...>, 0, sizeof...(Ts)>(out, var); } template <typename T, typename U> MyPrinter &operator<<(MyPrinter &out, pair<T, U> var) { return out << var.first << " " << var.second; } template <typename Tuple, size_t I, size_t N, enable_if_t<I == N> * = nullptr> MyPrinter &tuple_impl(MyPrinter &out, Tuple var) { return out; } template <typename Tuple, size_t I, size_t N, enable_if_t<I != N> * = nullptr> MyPrinter &tuple_impl(MyPrinter &out, Tuple var) { out << get<I>(var) << " "; return tuple_impl<Tuple, I + 1, N>(out, var); } template <typename... Ts> MyPrinter &operator<<(MyPrinter &out, tuple<Ts...> var) { return tuple_impl<tuple<Ts...>, 0, sizeof...(Ts)>(out, var); } template <typename T, typename U> MyScanner &operator>>(MyScanner &in, pair<T, U> &var) { return in >> var.first >> var.second; } template <typename... Ts> MyScanner &operator>>(MyScanner &in, tuple<Ts...> &var) { return tuple_impl<tuple<Ts...>, 0, sizeof...(Ts)>(in, var); } template <typename Tuple, size_t I, size_t N, enable_if_t<I == N> * = nullptr> MyScanner &tuple_impl(MyScanner &in, Tuple &var) { return in; } template <typename Tuple, size_t I, size_t N, enable_if_t<I != N> * = nullptr> MyScanner &tuple_impl(MyScanner &in, Tuple &var) { in >> get<I>(var); return tuple_impl<Tuple, I + 1, N>(in, var); } int main() { int n = IN, m = IN; auto ab = IN.v<PII>(n); sort(all(ab), [&](auto a, auto b) { return get<1>(a) > get<1>(b); }); VI prev(m); iota(all(prev), 0); ll res = 0; rep(i, n) { int d = m - ab[i]._1; if (d < 0) continue; VI st; while (d != -1 and prev[d] != d) { st.push_back(d); d = prev[d]; } debug(ab[i]); debug(d); debugv(st); if (d != -1) res += ab[i]._2, prev[d] = d - 1, d--; for (auto s : st) prev[s] = d; debugv(prev); } OUT(res); }
insert
390
390
390
392
0
p02948
C++
Runtime Error
#include <iostream> #include <queue> using namespace std; int n; int m; priority_queue<int> que; vector<int> t[100005]; int main() { ios::sync_with_stdio(false); cin >> n >> m; for (int i = 1, c, v; i <= n; ++i) { cin >> c >> v; t[m - c + 1].push_back(v); } int ans = 0; for (int i = m; i >= 1; --i) { for (int j = 0; j < (int)t[i].size(); ++j) { que.push(t[i][j]); } if (!que.empty()) { ans += que.top(); que.pop(); } } cout << ans << endl; return 0; }
#include <iostream> #include <queue> using namespace std; int n; int m; priority_queue<int> que; vector<int> t[100005]; int main() { ios::sync_with_stdio(false); cin >> n >> m; for (int i = 1, c, v; i <= n; ++i) { cin >> c >> v; if (m - c + 1 >= 1) { t[m - c + 1].push_back(v); } } int ans = 0; for (int i = m; i >= 1; --i) { for (int j = 0; j < (int)t[i].size(); ++j) { que.push(t[i][j]); } if (!que.empty()) { ans += que.top(); que.pop(); } } cout << ans << endl; return 0; }
replace
16
17
16
19
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<int>> vvi(m + 1); int a, b; for (int i = 0; i < n; i++) { cin >> a >> b; vvi[a].push_back(b); } int w = 0; priority_queue<int> pq; for (int i = 1; i <= m; i++) { for (int x : vvi[i]) { pq.push(x); } if (pq.empty()) continue; w += pq.top(); pq.pop(); } cout << w << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<int>> vvi(m + 1); int a, b; for (int i = 0; i < n; i++) { cin >> a >> b; if (a > m) continue; vvi[a].push_back(b); } int w = 0; priority_queue<int> pq; for (int i = 1; i <= m; i++) { for (int x : vvi[i]) { pq.push(x); } if (pq.empty()) continue; w += pq.top(); pq.pop(); } cout << w << endl; }
insert
10
10
10
12
0
p02948
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <string> #include <vector> #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define int long long int #define mod 1000000007 #define inf 1e18 + 42 #define endl "\n" #define pi 3.1415926535897932384626433832795028841971693993751058 #define maxn 100005 #define out1(a) cout << #a << " " << a << endl #define out2(a, b) cout << #a << " " << a << " " << #b << " " << b << endl #define out3(a, b, c) \ cout << #a << " " << a << " " << #b << " " << b << " " << #c << " " << c \ << endl #define rep(i, a, b) for (int i = a; i < b; i++) #define repr(i, a, b) for (int i = a; i >= b; i--) #define fori(it, A) for (auto it = A.begin(); it != A.end(); it++) #define ft first #define sd second #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define zero(x) memset(x, 0, sizeof(x)); using namespace std; int binpow(int a, int b) { int res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } // START OF CODE ->->->->->->-> void solve() { int n, m; cin >> n >> m; // map< int,priority_queue<int> > p; vector<pair<int, int>> p; rep(i, 0, n) { int a, b; cin >> a >> b; if (a <= m) { // continue; p.pb(mp(a, b)); } } int ans = 0; sort(all(p)); priority_queue<int> s; int idx = 0; rep(i, 1, m + 1) { while (idx < n && p[idx].ft <= i) { s.push(p[idx].sd); idx++; } if (!s.empty()) { ans += s.top(); s.pop(); } } cout << ans << endl; } // END OF CODE ->->->->->->->-> signed main() { fast; int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
#include <algorithm> #include <bits/stdc++.h> #include <cmath> #include <string> #include <vector> #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define int long long int #define mod 1000000007 #define inf 1e18 + 42 #define endl "\n" #define pi 3.1415926535897932384626433832795028841971693993751058 #define maxn 100005 #define out1(a) cout << #a << " " << a << endl #define out2(a, b) cout << #a << " " << a << " " << #b << " " << b << endl #define out3(a, b, c) \ cout << #a << " " << a << " " << #b << " " << b << " " << #c << " " << c \ << endl #define rep(i, a, b) for (int i = a; i < b; i++) #define repr(i, a, b) for (int i = a; i >= b; i--) #define fori(it, A) for (auto it = A.begin(); it != A.end(); it++) #define ft first #define sd second #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define zero(x) memset(x, 0, sizeof(x)); using namespace std; int binpow(int a, int b) { int res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; } // START OF CODE ->->->->->->-> void solve() { int n, m; cin >> n >> m; // map< int,priority_queue<int> > p; vector<pair<int, int>> p; rep(i, 0, n) { int a, b; cin >> a >> b; p.pb(mp(a, b)); } int ans = 0; sort(all(p)); priority_queue<int> s; int idx = 0; rep(i, 1, m + 1) { while (idx < n && p[idx].ft <= i) { s.push(p[idx].sd); idx++; } if (!s.empty()) { ans += s.top(); s.pop(); } } cout << ans << endl; } // END OF CODE ->->->->->->->-> signed main() { fast; int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
replace
60
64
60
61
0
p02948
C++
Runtime Error
#include <bits/stdc++.h> #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) using namespace std; template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(0); ll N, M; cin >> N >> M; vector<vector<ll>> B(M + 1, vector<ll>()); REP(i, N) { ll a, b; cin >> a >> b; if (a > M) continue; B[a].push_back(b); } priority_queue<ll> pq; ll ans = 0; for (ll i = 1; i <= M; i++) { if (!B[i].empty()) { for (auto j : B[i]) { pq.push(j); } } ans += pq.top(); pq.pop(); } cout << ans << endl; }
#include <bits/stdc++.h> #define REP(i, n) for (ll i = 0; i < (ll)(n); i++) using namespace std; template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; } typedef long long ll; int main() { ios::sync_with_stdio(false); cin.tie(0); ll N, M; cin >> N >> M; vector<vector<ll>> B(M + 1, vector<ll>()); REP(i, N) { ll a, b; cin >> a >> b; if (a > M) continue; B[a].push_back(b); } priority_queue<ll> pq; ll ans = 0; for (ll i = 1; i <= M; i++) { if (!B[i].empty()) { for (auto j : B[i]) { pq.push(j); } } if (!pq.empty()) { ans += pq.top(); pq.pop(); } } cout << ans << endl; }
replace
39
41
39
43
-11
p02948
C++
Runtime Error
#include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; bool compare(pair<int, int> a, pair<int, int> b) { if (a.first == b.first) return a.second < b.second; else return a.first < b.first; } int main() { int n, m; cin >> n >> m; vector<pair<int, int>> a(n); for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; } sort(a.begin(), a.end(), compare); int count = 1; priority_queue<int> que; for (int i = 0; i < n; i++) { que.push(0); } int sum = 0; int buf = 0; for (int i = 1; i <= m; i++) { for (int j = buf; a[j].first <= i; j++) { que.push(a[j].second); buf++; } sum += que.top(); que.pop(); } cout << sum << endl; return 0; }
#include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; bool compare(pair<int, int> a, pair<int, int> b) { if (a.first == b.first) return a.second < b.second; else return a.first < b.first; } int main() { int n, m; cin >> n >> m; vector<pair<int, int>> a(n); for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; } sort(a.begin(), a.end(), compare); int count = 1; priority_queue<int> que; for (int i = 0; i < m; i++) { que.push(0); } int sum = 0; int buf = 0; for (int i = 1; i <= m; i++) { for (int j = buf; a[j].first <= i; j++) { que.push(a[j].second); buf++; } sum += que.top(); que.pop(); } cout << sum << endl; return 0; }
replace
21
22
21
22
0
p02948
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iostream> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stdio.h> #include <stdlib.h> #include <vector> const long long MOD = 1000000007; using namespace std; typedef long long llong; // int isalpha(char ch): ch がアルファベットなら true を返す // int isdigit(char ch): ch が数字なら true を返す // int islower(char ch): ch が小文字なら true を返す // int isupper(char ch): ch が大文字なら true を返す // int tolower(char ch): ch の小文字を返す // int toupper(char ch): ch の大文字を返す // string型 // size() 文字数を返す // Insert() (指定した場所に)文字・文字列を挿入する // erase() (指定した場所の)文字・文字列を削除する // clear() すべての文字を削除する // substr() 文字列の(指定した)部分文字列を返す // replace() (指定した)部分文字列を新しい文字列に置換する // c_str()変換 // 文字列の比較は、<=や==などを使え // replace関数を使い、簡単に文字列を置換 // リバース関数:reverse(str.begin(), str.end()); // map<type, type> dict;で宣言 // グラフ理論用変数 // vector<vector<llong> > graph(N); // ソート // 降順sort(v.begin(), v.end(), std::greater<Type>()); // 大文字から小文字へんかん // w[i] = w[i]-'A'+'a'; // vector // assignメソッド 引数:サイズ、値 // 与えられたサイズと値でvectorを初期化する // queueクラス // find()次に取り出す値の表示をする。 // pop()値を取り出す。戻り値はなし // push()キューに値をプッシュする // priority_queueクラス // 切り上げ // ceil // floor int main() { llong N, M; cin >> N >> M; priority_queue<llong> PQ; vector<vector<llong>> Table(M + 1); pair<llong, llong> x; llong min_day = MOD; for (int i = 0; i < N; i++) { cin >> x.first >> x.second; if (x.first > M) { continue; } Table[x.first].push_back(x.second); min_day = min(x.first, min_day); } llong total = 0; llong now_day = min_day; while (now_day <= M) { for (int j = 0; j < Table[now_day].size(); j++) { PQ.push(Table[now_day][j]); } if (PQ.empty()) { now_day++; continue; } total = total + PQ.top(); PQ.pop(); } cout << total << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stdio.h> #include <stdlib.h> #include <vector> const long long MOD = 1000000007; using namespace std; typedef long long llong; // int isalpha(char ch): ch がアルファベットなら true を返す // int isdigit(char ch): ch が数字なら true を返す // int islower(char ch): ch が小文字なら true を返す // int isupper(char ch): ch が大文字なら true を返す // int tolower(char ch): ch の小文字を返す // int toupper(char ch): ch の大文字を返す // string型 // size() 文字数を返す // Insert() (指定した場所に)文字・文字列を挿入する // erase() (指定した場所の)文字・文字列を削除する // clear() すべての文字を削除する // substr() 文字列の(指定した)部分文字列を返す // replace() (指定した)部分文字列を新しい文字列に置換する // c_str()変換 // 文字列の比較は、<=や==などを使え // replace関数を使い、簡単に文字列を置換 // リバース関数:reverse(str.begin(), str.end()); // map<type, type> dict;で宣言 // グラフ理論用変数 // vector<vector<llong> > graph(N); // ソート // 降順sort(v.begin(), v.end(), std::greater<Type>()); // 大文字から小文字へんかん // w[i] = w[i]-'A'+'a'; // vector // assignメソッド 引数:サイズ、値 // 与えられたサイズと値でvectorを初期化する // queueクラス // find()次に取り出す値の表示をする。 // pop()値を取り出す。戻り値はなし // push()キューに値をプッシュする // priority_queueクラス // 切り上げ // ceil // floor int main() { llong N, M; cin >> N >> M; priority_queue<llong> PQ; vector<vector<llong>> Table(M + 1); pair<llong, llong> x; llong min_day = MOD; for (int i = 0; i < N; i++) { cin >> x.first >> x.second; if (x.first > M) { continue; } Table[x.first].push_back(x.second); min_day = min(x.first, min_day); } llong total = 0; llong now_day = min_day; while (now_day <= M) { for (int j = 0; j < Table[now_day].size(); j++) { PQ.push(Table[now_day][j]); } if (PQ.empty()) { now_day++; continue; } total = total + PQ.top(); PQ.pop(); now_day++; } cout << total << endl; return 0; }
insert
87
87
87
88
TLE
p02948
C++
Time Limit Exceeded
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; 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; } #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(vec) vec.begin(), vec.end() typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; const ll mod = 1e9 + 7; const int inf = 1 << 30; vector<vector<int>> vec; int main() { int n, m; cin >> n >> m; vec.resize(100010); rep(i, n) { int a, b; cin >> a >> b; vec[a].push_back(b); } priority_queue<int> que; ll ans = 0; for (int i = 1; i <= m; i++) { rep(j, vec[i].size()) que.push(vec[i][j]); if (que.size()) { ans += que.top(); que.pop(); } } cout << ans << endl; }
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; 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; } #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(vec) vec.begin(), vec.end() typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; const ll mod = 1e9 + 7; const int inf = 1 << 30; vector<vector<int>> vec; int main() { int n, m; cin >> n >> m; vec.resize(100010); rep(i, n) { int a, b; cin >> a >> b; vec[a].push_back(b); } priority_queue<int> que; ll ans = 0; for (int i = 1; i <= m; i++) { rep(j, vec[i].size()) que.push(vec[i][j]); if (que.size()) { ans += que.top(); que.pop(); } } cout << ans << endl; }
replace
0
1
0
1
TLE
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ipair; #define pb push_back #define MP make_pair #define ff first #define ss second #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define ABS(x) ((x) < 0 ? -(x) : (x)) ll mod = 1000000007; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<ipair> rec(n); for (int i = 0; i < n; i++) { cin >> rec[i].first >> rec[i].second; } sort(rec.begin(), rec.end()); priority_queue<ipair, vector<ipair>> pq; int p = 0; ll re = 0; for (int i = m; i > 0; i--) { while (p < n && ((rec[p].first + i - 1) <= m)) { pq.push(make_pair(rec[p].second, rec[p].first)); p++; } // cout<<p<<endl; if (!pq.empty()) { ipair temp = pq.top(); pq.pop(); // cout<<temp.first<<" "<<i<<endl; re += temp.first; } } cout << re << endl; return 0; } //-------------------------//
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ipair; #define pb push_back #define MP make_pair #define ff first #define ss second #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define ABS(x) ((x) < 0 ? -(x) : (x)) ll mod = 1000000007; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<ipair> rec(n); for (int i = 0; i < n; i++) { cin >> rec[i].first >> rec[i].second; } sort(rec.begin(), rec.end()); priority_queue<ipair, vector<ipair>> pq; int p = 0; ll re = 0; for (int i = m; i > 0; i--) { while (p < n && ((rec[p].first + i - 1) <= m)) { pq.push(make_pair(rec[p].second, rec[p].first)); p++; } // cout<<p<<endl; if (!pq.empty()) { ipair temp = pq.top(); pq.pop(); // cout<<temp.first<<" "<<i<<endl; re += temp.first; } } cout << re << endl; return 0; } //-------------------------//
replace
17
21
17
18
TLE
p02948
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; signed main() { cin.tie(0); ios::sync_with_stdio(false); long N, M; cin >> N >> M; vector<vector<long>> v(M + 2); priority_queue<long> q; long A; int B; for (long i = 0; i < N; i++) { cin >> A >> B; v[A].push_back(B); } long long t = 0; pair<int, long> tp; for (long D = 1; D < M + 1; D++) { for (auto &vv : v[D]) q.push(vv); if (q.size() > 0) { t += q.top(); q.pop(); } } cout << t << endl; return 0; }
#include <bits/stdc++.h> using namespace std; signed main() { cin.tie(0); ios::sync_with_stdio(false); long N, M; cin >> N >> M; vector<vector<long>> v(100010); priority_queue<long> q; long A; int B; for (long i = 0; i < N; i++) { cin >> A >> B; v[A].push_back(B); } long long t = 0; pair<int, long> tp; for (long D = 1; D < M + 1; D++) { for (auto &vv : v[D]) q.push(vv); if (q.size() > 0) { t += q.top(); q.pop(); } } cout << t << endl; return 0; }
replace
10
11
10
11
0