#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("VNOICUP.INP");
ofstream fout("VNOICUP.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
using u128 = __uint128_t;
//const int x[4] = {1, -1, 0, 0};
//const int y[4] = {0, 0, 1, -1};
const ll mod = 1e9 + 7;
const int mxn = 1e6 + 5, mxq = 2e5 + 5, sq = 400, mxv = 2e7 + 5;
//const int base = (1 << 18);
int r, s, n;
int a[505][505];
int dp[305][2005], id[mxn + 1], predp[305][2005];
int cc(int u, int v){
return((u - 1) / v + 1);
}
void add(int &a, int b){
a += b;
if(a >= mod)a -= mod;
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> r >> s >> n;
for(int i = 1; i <= r; i++){
for(int j = 1; j <= s; j++){
cin >> a[i][j];
}
}
vt<int>care;
for(int i = 1; i <= n; i++){
int cand = cc(n, i);
if(care.empty() || cand != care.back()){
id[cand] = sz(care); care.pb(cand);
}
}
dp[1][id[cc(n, a[1][1])]] = 1;
for(int i = 1; i <= r; i++){
for(int j = 1; j <= s; j++){
for(int k = 0; k < sz(care); k++){
int nwid = id[cc(care[k], a[i][j])];
if(i > 1){
add(dp[j][nwid], predp[j][k]);
}if(j > 1){
add(dp[j][nwid], dp[j - 1][k]);
}
}
}
for(int j = 1; j <= s; j++){
for(int k = 0; k < sz(care); k++){
predp[j][k] = dp[j][k]; dp[j][k] = 0;
}
}
}
cout << predp[s][sz(care) - 1];
return(0);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
3540 KB |
Output is correct |
2 |
Correct |
28 ms |
3636 KB |
Output is correct |
3 |
Correct |
116 ms |
2376 KB |
Output is correct |
4 |
Correct |
124 ms |
2464 KB |
Output is correct |
5 |
Correct |
127 ms |
2388 KB |
Output is correct |
6 |
Correct |
125 ms |
2412 KB |
Output is correct |
7 |
Correct |
62 ms |
1748 KB |
Output is correct |
8 |
Correct |
595 ms |
4588 KB |
Output is correct |
9 |
Correct |
1115 ms |
5972 KB |
Output is correct |
10 |
Correct |
1140 ms |
6112 KB |
Output is correct |