Submission #1518341
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;
const bool debug = 0;
//----------------------//
ll mod_pow(ll x, ll n, ll mod) {
if (n == 0) return 1;
ll res = mod_pow(x * x % mod, n / 2, mod);
if (n & 1) res = res * x % mod;
return res;
}
vector<ll> fact, inv;
void fact_inv(int n, ll mod) {
fact.resize(n + 1);
inv.resize(n + 1);
fact[0] = 1;
FOR(i, 1, n + 1) fact[i] = fact[i - 1] * i % mod;
inv[n] = mod_pow(fact[n], mod - 2, mod);
for (int i = n; i > 0; i--) inv[i - 1] = inv[i] * i % mod;
}
ll ncr(ll n, ll r, ll mod = MOD) {
if (n < r || r < 0 || n < 0) return 0;
return fact[n] * inv[r] % mod * inv[n - r] % mod;
}
int N, K;
int atk[112345], def[112345];
int sum[3002][3002];
ll getSum(int y1, int x1, int y2, int x2) {
return sum[y2][x2] - sum[y1 - 1][x2] - sum[y2][x1 - 1] + sum[y1 - 1][x1 - 1];
}
ll solve(int diff, bool f) {
ll res = 0;
FOR(i, 1, 3002 - diff) {
FOR(j, 1, 3002 - diff) {
int cnt = getSum(i, j, i + diff, j + diff);
if (!f) {
if (cnt >= K) return true;
continue;
}
int corner = getSum(i + diff, j + diff, i + diff, j + diff);
int r = getSum(i, j, i + diff, j) - corner;
int d = getSum(i, j, i, j + diff) - corner;
ll now = ncr(cnt, K) - ncr(cnt - corner, K) + MOD;
now += ncr(cnt - corner, K);
now += MOD - ncr(cnt - corner - r, K);
now += MOD - ncr(cnt - corner - d, K);
now += ncr(cnt - corner - r - d, K);
res = (res + now) % MOD;
}
}
return res;
}
int main() {
cin >> N >> K;
REP(i, N) scanf("%d %d", atk + i, def + i), atk[i]++, def[i]++;
REP(i, N) sum[atk[i]][def[i]]++;
REP(i, 3001) REP(j, 3001) sum[i][j + 1] += sum[i][j];
REP(j, 3001) REP(i, 3001) sum[i + 1][j] += sum[i][j];
fact_inv(N, MOD);
int l = -1, r = 3000;
while (r - l > 1) {
int m = (l + r) / 2;
if (solve(m, false)) r = m;
else l = m;
}
cout << r << endl;
cout << solve(r, true) << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
D - アットコーダーモンスターズ |
User |
tkmst201 |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
2543 Byte |
Status |
WA |
Exec Time |
301 ms |
Memory |
37760 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:79:64: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
REP(i, N) scanf("%d %d", atk + i, def + i), atk[i]++, def[i]++;
^
Judge Result
Set Name |
Sample |
Subtask1 |
All |
Score / Max Score |
0 / 0 |
0 / 10 |
0 / 90 |
Status |
|
|
|
Set Name |
Test Cases |
Sample |
subtask0_sample_01.txt, subtask0_sample_02.txt, subtask0_sample_03.txt, subtask0_sample_04.txt |
Subtask1 |
subtask0_sample_01.txt, subtask0_sample_02.txt, subtask0_sample_03.txt, subtask1_random01.txt, subtask1_random02.txt, subtask1_random03.txt, subtask1_random04.txt, subtask1_random05.txt, subtask1_random06.txt, subtask1_random07.txt, subtask1_random08.txt, subtask1_random09.txt, subtask1_random10.txt |
All |
subtask0_sample_01.txt, subtask0_sample_02.txt, subtask0_sample_03.txt, subtask0_sample_04.txt, subtask1_random01.txt, subtask1_random02.txt, subtask1_random03.txt, subtask1_random04.txt, subtask1_random05.txt, subtask1_random06.txt, subtask1_random07.txt, subtask1_random08.txt, subtask1_random09.txt, subtask1_random10.txt, subtask2_random01.txt, subtask2_random02.txt, subtask2_random03.txt, subtask2_random04.txt, subtask2_random05.txt, subtask2_random06.txt, subtask2_random07.txt, subtask2_random08.txt, subtask2_random09.txt, subtask2_random10.txt, subtask2_random11.txt, subtask2_random12.txt, subtask2_random13.txt, subtask2_random14.txt, subtask2_random15.txt, subtask2_random16.txt, subtask2_random17.txt, subtask2_random18.txt, subtask2_random19.txt, subtask2_random20.txt, subtask2_special01.txt, subtask2_special02.txt, subtask2_special03.txt, subtask2_special04.txt, subtask2_special05.txt, subtask2_special06.txt, subtask2_special07.txt |
Case Name |
Status |
Exec Time |
Memory |
subtask0_sample_01.txt |
AC |
159 ms |
35456 KB |
subtask0_sample_02.txt |
AC |
217 ms |
35456 KB |
subtask0_sample_03.txt |
AC |
143 ms |
35456 KB |
subtask0_sample_04.txt |
AC |
301 ms |
35456 KB |
subtask1_random01.txt |
WA |
193 ms |
35456 KB |
subtask1_random02.txt |
AC |
142 ms |
35456 KB |
subtask1_random03.txt |
AC |
159 ms |
35456 KB |
subtask1_random04.txt |
WA |
159 ms |
35456 KB |
subtask1_random05.txt |
WA |
159 ms |
35584 KB |
subtask1_random06.txt |
WA |
192 ms |
35456 KB |
subtask1_random07.txt |
AC |
142 ms |
35456 KB |
subtask1_random08.txt |
AC |
142 ms |
35456 KB |
subtask1_random09.txt |
AC |
175 ms |
35456 KB |
subtask1_random10.txt |
AC |
159 ms |
35456 KB |
subtask2_random01.txt |
AC |
177 ms |
37760 KB |
subtask2_random02.txt |
AC |
72 ms |
37760 KB |
subtask2_random03.txt |
AC |
67 ms |
37760 KB |
subtask2_random04.txt |
AC |
72 ms |
37760 KB |
subtask2_random05.txt |
WA |
72 ms |
37760 KB |
subtask2_random06.txt |
AC |
97 ms |
37760 KB |
subtask2_random07.txt |
AC |
64 ms |
37760 KB |
subtask2_random08.txt |
AC |
125 ms |
37760 KB |
subtask2_random09.txt |
WA |
63 ms |
37760 KB |
subtask2_random10.txt |
AC |
88 ms |
37760 KB |
subtask2_random11.txt |
AC |
226 ms |
37760 KB |
subtask2_random12.txt |
AC |
255 ms |
37760 KB |
subtask2_random13.txt |
WA |
196 ms |
37760 KB |
subtask2_random14.txt |
AC |
250 ms |
37760 KB |
subtask2_random15.txt |
AC |
221 ms |
37760 KB |
subtask2_random16.txt |
AC |
209 ms |
37760 KB |
subtask2_random17.txt |
AC |
223 ms |
37760 KB |
subtask2_random18.txt |
AC |
225 ms |
37760 KB |
subtask2_random19.txt |
AC |
207 ms |
37760 KB |
subtask2_random20.txt |
AC |
241 ms |
37760 KB |
subtask2_special01.txt |
WA |
64 ms |
37760 KB |
subtask2_special02.txt |
AC |
81 ms |
37760 KB |
subtask2_special03.txt |
WA |
167 ms |
37760 KB |
subtask2_special04.txt |
AC |
160 ms |
37760 KB |
subtask2_special05.txt |
AC |
159 ms |
37760 KB |
subtask2_special06.txt |
AC |
175 ms |
37760 KB |
subtask2_special07.txt |
AC |
175 ms |
37760 KB |