Submission #2097575
Source Code Expand
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #define pb push_back #define fs first #define sc second #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<double> vd; typedef pair<int, int> pii; typedef pair<ll, int> plli; typedef vector<pii> vpii; typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ost; const int N=210000; const ll P=1e9+7; const ll INFTY=1e18; vll b[N]; ll f[N], invf[N]; ll pw(ll x, ll n) { ll ans=1; while(n) { if(n&1) ans=ans*x%P, n--; x=x*x%P, n/=2; } return ans; } int main() { ll i, j, k, m, n, x, y, c, w, ans; scanf("%lld%lld%lld", &n, &x, &y); f[0]=invf[0]=1; for(i=1; i<=n; i++) { f[i]=f[i-1]*i%P; invf[i]=pw(f[i], P-2); } for(i=0; i<n; i++) { scanf("%lld%lld", &c, &w); b[c-1].pb(w); b[i].pb(INFTY); } for(i=0; i<n; i++) sort(all(b[i])); sort(b, b+n, [](vll &v1, vll &v2) { return v1[0]<v2[0]; }); for(k=n-1; k>0 && b[k][0]+b[0][0]>y; k--); if(k>0) k++; ans=1; for(m=i=0; i<k; i++) { for(j=1; ; j++) { c=(i==0); if(b[i][j]+b[i][0]>x && b[i][j]+b[c][0]>y) break; } m+=j; ans=ans*invf[j]%P; } ans=ans*f[m]%P; printf("%lld\n", ans); return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - Colorful Balls |
User | Ajira |
Language | C++14 (GCC 5.4.1) |
Score | 1000 |
Code Size | 1579 Byte |
Status | AC |
Exec Time | 144 ms |
Memory | 17152 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:39:38: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%lld%lld%lld", &n, &x, &y); ^ ./Main.cpp:46:34: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%lld%lld", &c, &w); ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1000 / 1000 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt |
All | 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, 49.txt, 50.txt, 51.txt, 52.txt, 53.txt, 54.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_example_01.txt | AC | 4 ms | 6524 KB |
00_example_02.txt | AC | 3 ms | 6400 KB |
00_example_03.txt | AC | 3 ms | 6400 KB |
01.txt | AC | 3 ms | 6400 KB |
02.txt | AC | 3 ms | 6400 KB |
03.txt | AC | 7 ms | 6784 KB |
04.txt | AC | 3 ms | 6400 KB |
05.txt | AC | 4 ms | 6528 KB |
06.txt | AC | 3 ms | 6400 KB |
07.txt | AC | 57 ms | 11392 KB |
08.txt | AC | 3 ms | 6528 KB |
09.txt | AC | 31 ms | 9856 KB |
10.txt | AC | 21 ms | 8448 KB |
11.txt | AC | 3 ms | 6400 KB |
12.txt | AC | 3 ms | 6400 KB |
13.txt | AC | 7 ms | 6784 KB |
14.txt | AC | 3 ms | 6400 KB |
15.txt | AC | 26 ms | 8576 KB |
16.txt | AC | 58 ms | 11520 KB |
17.txt | AC | 11 ms | 7296 KB |
18.txt | AC | 24 ms | 8960 KB |
19.txt | AC | 48 ms | 11392 KB |
20.txt | AC | 144 ms | 15616 KB |
21.txt | AC | 136 ms | 15616 KB |
22.txt | AC | 137 ms | 15616 KB |
23.txt | AC | 138 ms | 15616 KB |
24.txt | AC | 136 ms | 15616 KB |
25.txt | AC | 137 ms | 15616 KB |
26.txt | AC | 141 ms | 15616 KB |
27.txt | AC | 140 ms | 15616 KB |
28.txt | AC | 138 ms | 15616 KB |
29.txt | AC | 140 ms | 15616 KB |
30.txt | AC | 138 ms | 15616 KB |
31.txt | AC | 138 ms | 15616 KB |
32.txt | AC | 138 ms | 15616 KB |
33.txt | AC | 138 ms | 15616 KB |
34.txt | AC | 130 ms | 16256 KB |
35.txt | AC | 98 ms | 16512 KB |
36.txt | AC | 113 ms | 16896 KB |
37.txt | AC | 99 ms | 17152 KB |
38.txt | AC | 99 ms | 16640 KB |
39.txt | AC | 102 ms | 16768 KB |
40.txt | AC | 142 ms | 16384 KB |
41.txt | AC | 132 ms | 15360 KB |
42.txt | AC | 132 ms | 15360 KB |
43.txt | AC | 132 ms | 15488 KB |
44.txt | AC | 136 ms | 15360 KB |
45.txt | AC | 130 ms | 15488 KB |
46.txt | AC | 133 ms | 15488 KB |
47.txt | AC | 100 ms | 16240 KB |
48.txt | AC | 104 ms | 16240 KB |
49.txt | AC | 102 ms | 16240 KB |
50.txt | AC | 104 ms | 15348 KB |
51.txt | AC | 107 ms | 15348 KB |
52.txt | AC | 96 ms | 16500 KB |
53.txt | AC | 96 ms | 16500 KB |
54.txt | AC | 98 ms | 16500 KB |