Submission #35236

# Submission time Handle Problem Language Result Execution time Memory
35236 2017-11-19T08:07:45 Z bql20000 마스코트 (JOI13_mascots) C++14
100 / 100
283 ms 213936 KB
#include <bits/stdc++.h>

#define ff(i,a,b)       for(int i=(a), _b=(b); i<=_b; ++i)
#define gg(i,a,b)       for(int i=(a), _b=(b); i>=_b; --i)
#define REP(i,b)        for(int i=(0), _b=(b); i< _b; ++i)
#define endl            '\n'
#define long            long long
#define ALL(x)          (x).begin(), (x).end()
#define Love(a)         {cerr << #a << " = " << a << endl;}
#define _               << "," <<
#define BIT(i, x)       (((x)>>(i))&1)
#define X               first
#define Y               second

#define NAME            "MASCOTS"

using namespace std;
const int N = 3e3 + 7;
const int MOD = 1e9 + 7;

int n, m, k, a, b, c, d;
long p[N*N], ans, dp[N][N], CC[N][N];

void Enter() {
    scanf("%d%d%d", &m, &n, &k);

    a = N;
    b = N;

    ff(i, 1, k) {
        int x , y;
        scanf("%d%d", &x, &y);
        a = min(a, x);
        c = max(c, x);
        b = min(b, y);
        d = max(d, y);
    }

    p[0] = 1;
    ff(i, 1, n*m) p[i] = p[i-1] * i % MOD;
    ans = p[(c-a+1)*(d-b+1)-k];
}

inline void Add(long &a, long b) {
    a += b;
    if (a > MOD) a -= MOD;
}

void Init() {
    int V = max(m, n);
    ff(i, 0, V) CC[0][i] = 1;
    ff(i, 1, V)
        ff(j, i, V)
            CC[i][j] = (CC[i-1][j-1] + CC[i][j-1]) % MOD;
}

void Process() {
    Init();
    dp[m][n] = 1;
    gg(i, m, 1)
        gg(j, n, 1) {
            if (i < m) Add(dp[i][j], dp[i+1][j] * p[j] % MOD);
            if (j < n) Add(dp[i][j], dp[i][j+1] * p[i] % MOD);
        }

    printf("%d", ans * dp[c-a+1][d-b+1] % MOD * CC[a-1][m-(c-a+1)] % MOD * CC[b-1][n-(d-b+1)] % MOD);
}

int main() {
    //ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen(NAME".inp", "r", stdin);
    //freopen(NAME".out", "w", stdout);
    Enter();
    Process();
    return 0;
}

Compilation message

mascots.cpp: In function 'void Process()':
mascots.cpp:66:100: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
     printf("%d", ans * dp[c-a+1][d-b+1] % MOD * CC[a-1][m-(c-a+1)] % MOD * CC[b-1][n-(d-b+1)] % MOD);
                                                                                                    ^
mascots.cpp: In function 'void Enter()':
mascots.cpp:25:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", &m, &n, &k);
                                ^
mascots.cpp:32:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &y);
                              ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 213936 KB Output is correct
2 Correct 0 ms 213936 KB Output is correct
3 Correct 0 ms 213936 KB Output is correct
4 Correct 0 ms 213936 KB Output is correct
5 Correct 0 ms 213936 KB Output is correct
6 Correct 0 ms 213936 KB Output is correct
7 Correct 0 ms 213936 KB Output is correct
8 Correct 0 ms 213936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 213936 KB Output is correct
2 Correct 0 ms 213936 KB Output is correct
3 Correct 0 ms 213936 KB Output is correct
4 Correct 0 ms 213936 KB Output is correct
5 Correct 0 ms 213936 KB Output is correct
6 Correct 0 ms 213936 KB Output is correct
7 Correct 0 ms 213936 KB Output is correct
8 Correct 0 ms 213936 KB Output is correct
9 Correct 0 ms 213936 KB Output is correct
10 Correct 0 ms 213936 KB Output is correct
11 Correct 0 ms 213936 KB Output is correct
12 Correct 0 ms 213936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 213936 KB Output is correct
2 Correct 3 ms 213936 KB Output is correct
3 Correct 3 ms 213936 KB Output is correct
4 Correct 9 ms 213936 KB Output is correct
5 Correct 23 ms 213936 KB Output is correct
6 Correct 43 ms 213936 KB Output is correct
7 Correct 49 ms 213936 KB Output is correct
8 Correct 143 ms 213936 KB Output is correct
9 Correct 269 ms 213936 KB Output is correct
10 Correct 216 ms 213936 KB Output is correct
11 Correct 219 ms 213936 KB Output is correct
12 Correct 233 ms 213936 KB Output is correct
13 Correct 13 ms 213936 KB Output is correct
14 Correct 283 ms 213936 KB Output is correct
15 Correct 249 ms 213936 KB Output is correct
16 Correct 169 ms 213936 KB Output is correct
17 Correct 266 ms 213936 KB Output is correct
18 Correct 266 ms 213936 KB Output is correct