Submission #1518448
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];
int 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) {
FOR(j, 1, 3002) {
int x = min(3001, j + diff), y = min(3001, i + diff);
int cnt = getSum(i, j, y, x);
if (!f) {
if (cnt >= K) return true;
continue;
}
int u = getSum(i, j, i, x);
int l = getSum(i, j, y, j);
ll now = ncr(cnt, K);
now += MOD - ncr(cnt - u, K);
now += MOD - ncr(cnt - l, K);
now += ncr(cnt - u - l, 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, 3002) REP(j, 3001) sum[i][j + 1] += sum[i][j];
REP(i, 3001) REP(j, 3002) 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
2017-08-18 13:06:54+0900
Task
D - アットコーダーモンスターズ
User
tkmst201
Language
C++14 (GCC 5.4.1)
Score
100
Code Size
2413 Byte
Status
AC
Exec Time
350 ms
Memory
37760 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:82:35: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", atk + i, def + i);
^
Judge Result
Set Name
Sample
Subtask1
All
Score / Max Score
0 / 0
10 / 10
90 / 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
123 ms
35456 KB
subtask0_sample_02.txt
AC
196 ms
35456 KB
subtask0_sample_03.txt
AC
104 ms
35456 KB
subtask0_sample_04.txt
AC
289 ms
35456 KB
subtask1_random01.txt
AC
160 ms
35456 KB
subtask1_random02.txt
AC
104 ms
35456 KB
subtask1_random03.txt
AC
123 ms
35456 KB
subtask1_random04.txt
AC
123 ms
35456 KB
subtask1_random05.txt
AC
123 ms
35456 KB
subtask1_random06.txt
AC
160 ms
35456 KB
subtask1_random07.txt
AC
104 ms
35456 KB
subtask1_random08.txt
AC
104 ms
35456 KB
subtask1_random09.txt
AC
141 ms
35456 KB
subtask1_random10.txt
AC
122 ms
35456 KB
subtask2_random01.txt
AC
268 ms
37760 KB
subtask2_random02.txt
AC
257 ms
37760 KB
subtask2_random03.txt
AC
278 ms
37760 KB
subtask2_random04.txt
AC
256 ms
37760 KB
subtask2_random05.txt
AC
207 ms
37760 KB
subtask2_random06.txt
AC
171 ms
37760 KB
subtask2_random07.txt
AC
259 ms
37760 KB
subtask2_random08.txt
AC
187 ms
37760 KB
subtask2_random09.txt
AC
239 ms
37760 KB
subtask2_random10.txt
AC
228 ms
37760 KB
subtask2_random11.txt
AC
198 ms
37760 KB
subtask2_random12.txt
AC
235 ms
37760 KB
subtask2_random13.txt
AC
161 ms
37760 KB
subtask2_random14.txt
AC
228 ms
37760 KB
subtask2_random15.txt
AC
197 ms
37760 KB
subtask2_random16.txt
AC
176 ms
37760 KB
subtask2_random17.txt
AC
195 ms
37760 KB
subtask2_random18.txt
AC
196 ms
37760 KB
subtask2_random19.txt
AC
177 ms
37760 KB
subtask2_random20.txt
AC
214 ms
37760 KB
subtask2_special01.txt
AC
350 ms
37760 KB
subtask2_special02.txt
AC
246 ms
37760 KB
subtask2_special03.txt
AC
124 ms
37760 KB
subtask2_special04.txt
AC
120 ms
37760 KB
subtask2_special05.txt
AC
120 ms
37760 KB
subtask2_special06.txt
AC
139 ms
37760 KB
subtask2_special07.txt
AC
139 ms
37760 KB