Submission #1882846
Source Code Expand
#include <bits/stdc++.h> #define x first #define y second #define y1 secondy1 #define rank tipa_rank #define pb push_back #define mp make_pair #define pow10 tipa_pow10 #define ll long long #define INF 1000000000 #define EPS 1e-9 #define EPS2 1e-8 #define PI acos(-1.0) using namespace std; const int MOD = INF + 7; int n , x, y; int cntByColour[200000]; int c[200000] , w[200000]; ll fact[200005]; bool good[200000]; vector<int> colWeight[200000]; vector<pair<int , int> > weight; ll mod = 1000 * 1000 * 1000 + 7; ll gcdExtended(ll a, ll b, ll *x, ll *y); // Function to find modulo inverse of a ll modInverse(ll a, ll m) { ll x, y; ll g = gcdExtended(a, m, &x, &y); if (g != 1) cout << "Inverse doesn't exist"; else { // m is added to handle negative x ll res = (x%m + m) % m; return res; } } // C function for extended Euclidean Algorithm ll gcdExtended(ll a, ll b, ll *x, ll *y) { // Base Case if (a == 0) { *x = 0, *y = 1; return b; } ll x1, y1; // To store results of recursive call ll gcd = gcdExtended(b%a, a, &x1, &y1); // Update x and y using results of recursive // call *x = y1 - (b/a) * x1; *y = x1; return gcd; } int main() { fact[0] = 1; for(int i = 1; i <= 200000; i++) fact[i] = (fact[i - 1] * i) % MOD; scanf("%d %d %d" , &n , &x , &y); for(int i = 0; i < n; i++) { scanf("%d %d" , &c[i] , &w[i]); c[i]--; colWeight[c[i]].pb(w[i]); weight.pb(mp(w[i] , c[i])); } sort(weight.begin() , weight.end()); for(int i = 0; i < n; i++) sort(colWeight[i].begin() , colWeight[i].end()); ll ans = 1; auto it = lower_bound(weight.begin() , weight.end() , mp(y - weight[0].first + 1, 0)); //cout << it->first << " " << it->second << endl; for(auto it2 = weight.begin(); it2 != it; it2++) { good[it2->second] = true; cntByColour[it2->second]++; } int cnt = 0; for(int i = 0; i < n; i++) { if(!good[i]) continue; if(!colWeight[i].size()) continue; auto It = upper_bound(colWeight[i].begin() , colWeight[i].end() , x - colWeight[i][0]); for(auto it2 = colWeight[i].begin(); it2 != It; it2++) { if(!binary_search(weight.begin() , it , mp(*it2 , i))) { cntByColour[i]++; cnt++; } } } ans *= fact[it - weight.begin() + cnt]; for(int i = 0; i < n; i++) { ans *= modInverse(fact[cntByColour[i]] , MOD); ans %= MOD; } ans %= MOD; cout << ans; }
Submission Info
Submission Time | |
---|---|
Task | D - Colorful Balls |
User | vjudge2 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 2441 Byte |
Status | WA |
Exec Time | 119 ms |
Memory | 14960 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:66:34: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d %d %d" , &n , &x , &y); ^ ./Main.cpp:69:33: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d %d" , &c[i] , &w[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 | 8448 KB |
00_example_02.txt | AC | 5 ms | 8448 KB |
00_example_03.txt | AC | 5 ms | 8448 KB |
01.txt | AC | 5 ms | 8448 KB |
02.txt | AC | 5 ms | 8448 KB |
03.txt | AC | 8 ms | 8576 KB |
04.txt | AC | 5 ms | 8448 KB |
05.txt | AC | 6 ms | 8448 KB |
06.txt | AC | 5 ms | 8448 KB |
07.txt | AC | 49 ms | 10360 KB |
08.txt | AC | 5 ms | 8448 KB |
09.txt | AC | 28 ms | 9308 KB |
10.txt | AC | 20 ms | 9212 KB |
11.txt | AC | 5 ms | 8448 KB |
12.txt | AC | 5 ms | 8448 KB |
13.txt | AC | 8 ms | 8576 KB |
14.txt | AC | 5 ms | 8448 KB |
15.txt | AC | 25 ms | 9596 KB |
16.txt | AC | 43 ms | 10360 KB |
17.txt | AC | 11 ms | 8704 KB |
18.txt | AC | 23 ms | 9216 KB |
19.txt | AC | 40 ms | 9976 KB |
20.txt | AC | 106 ms | 14576 KB |
21.txt | AC | 90 ms | 14576 KB |
22.txt | AC | 91 ms | 14576 KB |
23.txt | AC | 100 ms | 14576 KB |
24.txt | AC | 91 ms | 14576 KB |
25.txt | AC | 106 ms | 14576 KB |
26.txt | AC | 93 ms | 14576 KB |
27.txt | AC | 89 ms | 13936 KB |
28.txt | AC | 119 ms | 14576 KB |
29.txt | AC | 113 ms | 14576 KB |
30.txt | AC | 91 ms | 14576 KB |
31.txt | AC | 110 ms | 14576 KB |
32.txt | AC | 99 ms | 14576 KB |
33.txt | AC | 117 ms | 14576 KB |
34.txt | AC | 112 ms | 13808 KB |
35.txt | WA | 72 ms | 11460 KB |
36.txt | AC | 95 ms | 12144 KB |
37.txt | WA | 75 ms | 11760 KB |
38.txt | WA | 71 ms | 11364 KB |
39.txt | AC | 83 ms | 11760 KB |
40.txt | AC | 112 ms | 14448 KB |
41.txt | AC | 102 ms | 14960 KB |
42.txt | AC | 89 ms | 14960 KB |
43.txt | AC | 91 ms | 14960 KB |
44.txt | AC | 94 ms | 14960 KB |
45.txt | AC | 91 ms | 14960 KB |
46.txt | AC | 103 ms | 14960 KB |
47.txt | AC | 78 ms | 11244 KB |
48.txt | AC | 77 ms | 11244 KB |
49.txt | AC | 78 ms | 11244 KB |
50.txt | AC | 66 ms | 13676 KB |
51.txt | AC | 66 ms | 13548 KB |
52.txt | AC | 75 ms | 11120 KB |
53.txt | AC | 75 ms | 11120 KB |
54.txt | AC | 75 ms | 11120 KB |