Submission #1197178
Source Code Expand
#include<bits/stdc++.h> #define X first #define Y second using namespace std; typedef long long ll; const ll mod = 1e9+7, inf = 1e18; ll n, cc, x, y, mn[200005], a[200005], b[200005], fac[200005], ans = 1; vector<pair<ll, ll> > grp[400005]; priority_queue<pair<ll, ll> > pq; ll calc (ll X, ll Y) { if(!Y) return 1; ll ret = calc(X, Y/2); ret = (ret * ret) % mod; if(Y&1) ret = (ret * X) % mod; return ret; } int main() { scanf("%lld%lld%lld",&n,&x,&y); for(int i=1;i<=n;i++) { scanf("%lld%lld",&a[i],&b[i]); grp[a[i]].push_back({b[i], a[i]}); cc = max(cc, a[i]); } for(int i=1;i<=cc;i++) { if(grp[i].empty()) continue; sort(grp[i].begin(), grp[i].end()); mn[i] = grp[i][0].X; pq.push({-mn[i], i}); } ll idx = pq.top().Y; pq.pop(); while(!pq.empty()) { ll cur = pq.top().Y; pq.pop(); if(grp[cur][0].X + grp[idx][0].X > y) break; while(grp[cur].size()) { grp[idx].push_back(grp[cur].back()); grp[cur].pop_back(); } } for(int i=1;i<=cc;i++) { if(grp[i].empty()) continue; sort(grp[i].begin(), grp[i].end()); ll b1 = grp[i][0].X, i1 = grp[i][0].Y, b2 = inf; for(int j=1;j<grp[i].size();j++) { if(grp[i][j].Y != i1) {b2 = grp[i][j].X;} } vector<pair<ll, ll> >tmp; tmp.push_back(grp[i][0]); for(int j=1;j<grp[i].size();j++) { if((i1 == grp[i][j].Y ? b2 : b1) + grp[i][j].X > y && grp[i][j].X + mn[grp[i][j].Y] > x) { grp[++cc].push_back(grp[i][j]); } else tmp.push_back(grp[i][j]); } swap(grp[i], tmp); } fac[0] = 1; for(int i=1;i<=n;i++) fac[i] = fac[i-1] * i % mod; for(int i=1;i<=cc;i++) { if(grp[i].empty()) continue; for(int j=0;j<grp[i].size();j++) swap(grp[i][j].X, grp[i][j].Y); sort(grp[i].begin(), grp[i].end()); ans = (ans * fac[grp[i].size()]) % mod; ll cur = 1; for(int j=1;j<grp[i].size();j++) { if(grp[i][j].X != grp[i][j-1].X) { ans = (ans * calc(fac[cur], mod-2)) % mod; cur = 1; } else cur++; } ans = (ans * calc(fac[cur], mod-2)) % mod; } printf("%lld\n",ans); }
Submission Info
Submission Time | |
---|---|
Task | D - Colorful Balls |
User | khsoo01 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 2072 Byte |
Status | WA |
Exec Time | 188 ms |
Memory | 35440 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:21:32: 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:23:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%lld%lld",&a[i],&b[i]); ^
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | 5 ms | 14592 KB |
00_example_02.txt | AC | 5 ms | 14592 KB |
00_example_03.txt | AC | 5 ms | 14592 KB |
01.txt | WA | 6 ms | 14592 KB |
02.txt | AC | 5 ms | 14592 KB |
03.txt | AC | 10 ms | 15104 KB |
04.txt | AC | 5 ms | 14592 KB |
05.txt | AC | 7 ms | 14848 KB |
06.txt | AC | 6 ms | 14592 KB |
07.txt | WA | 74 ms | 22132 KB |
08.txt | AC | 6 ms | 14592 KB |
09.txt | WA | 30 ms | 18568 KB |
10.txt | WA | 24 ms | 17140 KB |
11.txt | AC | 6 ms | 14592 KB |
12.txt | AC | 5 ms | 14592 KB |
13.txt | AC | 11 ms | 15232 KB |
14.txt | AC | 5 ms | 14592 KB |
15.txt | AC | 35 ms | 18296 KB |
16.txt | AC | 80 ms | 20592 KB |
17.txt | AC | 14 ms | 15740 KB |
18.txt | AC | 29 ms | 17464 KB |
19.txt | WA | 58 ms | 20208 KB |
20.txt | AC | 167 ms | 28532 KB |
21.txt | AC | 181 ms | 28660 KB |
22.txt | AC | 162 ms | 26740 KB |
23.txt | AC | 179 ms | 33008 KB |
24.txt | AC | 174 ms | 26228 KB |
25.txt | AC | 166 ms | 28404 KB |
26.txt | AC | 180 ms | 33008 KB |
27.txt | AC | 134 ms | 23284 KB |
28.txt | AC | 175 ms | 33904 KB |
29.txt | AC | 176 ms | 32368 KB |
30.txt | AC | 179 ms | 25204 KB |
31.txt | AC | 177 ms | 32496 KB |
32.txt | AC | 163 ms | 27124 KB |
33.txt | WA | 188 ms | 35056 KB |
34.txt | AC | 171 ms | 33136 KB |
35.txt | WA | 86 ms | 28784 KB |
36.txt | AC | 121 ms | 32876 KB |
37.txt | WA | 89 ms | 30188 KB |
38.txt | WA | 86 ms | 28524 KB |
39.txt | AC | 96 ms | 31084 KB |
40.txt | AC | 181 ms | 34288 KB |
41.txt | AC | 171 ms | 31600 KB |
42.txt | AC | 180 ms | 31728 KB |
43.txt | AC | 158 ms | 28016 KB |
44.txt | AC | 185 ms | 35440 KB |
45.txt | AC | 160 ms | 27248 KB |
46.txt | AC | 164 ms | 30192 KB |
47.txt | AC | 92 ms | 24556 KB |
48.txt | AC | 114 ms | 23788 KB |
49.txt | AC | 99 ms | 22124 KB |
50.txt | WA | 137 ms | 27372 KB |
51.txt | AC | 93 ms | 24432 KB |
52.txt | AC | 99 ms | 24172 KB |
53.txt | WA | 98 ms | 24172 KB |
54.txt | WA | 104 ms | 24428 KB |