Submission #102452

#TimeUsernameProblemLanguageResultExecution timeMemory
102452jwvg0425마스코트 (JOI13_mascots)C++17
100 / 100
468 ms213520 KiB
#include <stdio.h> #include <vector> #include <queue> #include <algorithm> #include <iostream> #include <string> #include <bitset> #include <map> #include <set> #include <tuple> #include <string.h> #include <math.h> #include <random> #include <functional> #include <assert.h> #include <math.h> #include <iterator> #include <chrono> #define MOD 1000000007 #define all(x) (x).begin(), (x).end() #define xx first #define yy second using namespace std; using i64 = long long int; using ii = pair<int, int>; using ii64 = pair<i64, i64>; using vi = vector<long long int>; i64 table[3005][3005]; i64 ctable[3005][3005]; int r, c, n; i64 facto[9000005]; i64 solve(int w, int h) { if (w > r || h > c) return 0; if (w == r && h == c) return 1; if (table[w][h] != -1) return table[w][h]; auto& res = table[w][h]; i64 lr = (facto[h] * solve(w + 1, h)) % MOD; i64 ud = (facto[w] * solve(w, h + 1)) % MOD; res = (lr + ud) % MOD; return res; } i64 comb(int n, int k) { if (k == 0 || k == n) return 1; if (ctable[n][k] != -1) return ctable[n][k]; auto& res = ctable[n][k]; res = (comb(n - 1, k - 1) + comb(n - 1, k)) % MOD; return res; } int main() { memset(table, -1, sizeof(table)); memset(ctable, -1, sizeof(ctable)); scanf("%d %d %d", &r, &c, &n); int lx = r, rx = 0, ly = c, ry = 0; facto[0] = 1; for (int i = 1; i <= r * c; i++) facto[i] = (facto[i - 1] * i) % MOD; for (int i = 0; i < n; i++) { int x, y; scanf("%d %d", &x, &y); lx = min(lx, x); rx = max(rx, x); ly = min(ly, y); ry = max(ry, y); } int w = rx - lx + 1; int h = ry - ly + 1; int count = w * h - n; i64 ans = (facto[count] * solve(w, h)) % MOD; // 좌,우 / 상, 하 고르는 경우 끼워넣는다 ans = (ans * comb(r - w, r - rx)) % MOD; ans = (ans * comb(c - h, c - ry)) % MOD; printf("%lld\n", ans); return 0; }

Compilation message (stderr)

mascots.cpp: In function 'int main()':
mascots.cpp:76:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &r, &c, &n);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
mascots.cpp:88:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &x, &y);
   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...