problem_id
stringlengths
6
6
language
stringclasses
2 values
original_status
stringclasses
3 values
original_src
stringlengths
19
243k
changed_src
stringlengths
19
243k
change
stringclasses
3 values
i1
int64
0
8.44k
i2
int64
0
8.44k
j1
int64
0
8.44k
j2
int64
0
8.44k
error
stringclasses
270 values
stderr
stringlengths
0
226k
p03167
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <vector> #define rep(i, N) for (int i = 0; i < (int)N; i++) using namespace std; typedef long long ll; const ll INF = 9223372036854775807 / 2; const int MOD = 1000000007; const int H_MAX = pow(10, 3); const int W_MAX = pow(10, 3); vector<vector<ll>> dp(H_MAX, vector<ll>(H_MAX, -1)); vector<vector<bool>> m(W_MAX, vector<bool>(H_MAX, true)); ll dfs(int h, int w) { if (h == 0 && w == 0) return dp[0][0] = 1; if (dp[h][w] != -1) return dp[h][w]; ll result = 0; if (h != 0 && m[h - 1][w]) result += dfs(h - 1, w); if (w != 0 && m[h][w - 1]) result += dfs(h, w - 1); return dp[h][w] = result % MOD; } int main() { int H, W; cin >> H >> W; rep(i, H) { string row; cin >> row; rep(j, W) if (row[j] == '#') m[i][j] = false; } dfs(H, W); // rep(i, H) { rep(j, W) {cout << dp[i][j] << " ";} cout << endl; } cout << dp[H - 1][W - 1] << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <vector> #define rep(i, N) for (int i = 0; i < (int)N; i++) using namespace std; typedef long long ll; const ll INF = 9223372036854775807 / 2; const int MOD = 1000000007; const int H_MAX = pow(10, 4); const int W_MAX = pow(10, 4); vector<vector<ll>> dp(H_MAX, vector<ll>(H_MAX, -1)); vector<vector<bool>> m(W_MAX, vector<bool>(H_MAX, true)); ll dfs(int h, int w) { if (h == 0 && w == 0) return dp[0][0] = 1; if (dp[h][w] != -1) return dp[h][w]; ll result = 0; if (h != 0 && m[h - 1][w]) result += dfs(h - 1, w); if (w != 0 && m[h][w - 1]) result += dfs(h, w - 1); return dp[h][w] = result % MOD; } int main() { int H, W; cin >> H >> W; rep(i, H) { string row; cin >> row; rep(j, W) if (row[j] == '#') m[i][j] = false; } dfs(H, W); // rep(i, H) { rep(j, W) {cout << dp[i][j] << " ";} cout << endl; } cout << dp[H - 1][W - 1] << endl; return 0; }
replace
11
13
11
13
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> using namespace std; #define int long long int #define pb push_back #define fi(n) for (int i = 0; i < n; i++) #define fi1(n) for (int i = 1; i < n; i++) #define fj(n) for (int j = 0; j < n; j++) #define rep(z, a, n) for (z = a; z < n; z++) #define rep2(z, a, n) for (z = a; z < n; z += 2) #define clr(x) memset(x, 0, sizeof(x)) #define print(x, n) \ for (int i = 0; i < n; i++) \ cout << x[i] << " "; \ cout << "\n" #define nl "\n" #define vi vector<int> #define mp make_pair #define pairi pair<int, int> #define vpairi vector<pair<int, int>> #define ff first #define ss second #define inf 2e18 #define input \ "C://Users//Piyush Aggarwal//Documents//Cpp files//input-output//input.txt" #define output \ "C://Users//Piyush Aggarwal//Documents//Cpp files//input-output//output.txt" #define error \ "C://Users//Piyush Aggarwal//Documents//Cpp files//input-output//error.txt" int ctoi(char a) { int x = a - 48; return x; } string itos(int a) { string out_string; stringstream ss; ss << a; out_string = ss.str(); return out_string; } char itoc(int a) { return itos(a)[0]; } int pow(int e, int x) { int ans = 1; while (x > 0) { if (x & 1) ans *= e; e *= e; x >>= 1; } return ans; } string bin(int x) { bitset<sizeof(1) * CHAR_BIT> bits(x); string b = bits.to_string(); return b; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen(input, "r", stdin); freopen(output, "w", stdout); freopen(error, "w", stderr); #endif int T = 1; // cin>>T; while (T--) { int n, k, m, x, y; cin >> n >> m; // int a[n];clr(a); int a[n][m]; clr(a); char c[n][m]; fi(n) { fj(m) cin >> c[i][j]; } fi(n) { fj(m) { if (i == 0 && j == 0) { a[i][j] = 1; } else if (i == 0) { if (c[i][j] == '.') a[i][j] = a[i][j - 1]; } else if (j == 0) { if (c[i][j] == '.') a[i][j] = a[i - 1][j]; } else { if (c[i][j] == '.') a[i][j] = (a[i - 1][j] + a[i][j - 1]) % 1000000007; } } } cout << a[n - 1][m - 1] << nl; } return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; #define int long long int #define pb push_back #define fi(n) for (int i = 0; i < n; i++) #define fi1(n) for (int i = 1; i < n; i++) #define fj(n) for (int j = 0; j < n; j++) #define rep(z, a, n) for (z = a; z < n; z++) #define rep2(z, a, n) for (z = a; z < n; z += 2) #define clr(x) memset(x, 0, sizeof(x)) #define print(x, n) \ for (int i = 0; i < n; i++) \ cout << x[i] << " "; \ cout << "\n" #define nl "\n" #define vi vector<int> #define mp make_pair #define pairi pair<int, int> #define vpairi vector<pair<int, int>> #define ff first #define ss second #define inf 2e18 #define input \ "C://Users//Piyush Aggarwal//Documents//Cpp files//input-output//input.txt" #define output \ "C://Users//Piyush Aggarwal//Documents//Cpp files//input-output//output.txt" #define error \ "C://Users//Piyush Aggarwal//Documents//Cpp files//input-output//error.txt" int ctoi(char a) { int x = a - 48; return x; } string itos(int a) { string out_string; stringstream ss; ss << a; out_string = ss.str(); return out_string; } char itoc(int a) { return itos(a)[0]; } int pow(int e, int x) { int ans = 1; while (x > 0) { if (x & 1) ans *= e; e *= e; x >>= 1; } return ans; } string bin(int x) { bitset<sizeof(1) * CHAR_BIT> bits(x); string b = bits.to_string(); return b; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE #endif int T = 1; // cin>>T; while (T--) { int n, k, m, x, y; cin >> n >> m; // int a[n];clr(a); int a[n][m]; clr(a); char c[n][m]; fi(n) { fj(m) cin >> c[i][j]; } fi(n) { fj(m) { if (i == 0 && j == 0) { a[i][j] = 1; } else if (i == 0) { if (c[i][j] == '.') a[i][j] = a[i][j - 1]; } else if (j == 0) { if (c[i][j] == '.') a[i][j] = a[i - 1][j]; } else { if (c[i][j] == '.') a[i][j] = (a[i - 1][j] + a[i][j - 1]) % 1000000007; } } } cout << a[n - 1][m - 1] << nl; } return 0; }
delete
63
66
63
63
-11
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define INF 1e9 #define MAX 105 #define xx first #define yy second #define pb push_back #define mp make_pair #define ull long long #define FOR(i, a, b) for (int i = a; i <= b; i++) #define nl '\n' #define zai << ' ' << #define all(a) a.begin(), a.end() typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; const int MOD = 1000000007; bool a[MAX][MAX]; int dp[MAX][MAX]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; char tmp; cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> tmp; if (tmp == '#') a[i][j] = 1; } } if (!a[0][0]) dp[0][0] = 1; else { cout << 0; return 0; } for (int i = 1; i < m; i++) { if (!a[0][i] && dp[0][i - 1] != INF) dp[0][i] = 1; else dp[0][i] = INF; } for (int i = 1; i < n; i++) { if (!a[i][0] && dp[i - 1][0] != INF) dp[i][0] = 1; else dp[i][0] = INF; } for (int i = 1; i < n; i++) { for (int j = 1; j < m; j++) { if (a[i][j] == 0) { if (dp[i - 1][j] == INF && dp[i][j - 1] == INF) { dp[i][j] = INF; } else { if (dp[i - 1][j] == INF && dp[i][j - 1] != INF) { dp[i][j] = (dp[i][j - 1]) % MOD; } else if (dp[i - 1][j] != INF && dp[i][j - 1] == INF) { dp[i][j] = (dp[i - 1][j]) % MOD; } else if (dp[i - 1][j] != INF && dp[i][j - 1] != INF) { dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD; } } } else { dp[i][j] = INF; } } } if (dp[n - 1][m - 1] != INF) cout << dp[n - 1][m - 1]; else cout << 0; return 0; }
#include <bits/stdc++.h> using namespace std; #define INF 1e9 #define MAX 1005 #define xx first #define yy second #define pb push_back #define mp make_pair #define ull long long #define FOR(i, a, b) for (int i = a; i <= b; i++) #define nl '\n' #define zai << ' ' << #define all(a) a.begin(), a.end() typedef vector<int> vi; typedef pair<int, int> ii; typedef vector<ii> vii; const int MOD = 1000000007; bool a[MAX][MAX]; int dp[MAX][MAX]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, m; char tmp; cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> tmp; if (tmp == '#') a[i][j] = 1; } } if (!a[0][0]) dp[0][0] = 1; else { cout << 0; return 0; } for (int i = 1; i < m; i++) { if (!a[0][i] && dp[0][i - 1] != INF) dp[0][i] = 1; else dp[0][i] = INF; } for (int i = 1; i < n; i++) { if (!a[i][0] && dp[i - 1][0] != INF) dp[i][0] = 1; else dp[i][0] = INF; } for (int i = 1; i < n; i++) { for (int j = 1; j < m; j++) { if (a[i][j] == 0) { if (dp[i - 1][j] == INF && dp[i][j - 1] == INF) { dp[i][j] = INF; } else { if (dp[i - 1][j] == INF && dp[i][j - 1] != INF) { dp[i][j] = (dp[i][j - 1]) % MOD; } else if (dp[i - 1][j] != INF && dp[i][j - 1] == INF) { dp[i][j] = (dp[i - 1][j]) % MOD; } else if (dp[i - 1][j] != INF && dp[i][j - 1] != INF) { dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD; } } } else { dp[i][j] = INF; } } } if (dp[n - 1][m - 1] != INF) cout << dp[n - 1][m - 1]; else cout << 0; return 0; }
replace
4
5
4
5
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define lc "\n" #define fast_io \ ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(0) #define mp make_pair #define pb push_back #define fi first #define se second #define int long long #define c(a, n) \ for (int i = 0; i < n; i++) \ cin >> a[i]; #define ffor(n) for (int i = 0; i < n; i++) typedef vector<int> vi; typedef vector<float> vf; typedef vector<vi> vii; typedef vector<string> vs; typedef vector<long long> vll; typedef map<string, int> msi; typedef map<int, int> mii; typedef unordered_map<string, int> umsi; int32_t main() { int mod = 1e9 + 7; fast_io; int n, m; cin >> n >> m; vector<vector<char>> grid(n, vector<char>(m)); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> grid[i][j]; vii dp(n + 2, vi(m + 2, 0)); for (int i = 1; i <= n; i++) { if (grid[i - 1][0] == '#') break; else dp[i][1] = 1; } for (int i = 1; i <= m; i++) { if (grid[0][i - 1] == '#') break; else dp[1][i] = 1; } for (int i = 2; i <= m; i++) { for (int j = 2; j <= m; j++) { if (grid[i - 1][j - 1] != '#') { dp[i][j] += dp[i - 1][j]; dp[i][j] += dp[i][j - 1]; dp[i][j] %= mod; } } } cout << dp[n][m]; return 0; }
#include <bits/stdc++.h> using namespace std; #define lc "\n" #define fast_io \ ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(0) #define mp make_pair #define pb push_back #define fi first #define se second #define int long long #define c(a, n) \ for (int i = 0; i < n; i++) \ cin >> a[i]; #define ffor(n) for (int i = 0; i < n; i++) typedef vector<int> vi; typedef vector<float> vf; typedef vector<vi> vii; typedef vector<string> vs; typedef vector<long long> vll; typedef map<string, int> msi; typedef map<int, int> mii; typedef unordered_map<string, int> umsi; int32_t main() { int mod = 1e9 + 7; fast_io; int n, m; cin >> n >> m; vector<vector<char>> grid(n, vector<char>(m)); for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> grid[i][j]; vii dp(n + 2, vi(m + 2, 0)); for (int i = 1; i <= n; i++) { if (grid[i - 1][0] == '#') break; else dp[i][1] = 1; } for (int i = 1; i <= m; i++) { if (grid[0][i - 1] == '#') break; else dp[1][i] = 1; } for (int i = 2; i <= n; i++) { for (int j = 2; j <= m; j++) { if (grid[i - 1][j - 1] != '#') { dp[i][j] += dp[i - 1][j]; dp[i][j] += dp[i][j - 1]; dp[i][j] %= mod; } } } cout << dp[n][m]; return 0; }
replace
48
49
48
49
-11
p03167
C++
Runtime Error
// srinivas #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> // #include <boost/multiprecision/cpp_int.hpp> // using namespace boost::multiprecision; using namespace __gnu_pbds; using namespace std; #define all(c) (c).begin(), (c).end() #define endl "\n" #define ff first #define ss second #define allr(c) (c).rbegin(), (c).rend() #define fr(x, in, n, r) for (ll x = in; x < n; x += r) #define ifr(x, n) for (ll x = 0; x < n; x++) #define dfr(x, n) for (ll x = n - 1; x >= 0; x--) #define pb(a) push_back(a) #define pf(a) push_front(a) #define pof(a) pop_front(a) #define pob(a) pop_back(a) #define eb(a) emplace_back(a) #define ef(a) emplace_front(a) #define fstm(m, n, r) \ m.reserve(n); \ m.max_load_factor(r) #define os \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> typedef long long ll; typedef map<ll, ll> mll; typedef map<string, ll> msll; typedef unordered_map<ll, ll> umap; typedef vector<ll> vll; typedef pair<ll, ll> pll; typedef long double ld; #define mod 1000000007 #define N 100001 int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("/home/srinivas/Desktop/cp/input.txt", "r", stdin); // freopen("/home/srinivas/Desktop/output.txt","w",stdout); #endif ll n, m; cin >> n >> m; string s[n]; ifr(i, n) cin >> s[i]; ll dp[n][m]; ifr(i, n) ifr(j, m) dp[i][j] = 0; ifr(i, m) { if (s[0][i] == '.') dp[0][i] = 1; else break; } ifr(i, n) { if (s[i][0] == '.') dp[i][0] = 1; else break; } fr(i, 1, n, 1) { fr(j, 1, m, 1) { if (s[i][j] == '.') dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod; } } cout << dp[n - 1][m - 1] << endl; return 0; }
// srinivas #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> // #include <boost/multiprecision/cpp_int.hpp> // using namespace boost::multiprecision; using namespace __gnu_pbds; using namespace std; #define all(c) (c).begin(), (c).end() #define endl "\n" #define ff first #define ss second #define allr(c) (c).rbegin(), (c).rend() #define fr(x, in, n, r) for (ll x = in; x < n; x += r) #define ifr(x, n) for (ll x = 0; x < n; x++) #define dfr(x, n) for (ll x = n - 1; x >= 0; x--) #define pb(a) push_back(a) #define pf(a) push_front(a) #define pof(a) pop_front(a) #define pob(a) pop_back(a) #define eb(a) emplace_back(a) #define ef(a) emplace_front(a) #define fstm(m, n, r) \ m.reserve(n); \ m.max_load_factor(r) #define os \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> typedef long long ll; typedef map<ll, ll> mll; typedef map<string, ll> msll; typedef unordered_map<ll, ll> umap; typedef vector<ll> vll; typedef pair<ll, ll> pll; typedef long double ld; #define mod 1000000007 #define N 100001 int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, m; cin >> n >> m; string s[n]; ifr(i, n) cin >> s[i]; ll dp[n][m]; ifr(i, n) ifr(j, m) dp[i][j] = 0; ifr(i, m) { if (s[0][i] == '.') dp[0][i] = 1; else break; } ifr(i, n) { if (s[i][0] == '.') dp[i][0] = 1; else break; } fr(i, 1, n, 1) { fr(j, 1, m, 1) { if (s[i][j] == '.') dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod; } } cout << dp[n - 1][m - 1] << endl; return 0; }
delete
43
47
43
43
-11
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; void fst() { ios::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif } int nxt() { int x; cin >> x; return x; } int nex_l() { long long x; cin >> x; return x; } typedef long long ll; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<vi> vvi; typedef vector<vb> vvb; typedef vector<ll> vl; typedef vector<vl> vvl; typedef pair<int, int> pii; typedef vector<pair<int, int>> vpii; #define fr first #define sc second #define pb push_back #define all(v) v.begin(), v.end() #define binary(n) cout << bitset<31>(n) << "\n"; #define FOR(i, n) for (int i = 0; i < n; i++) #define rep(i, a, b) for (int i = a; i < b; i++) #define input_arr(a, n) \ for (int i = 0; i < n; i++) \ cin >> a[i]; #define print_arr(a, n) \ for (int i = 0; i < n; i++) \ cout << a[i] << " "; const int MOD = 1e9 + 7; int main() { fst(); int h = nxt(), w = nxt(); vector<string> in(h); rep(i, 0, h) cin >> in[i]; vvi dp(h + 1, vi(w + 1, 0)); dp[1][1] = 1; rep(i, 1, h + 1) { rep(j, 1, w + 1) { if (i > 1) if (in[i - 2][j - 1] != '#' && in[i - 1][j - 1] != '#') dp[i][j] += dp[i - 1][j]; if (j > 1) if (in[i - 1][j - 2] != '#' && in[i - 1][j - 1] != '#') dp[i][j] += dp[i][j - 1]; dp[i][j] = dp[i][j] % MOD; } } cout << dp[h][w]; }
#include <bits/stdc++.h> using namespace std; void fst() { ios::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif } int nxt() { int x; cin >> x; return x; } int nex_l() { long long x; cin >> x; return x; } typedef long long ll; typedef vector<int> vi; typedef vector<bool> vb; typedef vector<vi> vvi; typedef vector<vb> vvb; typedef vector<ll> vl; typedef vector<vl> vvl; typedef pair<int, int> pii; typedef vector<pair<int, int>> vpii; #define fr first #define sc second #define pb push_back #define all(v) v.begin(), v.end() #define binary(n) cout << bitset<31>(n) << "\n"; #define FOR(i, n) for (int i = 0; i < n; i++) #define rep(i, a, b) for (int i = a; i < b; i++) #define input_arr(a, n) \ for (int i = 0; i < n; i++) \ cin >> a[i]; #define print_arr(a, n) \ for (int i = 0; i < n; i++) \ cout << a[i] << " "; const int MOD = 1e9 + 7; int main() { // fst(); int h = nxt(), w = nxt(); vector<string> in(h); rep(i, 0, h) cin >> in[i]; vvi dp(h + 1, vi(w + 1, 0)); dp[1][1] = 1; rep(i, 1, h + 1) { rep(j, 1, w + 1) { if (i > 1) if (in[i - 2][j - 1] != '#' && in[i - 1][j - 1] != '#') dp[i][j] += dp[i - 1][j]; if (j > 1) if (in[i - 1][j - 2] != '#' && in[i - 1][j - 1] != '#') dp[i][j] += dp[i][j - 1]; dp[i][j] = dp[i][j] % MOD; } } cout << dp[h][w]; }
replace
47
48
47
48
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define Fast_IO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define m 1000000007 int dp[1005][1005]; int32_t main() { Fast_IO #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int r, c; cin >> r >> c; vector<vector<char>> grid(r, vector<char>(c)); for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { cin >> grid[i][j]; if (grid[i][j] == '#') dp[i][j] = -1; } } for (int i = 0; i < r; i++) { if (grid[i][0] == '#') break; dp[i][0] = 1; } for (int i = 0; i < c; i++) { if (grid[0][i] == '#') break; dp[0][i] = 1; } for (int i = 1; i < r; i++) { for (int j = 1; j < c; j++) { if (grid[i][j] == '#') continue; dp[i][j] = (max(dp[i - 1][j], 0) + max(dp[i][j - 1], 0)) % m; } } // for(int i=0;i<r;i++){ // for(int j=0;j<c;j++){ // cout<<dp[i][j]<<" "; // } // cout<<"\n"; // } cout << dp[r - 1][c - 1]; }
#include <bits/stdc++.h> using namespace std; #define Fast_IO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define m 1000000007 int dp[1005][1005]; int32_t main() { Fast_IO #ifdef __WIN32 freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int r, c; cin >> r >> c; vector<vector<char>> grid(r, vector<char>(c)); for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { cin >> grid[i][j]; if (grid[i][j] == '#') dp[i][j] = -1; } } for (int i = 0; i < r; i++) { if (grid[i][0] == '#') break; dp[i][0] = 1; } for (int i = 0; i < c; i++) { if (grid[0][i] == '#') break; dp[0][i] = 1; } for (int i = 1; i < r; i++) { for (int j = 1; j < c; j++) { if (grid[i][j] == '#') continue; dp[i][j] = (max(dp[i - 1][j], 0) + max(dp[i][j - 1], 0)) % m; } } // for(int i=0;i<r;i++){ // for(int j=0;j<c;j++){ // cout<<dp[i][j]<<" "; // } // cout<<"\n"; // } cout << dp[r - 1][c - 1]; }
replace
11
12
11
12
-11
p03167
C++
Runtime Error
#include <bits/stdc++.h> #define pb push_back #define int long long #define MOD 998244353 #define MOD2 1000000007 using namespace std; int32_t main() { int m, n; cin >> m >> n; int dp[100][100]; dp[0][0] = 1; string s[1001]; for (int i = 0; i < m; i++) cin >> s[i]; int i = 0, j = 0; while (i < n && s[0][i] == '.') dp[0][i++] = 1; i = 0; while (i < m && s[i][0] == '.') dp[i++][0] = 1; i = 0, j = 0; for (i = 1; i < m; i++) { for (j = 1; j < n; j++) { if (s[i][j] == '.') dp[i][j] = ((dp[i - 1][j] % MOD2) + (dp[i][j - 1] % MOD2)) % MOD2; else dp[i][j] = 0; } } cout << dp[m - 1][n - 1]; }
#include <bits/stdc++.h> #define pb push_back #define int long long #define MOD 998244353 #define MOD2 1000000007 using namespace std; int32_t main() { int m, n; cin >> m >> n; int dp[1001][1001]; dp[0][0] = 1; string s[1001]; for (int i = 0; i < m; i++) cin >> s[i]; int i = 0, j = 0; while (i < n && s[0][i] == '.') dp[0][i++] = 1; i = 0; while (i < m && s[i][0] == '.') dp[i++][0] = 1; i = 0, j = 0; for (i = 1; i < m; i++) { for (j = 1; j < n; j++) { if (s[i][j] == '.') dp[i][j] = ((dp[i - 1][j] % MOD2) + (dp[i][j - 1] % MOD2)) % MOD2; else dp[i][j] = 0; } } cout << dp[m - 1][n - 1]; }
replace
9
10
9
10
0
p03167
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> #include <stdlib.h> #include <string> #include <utility> #include <vector> using namespace std; #undef INT_MIN #undef INT_MAX #define LL long long #define INT_MIN -2147483647 #define INT_MAX 1000000009 #define LL_MIN -9223372036854775807 #define LL_MAX 9223372036854775807 #define MP make_pair #define PB push_back #define MOD 1000000007 int H, W; string grid[1009]; int dp[50][50]; // dp[i][j] >> (1,1)から(i+1,j+1)にたどり着くまでの経路数 // dp[i][j] = dp[i-1][j] + dp[i][j-1](i!=0 && j!=0) // = dp[0][j-1] (i==0) // = dp[i-1][0] (j==0) // = 0 (grid[i][j] == '#') int main() { cin >> H >> W; for (int i = 0; i < H; i++) { cin >> grid[i]; for (int j = 0; j < W; j++) dp[i][j] = 0; } dp[0][0] = 1; // cout << "dp[" << 0 << "][" << 0 << "] = " << dp[0][0] << endl; for (int i = 1; i < H; i++) { if (grid[i][0] != '#') dp[i][0] = dp[i - 1][0]; // cout << "dp[" << i << "][" << 0 << "] = " << dp[i][0] << endl; } for (int j = 1; j < W; j++) { if (grid[0][j] != '#') dp[0][j] = dp[0][j - 1]; // cout << "dp[" << 0 << "][" << j << "] = " << dp[0][j] << endl; } for (int i = 1; i < H; i++) { for (int j = 1; j < W; j++) { if (grid[i][j] != '#') dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD; // cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << //endl; } } cout << dp[H - 1][W - 1] % MOD << endl; return 0; } /* #include<algorithm> #include<iostream> #include<utility> using namespace std; #undef INT_MIN #undef INT_MAX #define LL long long #define INT_MIN -2147483647 #define INT_MAX 2147483647 #define LL_MIN -9223372036854775807 #define LL_MAX 9223372036854775807 int N,W; pair<int,int> b[100]; int w[105],v[105]; LL dp[105][100100]; int main(){ cin >> N >> W; for(int i = 0; i<N; i++){ for(int j=0; j<=W; j++){ dp[i][j]=-1; } } for(int i=0; i<N; i++){ int we,va; cin >> we >> va; b[i]=make_pair(we,va); } for(int i = 0; i <= W; i++) dp[N][i] = 0; for(int i = N-1; i >= 0; i--){ for(int j = W; j >= 0; j--){ dp[i][j] = dp[i+1][j];//not serect i if(j-b[i].first >= 0){ dp[i][j]= max( dp[i][j], dp[i+1][j-b[i].first] + b[i].second ); } } } cout << dp[0][W] << endl; return 0; } */ // union find & prime /* #include<algorithm> #include<iostream> #include<map> #include<string> #include<utility> #include<vector> using namespace std; int n; int num[100100]; vector<pair<int,int>>sortednum; int par[100010]; map<int,int>ppid; int neid(int x){ if(par[x]==x)return x; else{ return par[x]=neid(par[x]); } } void primenum(int inow, int NUM){ for(int i=2; i*i<=NUM; i++){ if(NUM%i==0){ if(ppid.count(i)==0){ ppid[i]=inow; } else{ par[neid(ppid[i])]=inow; } while(NUM%i==0)NUM/=i; } } if(NUM!=1){ if(ppid.count(NUM)==0){ ppid[NUM]=inow; } else{ par[neid(ppid[NUM])]=inow; } } } int main(){ cin >> n; for(int i=0; i<n; i++){ cin >> num[i]; sortednum.push_back(make_pair(num[i],i)); par[i]=i; primenum(i,num[i]); } sort(sortednum.begin(),sortednum.end()); int ans=1; for(int i=0; i<n; i++){ if(neid(i)!=neid(sortednum[i].second)){ ans=0; break; } } cout << ans << endl; return 0; } */ // djikstra /* #include <algorithm> #include <cassert> #include <cstdlib> #include <fstream> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <string> #include <time.h> #include <tuple> #include <unordered_map> #include <vector> using namespace std; int INF = 10000000; priority_queue< pair<int,int> > que; //INF-cost,i int cost[1000]; for(int i=0; i<1000; i++) cost[i] = INF; cost[0] = 0; que.push(make_pair(INF-0, 0)); while(!que.empty){ int now = que.top().second; for(int i=0; i<tonari[now].size(); i++){ if(cost[tonari[now][i]] > cost[now] + distance[now][tonari[now][i]){ cost[tonari[now][i]] = cost[now] + distance[now][tonari[now][i]; que.push(make_pair(INF-cost[tonari[now][i]], tonari[now][i])); } } que.pop(); } */
#include <algorithm> #include <iostream> #include <map> #include <stdlib.h> #include <string> #include <utility> #include <vector> using namespace std; #undef INT_MIN #undef INT_MAX #define LL long long #define INT_MIN -2147483647 #define INT_MAX 1000000009 #define LL_MIN -9223372036854775807 #define LL_MAX 9223372036854775807 #define MP make_pair #define PB push_back #define MOD 1000000007 int H, W; string grid[1009]; int dp[1009][1009]; // dp[i][j] >> (1,1)から(i+1,j+1)にたどり着くまでの経路数 // dp[i][j] = dp[i-1][j] + dp[i][j-1](i!=0 && j!=0) // = dp[0][j-1] (i==0) // = dp[i-1][0] (j==0) // = 0 (grid[i][j] == '#') int main() { cin >> H >> W; for (int i = 0; i < H; i++) { cin >> grid[i]; for (int j = 0; j < W; j++) dp[i][j] = 0; } dp[0][0] = 1; // cout << "dp[" << 0 << "][" << 0 << "] = " << dp[0][0] << endl; for (int i = 1; i < H; i++) { if (grid[i][0] != '#') dp[i][0] = dp[i - 1][0]; // cout << "dp[" << i << "][" << 0 << "] = " << dp[i][0] << endl; } for (int j = 1; j < W; j++) { if (grid[0][j] != '#') dp[0][j] = dp[0][j - 1]; // cout << "dp[" << 0 << "][" << j << "] = " << dp[0][j] << endl; } for (int i = 1; i < H; i++) { for (int j = 1; j < W; j++) { if (grid[i][j] != '#') dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD; // cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << //endl; } } cout << dp[H - 1][W - 1] % MOD << endl; return 0; } /* #include<algorithm> #include<iostream> #include<utility> using namespace std; #undef INT_MIN #undef INT_MAX #define LL long long #define INT_MIN -2147483647 #define INT_MAX 2147483647 #define LL_MIN -9223372036854775807 #define LL_MAX 9223372036854775807 int N,W; pair<int,int> b[100]; int w[105],v[105]; LL dp[105][100100]; int main(){ cin >> N >> W; for(int i = 0; i<N; i++){ for(int j=0; j<=W; j++){ dp[i][j]=-1; } } for(int i=0; i<N; i++){ int we,va; cin >> we >> va; b[i]=make_pair(we,va); } for(int i = 0; i <= W; i++) dp[N][i] = 0; for(int i = N-1; i >= 0; i--){ for(int j = W; j >= 0; j--){ dp[i][j] = dp[i+1][j];//not serect i if(j-b[i].first >= 0){ dp[i][j]= max( dp[i][j], dp[i+1][j-b[i].first] + b[i].second ); } } } cout << dp[0][W] << endl; return 0; } */ // union find & prime /* #include<algorithm> #include<iostream> #include<map> #include<string> #include<utility> #include<vector> using namespace std; int n; int num[100100]; vector<pair<int,int>>sortednum; int par[100010]; map<int,int>ppid; int neid(int x){ if(par[x]==x)return x; else{ return par[x]=neid(par[x]); } } void primenum(int inow, int NUM){ for(int i=2; i*i<=NUM; i++){ if(NUM%i==0){ if(ppid.count(i)==0){ ppid[i]=inow; } else{ par[neid(ppid[i])]=inow; } while(NUM%i==0)NUM/=i; } } if(NUM!=1){ if(ppid.count(NUM)==0){ ppid[NUM]=inow; } else{ par[neid(ppid[NUM])]=inow; } } } int main(){ cin >> n; for(int i=0; i<n; i++){ cin >> num[i]; sortednum.push_back(make_pair(num[i],i)); par[i]=i; primenum(i,num[i]); } sort(sortednum.begin(),sortednum.end()); int ans=1; for(int i=0; i<n; i++){ if(neid(i)!=neid(sortednum[i].second)){ ans=0; break; } } cout << ans << endl; return 0; } */ // djikstra /* #include <algorithm> #include <cassert> #include <cstdlib> #include <fstream> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <string> #include <time.h> #include <tuple> #include <unordered_map> #include <vector> using namespace std; int INF = 10000000; priority_queue< pair<int,int> > que; //INF-cost,i int cost[1000]; for(int i=0; i<1000; i++) cost[i] = INF; cost[0] = 0; que.push(make_pair(INF-0, 0)); while(!que.empty){ int now = que.top().second; for(int i=0; i<tonari[now].size(); i++){ if(cost[tonari[now][i]] > cost[now] + distance[now][tonari[now][i]){ cost[tonari[now][i]] = cost[now] + distance[now][tonari[now][i]; que.push(make_pair(INF-cost[tonari[now][i]], tonari[now][i])); } } que.pop(); } */
replace
23
24
23
24
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fto(i, s, e) for (int i = s; i <= e; ++i) #define fto1(i, s, e) for (int i = s; i < e; ++i) #define fdto(i, s, e) for (int i = s; i >= e; --i) #define fit(var, it) \ for (__typeof(var.begin()) it = var.begin(); it != var.end(); ++it) #define frit(var, it) \ for (__typeof(var.rbegin()) it = var.rbegin(); it != var.rend(); ++it) #define newl '\n' #define debugt cerr << 0.001 * clock() << newl #define debug1(x, i) cout << #x << '[' << i << "] = " << x[i] << newl #define debug(v, l, r) fto(_i, l, r) debug1(v, _i) #define debug2(x, i, j) \ cout << #x << '[' << i << "][" << j << "] = " << x[i][j] << newl #define debug3(x, i, j, k) \ cout << #x << '[' << i << "][" << j << "][" << k << "] = " << x[i][j][k] \ << newl #define ll long long #define ii pair<int, int> #define ff first #define ss second #define pb push_back #define glen(v) int((v).size()) template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> const &v) { return os << '(' << v.ff << ", " << v.ss << ')'; } #define eps 1e-15 #define oo 1000000007 #define OO 1000000000000000003LL #define maxn 103 int n, m; int f[maxn][maxn]; char a[maxn][maxn]; int main() { #ifndef ONLINE_JUDGE // freopen("main.inp", "r", stdin); // freopen("main.out", "w", stdout); #endif // ios_base::sync_with_stdio(0); cin.tie(0); scanf("%d%d", &n, &m); fto(i, 1, n) { scanf("%*c"); fto(j, 1, m) { scanf("%c", &a[i][j]); } } f[1][1] = 1; fto(j, 2, m) if (a[1][j] == '.') f[1][j] = f[1][j - 1]; fto(i, 2, n) if (a[i][1] == '.') f[i][1] = f[i - 1][1]; fto(i, 2, n) fto(j, 2, m) if (a[i][j] == '.') { f[i][j] = f[i - 1][j] + f[i][j - 1]; f[i][j] %= oo; } printf("%d\n", f[n][m]); return 0; }
#include <bits/stdc++.h> using namespace std; #define fto(i, s, e) for (int i = s; i <= e; ++i) #define fto1(i, s, e) for (int i = s; i < e; ++i) #define fdto(i, s, e) for (int i = s; i >= e; --i) #define fit(var, it) \ for (__typeof(var.begin()) it = var.begin(); it != var.end(); ++it) #define frit(var, it) \ for (__typeof(var.rbegin()) it = var.rbegin(); it != var.rend(); ++it) #define newl '\n' #define debugt cerr << 0.001 * clock() << newl #define debug1(x, i) cout << #x << '[' << i << "] = " << x[i] << newl #define debug(v, l, r) fto(_i, l, r) debug1(v, _i) #define debug2(x, i, j) \ cout << #x << '[' << i << "][" << j << "] = " << x[i][j] << newl #define debug3(x, i, j, k) \ cout << #x << '[' << i << "][" << j << "][" << k << "] = " << x[i][j][k] \ << newl #define ll long long #define ii pair<int, int> #define ff first #define ss second #define pb push_back #define glen(v) int((v).size()) template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> const &v) { return os << '(' << v.ff << ", " << v.ss << ')'; } #define eps 1e-15 #define oo 1000000007 #define OO 1000000000000000003LL #define maxn 1003 int n, m; int f[maxn][maxn]; char a[maxn][maxn]; int main() { #ifndef ONLINE_JUDGE // freopen("main.inp", "r", stdin); // freopen("main.out", "w", stdout); #endif // ios_base::sync_with_stdio(0); cin.tie(0); scanf("%d%d", &n, &m); fto(i, 1, n) { scanf("%*c"); fto(j, 1, m) { scanf("%c", &a[i][j]); } } f[1][1] = 1; fto(j, 2, m) if (a[1][j] == '.') f[1][j] = f[1][j - 1]; fto(i, 2, n) if (a[i][1] == '.') f[i][1] = f[i - 1][1]; fto(i, 2, n) fto(j, 2, m) if (a[i][j] == '.') { f[i][j] = f[i - 1][j] + f[i][j - 1]; f[i][j] %= oo; } printf("%d\n", f[n][m]); return 0; }
replace
37
38
37
38
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long const int mod = 1e9 + 7; int xinc[2] = {0, 1}; int yinc[2] = {1, 0}; ll ans(char **rc, int r, int c) { ll res; ll **distanc = new ll *[r]; bool **proc = new bool *[r]; for (int i = 0; i < r; i++) { distanc[i] = new ll[c]; proc[i] = new bool[c]; } for (int i = 0; i < r; i++) for (int j = 0; j < c; j++) proc[i][j] = 0, distanc[i][j] = 0; distanc[0][0] = 1; queue<int> xcor, ycor; xcor.push(0); ycor.push(0); while (!xcor.empty()) { int x = xcor.front(), y = ycor.front(); xcor.pop(); ycor.pop(); if (proc[x][y]) continue; for (int i = 0; i < 2; i++) { int xtemp = x + xinc[i]; int ytemp = y + yinc[i]; if (xtemp < 0 || ytemp < 0) continue; if (xtemp >= r || ytemp >= c) continue; if (rc[xtemp][ytemp] == '#') continue; distanc[xtemp][ytemp] = (distanc[xtemp][ytemp] + distanc[x][y]) % mod; xcor.push(xtemp); ycor.push(ytemp); } proc[x][y] = 1; } res = distanc[r - 1][c - 1]; for (int i = 0; i < r; i++) { delete[] distanc[i]; delete[] proc[i]; } delete[] distanc; delete[] proc; return res; } int main() { int r, c; cin >> r >> c; char **rc; rc = new char *[r]; for (int i = 0; i < r; i++) { rc[i] = new char[c]; cin >> rc[i]; } cout << ans(rc, r, c) << endl; for (int i = 0; i < r; i++) { delete[] rc[i]; } delete[] rc; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long const int mod = 1e9 + 7; int xinc[2] = {0, 1}; int yinc[2] = {1, 0}; ll ans(char **rc, int r, int c) { ll res; ll **distanc = new ll *[r]; bool **proc = new bool *[r]; for (int i = 0; i < r; i++) { distanc[i] = new ll[c]; proc[i] = new bool[c]; } for (int i = 0; i < r; i++) for (int j = 0; j < c; j++) proc[i][j] = 0, distanc[i][j] = 0; distanc[0][0] = 1; queue<int> xcor, ycor; xcor.push(0); ycor.push(0); while (!xcor.empty()) { int x = xcor.front(), y = ycor.front(); xcor.pop(); ycor.pop(); if (proc[x][y]) continue; for (int i = 0; i < 2; i++) { int xtemp = x + xinc[i]; int ytemp = y + yinc[i]; if (xtemp < 0 || ytemp < 0) continue; if (xtemp >= r || ytemp >= c) continue; if (rc[xtemp][ytemp] == '#') continue; distanc[xtemp][ytemp] = (distanc[xtemp][ytemp] + distanc[x][y]) % mod; xcor.push(xtemp); ycor.push(ytemp); } proc[x][y] = 1; } res = distanc[r - 1][c - 1]; for (int i = 0; i < r; i++) { delete[] distanc[i]; delete[] proc[i]; } delete[] distanc; delete[] proc; return res; } int main() { int r, c; cin >> r >> c; char **rc; rc = new char *[r]; for (int i = 0; i < r; i++) { rc[i] = new char[c + 1]; cin >> rc[i]; } cout << ans(rc, r, c) << endl; for (int i = 0; i < r; i++) { delete[] rc[i]; } delete[] rc; return 0; }
replace
67
68
67
68
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long const int mod = 1000000000 + 7; const int N = 1000; int dp[N][N]; int solve(int x, int y, int m, int n, char a[][1000]) { if (x == m - 1 && y == n - 1) return dp[x][y] = 1; if (a[x][y] == '#') return dp[x][y] = 0; if (dp[x][y] != -1) return dp[x][y]; // middle if (x < m - 1 && y < n - 1) { if (dp[x][y + 1] == -1) solve(x, y + 1, m, n, a); if (dp[x + 1][y] == -1) solve(x + 1, y, m, n, a); dp[x][y] = (dp[x + 1][y] + dp[x][y + 1]) % mod; } // bottom else if (x == m - 1 && y < n - 1) { if (dp[x][y + 1] == -1) solve(x, y + 1, m, n, a); dp[x][y] = dp[x][y + 1]; } else { if (dp[x + 1][y] == -1) solve(x + 1, y, m, n, a); dp[x][y] = dp[x + 1][y]; } return dp[x][y]; } int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif std::ios::sync_with_stdio(false); cout.tie(0); cin.tie(0); int m, n; cin >> m >> n; int i, j; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { dp[i][j] = -1; } } char a[m][1000]; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { cin >> a[i][j]; } } int ans = solve(0, 0, m, n, a); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long const int mod = 1000000000 + 7; const int N = 1000; int dp[N][N]; int solve(int x, int y, int m, int n, char a[][1000]) { if (x == m - 1 && y == n - 1) return dp[x][y] = 1; if (a[x][y] == '#') return dp[x][y] = 0; if (dp[x][y] != -1) return dp[x][y]; // middle if (x < m - 1 && y < n - 1) { if (dp[x][y + 1] == -1) solve(x, y + 1, m, n, a); if (dp[x + 1][y] == -1) solve(x + 1, y, m, n, a); dp[x][y] = (dp[x + 1][y] + dp[x][y + 1]) % mod; } // bottom else if (x == m - 1 && y < n - 1) { if (dp[x][y + 1] == -1) solve(x, y + 1, m, n, a); dp[x][y] = dp[x][y + 1]; } else { if (dp[x + 1][y] == -1) solve(x + 1, y, m, n, a); dp[x][y] = dp[x + 1][y]; } return dp[x][y]; } int32_t main() { int m, n; cin >> m >> n; int i, j; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { dp[i][j] = -1; } } char a[m][1000]; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { cin >> a[i][j]; } } int ans = solve(0, 0, m, n, a); cout << ans << endl; }
delete
42
50
42
42
-11
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int M = 1010; const ll mod = 1e9L + 7; char a[M][M]; ll dp[M][M]; int n, m; void move(ll &a, ll b) { a = (a + b) % mod; } int main() { freopen("input.txt", "r", stdin); ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; memset(dp, 0, sizeof(dp)); for (int i = 0; i < n; ++i) { cin >> a[i]; } dp[1][1] = 1; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { int x = i - 1, y = i - 1; if (a[i - 1][j - 1] == '#') continue; // move(dp[i][j], dp[i-1][j-1]); move(dp[i][j], dp[i - 1][j]); move(dp[i][j], dp[i][j - 1]); } } // for (int i = 0; i <= n; ++i) // { // for(int j = 0; j <= m; ++j)cout << dp[i][j] << " "; // cout << endl; // } cout << dp[n][m] << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int M = 1010; const ll mod = 1e9L + 7; char a[M][M]; ll dp[M][M]; int n, m; void move(ll &a, ll b) { a = (a + b) % mod; } int main() { // freopen("input.txt", "r", stdin); ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> m; memset(dp, 0, sizeof(dp)); for (int i = 0; i < n; ++i) { cin >> a[i]; } dp[1][1] = 1; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { int x = i - 1, y = i - 1; if (a[i - 1][j - 1] == '#') continue; // move(dp[i][j], dp[i-1][j-1]); move(dp[i][j], dp[i - 1][j]); move(dp[i][j], dp[i][j - 1]); } } // for (int i = 0; i <= n; ++i) // { // for(int j = 0; j <= m; ++j)cout << dp[i][j] << " "; // cout << endl; // } cout << dp[n][m] << endl; }
replace
14
15
14
15
0
p03167
C++
Runtime Error
#include <cstdio> #include <cstdlib> #include <iomanip> #include <iostream> #include <algorithm> #include <cmath> #include <fstream> #include <map> #include <set> #include <string> #include <vector> #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define forl(i, a, n) for (int i = a; i < n; i++) #define rfor(i, n, a) for (int i = n; i >= a; i--) #define ll long long #define ld long double #define pb push_back #define ld long double #define vi vector<int> #define vll vector<long long> #define pi pair<int, int> #define pll pair<long long, long long> #define mp make_pair #define B begin() #define E end() #define S size() #define m9 1000000007 using namespace std; /* string fs(string str1, string str2) { if (str1.length() > str2.length()) swap(str1, str2); string str = ""; int n1 = str1.length(), n2 = str2.length(); int diff = n2 - n1; int carry = 0; for (int i=n1-1; i>=0; i--) { int sum = ((str1[i]-'0') + (str2[i+diff]-'0') + carry); str.push_back(sum%10 + '0'); carry = sum/10; } for (int i=n2-n1-1; i>=0; i--) { int sum = ((str2[i]-'0')+carry); str.push_back(sum%10 + '0'); carry = sum/10; } if (carry) str.push_back(carry+'0'); reverse(str.begin(), str.end()); return str; }*/ ll gcd(ll x, ll y) { if (x == 0) return y; return gcd(y % x, x); } /* ll gcdextended(ll a, ll b, ll *x, ll *y) { if (a == 0) { *x = 0, *y = 1; return b; } ll x1, y1; int gcd = gcdextended(b%a, a, &x1, &y1); *x = y1 - (b/a) * x1; *y = x1; return gcd; } ///RELATIVE COPRIME ll modinverse(ll a, ll m) { ll x, y; ll g = gcdextended(a, m, &x, &y); if (g != 1) return -1; else { ll res = (x%m + m) % m; return res; } } */ ll powmod(ll x, ll y, ll m) { if (y == 0) return 1; ll p = powmod(x, y / 2, m) % m; p = (p * p) % m; return (y % 2 == 0) ? p : (x * p) % m; } /// M IS PRIME ll modif(ll x, ll m) { return (powmod(x, m - 2, m)); } bool fa(vll &x, vll &y) { return x[0] < y[0]; } bool fa1(vll &x, vll &y) { return x[1] < y[1]; } bool f1(pll &x, pll &y) { return x.second < y.second; } bool f2(pll &x, pll &y) { return x.first > y.first; } bool f3(ll &x, ll &y) { return x > y; } #define p0(a) cout << a << " " #define p1(a) cout << a << endl #define p2(a, b) cout << a << " " << b << endl #define p3(a, b, c) cout << a << " " << b << " " << c << endl #define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl #define pin(a) \ for (auto x : a) \ cout << x << " "; \ cout << endl #define fck(a) \ cout << a; \ exit(0) #define vvll vector<vector<ll>> #define A(b) b.begin(), b.end() // include<bits/stdc++.h> int main() { fastio; freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); ll n, m; cin >> n >> m; ll b[n][m]; forl(i, 0, n) { forl(t, 0, m) b[i][t] = 0; } vector<string> f; forl(i, 0, n) { string temp; cin >> temp; f.pb(temp); } b[0][0] = 1; // for(auto x:f)cout<<x<<endl; forl(i, 0, n) { forl(t, 0, m) { if (i - 1 >= 0 && f[i - 1][t] == '.') { b[i][t] += b[i - 1][t]; b[i][t] %= m9; } if (t - 1 >= 0 && f[i][t - 1] == '.') { b[i][t] += b[i][t - 1]; b[i][t] %= m9; } b[i][t] %= m9; /* forl(i,0,n){ forl(t,0,m)cout<<b[i][t]<<" ";cout<<endl; }cout<<endl;*/ } } cout << b[n - 1][m - 1]; return 0; }
#include <cstdio> #include <cstdlib> #include <iomanip> #include <iostream> #include <algorithm> #include <cmath> #include <fstream> #include <map> #include <set> #include <string> #include <vector> #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define forl(i, a, n) for (int i = a; i < n; i++) #define rfor(i, n, a) for (int i = n; i >= a; i--) #define ll long long #define ld long double #define pb push_back #define ld long double #define vi vector<int> #define vll vector<long long> #define pi pair<int, int> #define pll pair<long long, long long> #define mp make_pair #define B begin() #define E end() #define S size() #define m9 1000000007 using namespace std; /* string fs(string str1, string str2) { if (str1.length() > str2.length()) swap(str1, str2); string str = ""; int n1 = str1.length(), n2 = str2.length(); int diff = n2 - n1; int carry = 0; for (int i=n1-1; i>=0; i--) { int sum = ((str1[i]-'0') + (str2[i+diff]-'0') + carry); str.push_back(sum%10 + '0'); carry = sum/10; } for (int i=n2-n1-1; i>=0; i--) { int sum = ((str2[i]-'0')+carry); str.push_back(sum%10 + '0'); carry = sum/10; } if (carry) str.push_back(carry+'0'); reverse(str.begin(), str.end()); return str; }*/ ll gcd(ll x, ll y) { if (x == 0) return y; return gcd(y % x, x); } /* ll gcdextended(ll a, ll b, ll *x, ll *y) { if (a == 0) { *x = 0, *y = 1; return b; } ll x1, y1; int gcd = gcdextended(b%a, a, &x1, &y1); *x = y1 - (b/a) * x1; *y = x1; return gcd; } ///RELATIVE COPRIME ll modinverse(ll a, ll m) { ll x, y; ll g = gcdextended(a, m, &x, &y); if (g != 1) return -1; else { ll res = (x%m + m) % m; return res; } } */ ll powmod(ll x, ll y, ll m) { if (y == 0) return 1; ll p = powmod(x, y / 2, m) % m; p = (p * p) % m; return (y % 2 == 0) ? p : (x * p) % m; } /// M IS PRIME ll modif(ll x, ll m) { return (powmod(x, m - 2, m)); } bool fa(vll &x, vll &y) { return x[0] < y[0]; } bool fa1(vll &x, vll &y) { return x[1] < y[1]; } bool f1(pll &x, pll &y) { return x.second < y.second; } bool f2(pll &x, pll &y) { return x.first > y.first; } bool f3(ll &x, ll &y) { return x > y; } #define p0(a) cout << a << " " #define p1(a) cout << a << endl #define p2(a, b) cout << a << " " << b << endl #define p3(a, b, c) cout << a << " " << b << " " << c << endl #define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl #define pin(a) \ for (auto x : a) \ cout << x << " "; \ cout << endl #define fck(a) \ cout << a; \ exit(0) #define vvll vector<vector<ll>> #define A(b) b.begin(), b.end() // include<bits/stdc++.h> int main() { fastio; // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); ll n, m; cin >> n >> m; ll b[n][m]; forl(i, 0, n) { forl(t, 0, m) b[i][t] = 0; } vector<string> f; forl(i, 0, n) { string temp; cin >> temp; f.pb(temp); } b[0][0] = 1; // for(auto x:f)cout<<x<<endl; forl(i, 0, n) { forl(t, 0, m) { if (i - 1 >= 0 && f[i - 1][t] == '.') { b[i][t] += b[i - 1][t]; b[i][t] %= m9; } if (t - 1 >= 0 && f[i][t - 1] == '.') { b[i][t] += b[i][t - 1]; b[i][t] %= m9; } b[i][t] %= m9; /* forl(i,0,n){ forl(t,0,m)cout<<b[i][t]<<" ";cout<<endl; }cout<<endl;*/ } } cout << b[n - 1][m - 1]; return 0; }
replace
137
139
137
139
-11
p03167
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int #define ull unsigned long long #define ff first #define ss second #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define pb push_back #define mp make_pair #define inf 2000000009 #define mod 1000000007 using namespace std; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif fast; ll n, m; cin >> n >> m; char a[n][m]; for (ll i = 0; i < n; i++) for (ll j = 0; j < m; j++) cin >> a[i][j]; ll dp[n][m]; memset(dp, 0, sizeof(dp)); for (ll i = 0; i < n; i++) { for (ll j = 0; j < m; j++) { if (i == 0 and j == 0) dp[i][j] = 1; else if (a[i][j] == '.') { if (i > 0) dp[i][j] = (dp[i - 1][j] + dp[i][j]) % mod; if (j > 0) dp[i][j] = (dp[i][j - 1] + dp[i][j]) % mod; } } } cout << dp[n - 1][m - 1] << endl; }
#include <bits/stdc++.h> #define ll long long int #define ull unsigned long long #define ff first #define ss second #define fast \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define pb push_back #define mp make_pair #define inf 2000000009 #define mod 1000000007 using namespace std; int main() { fast; ll n, m; cin >> n >> m; char a[n][m]; for (ll i = 0; i < n; i++) for (ll j = 0; j < m; j++) cin >> a[i][j]; ll dp[n][m]; memset(dp, 0, sizeof(dp)); for (ll i = 0; i < n; i++) { for (ll j = 0; j < m; j++) { if (i == 0 and j == 0) dp[i][j] = 1; else if (a[i][j] == '.') { if (i > 0) dp[i][j] = (dp[i - 1][j] + dp[i][j]) % mod; if (j > 0) dp[i][j] = (dp[i][j - 1] + dp[i][j]) % mod; } } } cout << dp[n - 1][m - 1] << endl; }
delete
16
20
16
16
-11
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int n, m, f[7][7]; char b[7][7]; void add(int &x, int v) { x += v; if (x >= mod) x -= mod; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%s", b[i] + 1); } // int f[7][7]; f[1][1] = 1; // cout<<f[5][6]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (b[i][j] == '.') { add(f[i][j], f[i - 1][j]); add(f[i][j], f[i][j - 1]); } } } printf("%d\n", f[n][m]); return 0; }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int n, m, f[1005][1005]; char b[1005][1005]; void add(int &x, int v) { x += v; if (x >= mod) x -= mod; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%s", b[i] + 1); } // int f[7][7]; f[1][1] = 1; // cout<<f[5][6]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (b[i][j] == '.') { add(f[i][j], f[i - 1][j]); add(f[i][j], f[i][j - 1]); } } } printf("%d\n", f[n][m]); return 0; }
replace
3
5
3
5
0
p03167
C++
Time Limit Exceeded
// i_am_arin #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef vector<long long> vll; typedef vector<string> vs; #define f(i, a, n) for (ll i = a; i < (ll)n; i++) #define f2(i, a, b) for (ll i = a; i <= (ll)b; i++) #define PB push_back #define FF first #define SS second const ll MOD = 1e9 + 7; const ll INF = LLONG_MAX; ll h, w; vector<string> s(1000); ll dp[1005][1005]; ll go(ll h, ll w) { if (w == 0 && h == 0) return 1; // if(dp[h][w]!=-1) return dp[h][w]; if (h == 0) { if (s[h][w] == '.') return dp[h][w] = go(h, w - 1); else return dp[h][w] = 0; } if (w == 0) { if (s[h][w] == '.') return dp[h][w] = go(h - 1, w); else return dp[h][w] = 0; } if (s[h][w] == '.') return dp[h][w] = (go(h - 1, w) + go(h, w - 1)) % MOD; else return dp[h][w] = 0; } void solve() { cin >> h >> w; memset(dp, -1, sizeof(dp)); f(i, 0, h) cin >> s[i]; cout << go(h - 1, w - 1) << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
// i_am_arin #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef vector<long long> vll; typedef vector<string> vs; #define f(i, a, n) for (ll i = a; i < (ll)n; i++) #define f2(i, a, b) for (ll i = a; i <= (ll)b; i++) #define PB push_back #define FF first #define SS second const ll MOD = 1e9 + 7; const ll INF = LLONG_MAX; ll h, w; vector<string> s(1000); ll dp[1005][1005]; ll go(ll h, ll w) { if (w == 0 && h == 0) return 1; if (dp[h][w] != -1) return dp[h][w]; if (h == 0) { if (s[h][w] == '.') return dp[h][w] = go(h, w - 1); else return dp[h][w] = 0; } if (w == 0) { if (s[h][w] == '.') return dp[h][w] = go(h - 1, w); else return dp[h][w] = 0; } if (s[h][w] == '.') return dp[h][w] = (go(h - 1, w) + go(h, w - 1)) % MOD; else return dp[h][w] = 0; } void solve() { cin >> h >> w; memset(dp, -1, sizeof(dp)); f(i, 0, h) cin >> s[i]; cout << go(h - 1, w - 1) << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin>>t; while (t--) { solve(); } return 0; }
replace
26
27
26
28
TLE
p03167
C++
Runtime Error
// Nguyen Anh Tu #include <bits/stdc++.h> #define FOR(x, a, b) for (int x = a; x <= b; x++) #define FORD(x, a, b) for (int x = a; x >= b; x--) #define maxn 1005 #define maxc 1000000007 #define MOD 1000000007 #define reset(x, y) memset(x, y, sizeof(x)) #define task "" #define mp make_pair #define pb push_back #define F first #define S second #define pii pair<int, int> #define ll long long #define bit(p, x) ((x >> p) & 1) #define remain(a, b) (a + b >= MOD) ? (a + b - MOD) : (a + b) using namespace std; int n, m; ll dp[maxn][maxn]; char a[maxn][maxn]; int main() { #ifndef ONLINE_JUDGE ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); freopen(task ".inp", "r", stdin); freopen(task ".out", "w", stdout); #endif cin >> n >> m; for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) cin >> a[i][j]; dp[1][1] = (a[1][1] == '.'); for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) if (a[i][j] == '.') { if (a[i - 1][j] == '.') (dp[i][j] += dp[i - 1][j]) %= maxc; if (a[i][j - 1] == '.') (dp[i][j] += dp[i][j - 1]) %= maxc; } cout << dp[n][m]; }
// Nguyen Anh Tu #include <bits/stdc++.h> #define FOR(x, a, b) for (int x = a; x <= b; x++) #define FORD(x, a, b) for (int x = a; x >= b; x--) #define maxn 1005 #define maxc 1000000007 #define MOD 1000000007 #define reset(x, y) memset(x, y, sizeof(x)) #define task "" #define mp make_pair #define pb push_back #define F first #define S second #define pii pair<int, int> #define ll long long #define bit(p, x) ((x >> p) & 1) #define remain(a, b) (a + b >= MOD) ? (a + b - MOD) : (a + b) using namespace std; int n, m; ll dp[maxn][maxn]; char a[maxn][maxn]; int main() { // #ifndef ONLINE_JUDGE // ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL); // freopen(task".inp","r",stdin); // freopen(task".out","w",stdout); // #endif cin >> n >> m; for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) cin >> a[i][j]; dp[1][1] = (a[1][1] == '.'); for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) if (a[i][j] == '.') { if (a[i - 1][j] == '.') (dp[i][j] += dp[i - 1][j]) %= maxc; if (a[i][j - 1] == '.') (dp[i][j] += dp[i][j - 1]) %= maxc; } cout << dp[n][m]; }
replace
23
30
23
28
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long int #define IOS \ cin.tie(NULL); \ cout.tie(NULL) #define F first #define S second #define pb push_back using namespace std; ll arr[101][101]; int main() { IOS; int w, h; char x; ll const num = 1000000007; cin >> h >> w; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { cin >> x; if (i == 1 && j == 1 && x != '#') { arr[i][j] = 1; } else if (x == '#') arr[i][j] = 0; else { arr[i][j] = (arr[i - 1][j] % num + arr[i][j - 1] % num) % num; } } } cout << arr[h][w]; }
#include <bits/stdc++.h> #define ll long long int #define IOS \ cin.tie(NULL); \ cout.tie(NULL) #define F first #define S second #define pb push_back using namespace std; ll arr[1001][1001]; int main() { IOS; int w, h; char x; ll const num = 1000000007; cin >> h >> w; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { cin >> x; if (i == 1 && j == 1 && x != '#') { arr[i][j] = 1; } else if (x == '#') arr[i][j] = 0; else { arr[i][j] = (arr[i - 1][j] % num + arr[i][j - 1] % num) % num; } } } cout << arr[h][w]; }
replace
9
10
9
10
0
p03167
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define print printf("==================\n") #define ll long long #define pi acos(-1.0) #define eps 1e-16 #define max3(a, b, c) max(a, max(b, c)) const ll INF = 1 << 30; #define mod 1000000007 typedef pair<double, double> payar; typedef struct { ll x, y; } point; priority_queue<payar, vector<payar>, greater<payar>> pq; /// accending vector<pair<double, payar>> vpp; vector<payar> vp; char ara[1006][1006]; ll dp[1006][1005]; int n, m; ll cal(int i, int j) { if (i > n or j > m) return 0; if (i == n and j == m) return 1; if (ara[i][j] == '#') return 0; if (dp[i][j] != -1) return dp[i][j] % mod; return (cal(i + 1, j) % mod + cal(i, j + 1) % mod) % mod; } int main() { cin >> n >> m; memset(dp, -1, sizeof dp); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> ara[i][j]; } } cout << cal(1, 1); return 0; }
#include <bits/stdc++.h> using namespace std; #define print printf("==================\n") #define ll long long #define pi acos(-1.0) #define eps 1e-16 #define max3(a, b, c) max(a, max(b, c)) const ll INF = 1 << 30; #define mod 1000000007 typedef pair<double, double> payar; typedef struct { ll x, y; } point; priority_queue<payar, vector<payar>, greater<payar>> pq; /// accending vector<pair<double, payar>> vpp; vector<payar> vp; char ara[1006][1006]; ll dp[1006][1005]; int n, m; ll cal(int i, int j) { if (i > n or j > m) return 0; if (i == n and j == m) return 1; if (ara[i][j] == '#') return 0; if (dp[i][j] != -1) return dp[i][j] % mod; return dp[i][j] = (cal(i + 1, j) % mod + cal(i, j + 1) % mod) % mod; } int main() { cin >> n >> m; memset(dp, -1, sizeof dp); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> ara[i][j]; } } cout << cal(1, 1); return 0; }
replace
28
29
28
29
TLE
p03167
C++
Runtime Error
#include <stdio.h> // #define large 1050 #define large 100 #define mod 1000000007 int main() { int h, w; char a[large][large]; scanf("%d%d", &h, &w); for (int i = 0; i < h; i++) { scanf("%s", &a[i]); } int dp[large][large] = {}; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (i == 0 && j == 0) { dp[i][j] += 1; continue; } if (a[i][j] == '#') continue; if (i != 0) { dp[i][j] += dp[i - 1][j]; dp[i][j] %= mod; } if (j != 0) { dp[i][j] += dp[i][j - 1]; dp[i][j] %= mod; } } } // for(int i=0;i<h;i++) // { // for(int j=0;j<w;j++) // { // printf("%d ",dp[i][j]); // } // printf("\n"); // } printf("%d\n", dp[h - 1][w - 1]); }
#include <stdio.h> #define large 1050 // #define large 100 #define mod 1000000007 int main() { int h, w; char a[large][large]; scanf("%d%d", &h, &w); for (int i = 0; i < h; i++) { scanf("%s", &a[i]); } int dp[large][large] = {}; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (i == 0 && j == 0) { dp[i][j] += 1; continue; } if (a[i][j] == '#') continue; if (i != 0) { dp[i][j] += dp[i - 1][j]; dp[i][j] %= mod; } if (j != 0) { dp[i][j] += dp[i][j - 1]; dp[i][j] %= mod; } } } // for(int i=0;i<h;i++) // { // for(int j=0;j<w;j++) // { // printf("%d ",dp[i][j]); // } // printf("\n"); // } printf("%d\n", dp[h - 1][w - 1]); }
replace
1
3
1
3
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int height, width; long long int dp[1010][1010]; string a[1000]; int main() { ios::sync_with_stdio(false); cin >> height >> width; for (int i = 0; i < height; i++) cin >> a[i]; dp[0][0] = 1; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { if (a[i][j] == '#') continue; if (a[i][j + 1] == '.') { dp[i][j + 1] += dp[i][j]; dp[i][j + 1] %= 1000000007; } if (a[i + 1][j] == '.') { dp[i + 1][j] += dp[i][j]; dp[i + 1][j] %= 1000000007; } } } cout << dp[height - 1][width - 1] % (1000000007) << endl; }
#include <bits/stdc++.h> using namespace std; int height, width; long long int dp[1010][1010]; string a[1001]; int main() { ios::sync_with_stdio(false); cin >> height >> width; for (int i = 0; i < height; i++) cin >> a[i]; dp[0][0] = 1; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { if (a[i][j] == '#') continue; if (a[i][j + 1] == '.') { dp[i][j + 1] += dp[i][j]; dp[i][j + 1] %= 1000000007; } if (a[i + 1][j] == '.') { dp[i + 1][j] += dp[i][j]; dp[i + 1][j] %= 1000000007; } } } cout << dp[height - 1][width - 1] % (1000000007) << endl; }
replace
4
5
4
5
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> #define mod 1000000007 using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<char>> grid(n, vector<char>(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> grid[i][j]; } } vector<vector<int>> dp(n, vector<int>(m, 0)); dp[0][0] = 1; for (int i = 1; i < m; i++) { if (grid[0][i] == '#') break; dp[0][i] = dp[0][i - 1] % 1000000007; } for (int i = 1; i < m; i++) { if (grid[i][0] == '#') break; dp[i][0] = dp[i - 1][0] % 1000000007; } for (int i = 1; i < n; i++) { for (int j = 1; j < m; j++) { if (grid[i][j] == '#') continue; if (grid[i - 1][j] != '#') dp[i][j] = (dp[i][j] % mod + dp[i - 1][j] % mod) % mod; if (grid[i][j - 1] != '#') dp[i][j] = (dp[i][j] % mod + dp[i][j - 1] % mod) % mod; } } cout << dp[n - 1][m - 1]; }
#include <bits/stdc++.h> #define mod 1000000007 using namespace std; int main() { int n, m; cin >> n >> m; vector<vector<char>> grid(n, vector<char>(m)); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> grid[i][j]; } } vector<vector<int>> dp(n, vector<int>(m, 0)); dp[0][0] = 1; for (int i = 1; i < m; i++) { if (grid[0][i] == '#') break; dp[0][i] = dp[0][i - 1] % 1000000007; } for (int i = 1; i < n; i++) { if (grid[i][0] == '#') break; dp[i][0] = dp[i - 1][0] % 1000000007; } for (int i = 1; i < n; i++) { for (int j = 1; j < m; j++) { if (grid[i][j] == '#') continue; if (grid[i - 1][j] != '#') dp[i][j] = (dp[i][j] % mod + dp[i - 1][j] % mod) % mod; if (grid[i][j - 1] != '#') dp[i][j] = (dp[i][j] % mod + dp[i][j - 1] % mod) % mod; } } cout << dp[n - 1][m - 1]; }
replace
19
20
19
20
-11
p03167
C++
Runtime Error
//<============ Author --> @venom ============>// #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; #define fo(i, n) for (int i = 0; i < n; i++) #define int long long #define pb emplace_back #define mp make_pair #define ff first #define ss second #define all(x) x.begin(), x.end() #define sortall(x) sort(all(x)) #define sortrev(x) sort(all(x), greater<int>()) #define w(x) \ int x; \ cin >> x; \ while (x--) #define trunc(x, y) fixed << setprecision(y) << x #define mk(arr, n, type) type *arr = new type[n]; #define PI 3.1415926535897932384626 #define mod 1000000007 #define inf 1e9 + 5 #define FIO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) typedef pair<int, int> pi; typedef vector<int> vi; typedef vector<pi> vpi; typedef vector<vi> vvi; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; const int N = 3e5, M = N; int mpow(int base, int exp); int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } //<----------------------------------------------------------------------------->// void fastIO() { FIO; #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif } char grid[1002][1002]; int solve(int n, int m) { int dp[n + 1][m + 1]; dp[n][m] = 1; for (int i = n; i >= 1; i--) { for (int j = m; j >= 1; j--) { if (i == n && j == m) continue; if (grid[i][j] == '#') dp[i][j] = 0; else dp[i][j] = (((i == n) ? 0 : dp[i + 1][j]) + ((j == m) ? 0 : dp[i][j + 1])) % mod; } } return dp[1][1]; } int32_t main() { fastIO(); int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> grid[i][j]; } } cout << solve(n, m); return 0; } int mpow(int base, int exp) { base %= mod; int result = 1; while (exp > 0) { if (exp & 1) result = ((int)result * base) % mod; base = ((int)base * base) % mod; exp >>= 1; } return result; }
//<============ Author --> @venom ============>// #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; #define fo(i, n) for (int i = 0; i < n; i++) #define int long long #define pb emplace_back #define mp make_pair #define ff first #define ss second #define all(x) x.begin(), x.end() #define sortall(x) sort(all(x)) #define sortrev(x) sort(all(x), greater<int>()) #define w(x) \ int x; \ cin >> x; \ while (x--) #define trunc(x, y) fixed << setprecision(y) << x #define mk(arr, n, type) type *arr = new type[n]; #define PI 3.1415926535897932384626 #define mod 1000000007 #define inf 1e9 + 5 #define FIO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) typedef pair<int, int> pi; typedef vector<int> vi; typedef vector<pi> vpi; typedef vector<vi> vvi; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; const int N = 3e5, M = N; int mpow(int base, int exp); int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } //<----------------------------------------------------------------------------->// void fastIO() { FIO; #ifndef ONLINE_JUDGE // for getting input from input.txt freopen("input.txt", "r", stdin); // for writing output to output.txt freopen("output.txt", "w", stdout); #endif } char grid[1002][1002]; int solve(int n, int m) { int dp[n + 1][m + 1]; dp[n][m] = 1; for (int i = n; i >= 1; i--) { for (int j = m; j >= 1; j--) { if (i == n && j == m) continue; if (grid[i][j] == '#') dp[i][j] = 0; else dp[i][j] = (((i == n) ? 0 : dp[i + 1][j]) + ((j == m) ? 0 : dp[i][j + 1])) % mod; } } return dp[1][1]; } int32_t main() { FIO; int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> grid[i][j]; } } cout << solve(n, m); return 0; } int mpow(int base, int exp) { base %= mod; int result = 1; while (exp > 0) { if (exp & 1) result = ((int)result * base) % mod; base = ((int)base * base) % mod; exp >>= 1; } return result; }
replace
80
81
80
81
TLE
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const int MOD = 1e9 + 7; void solve() { int h, w; cin >> h >> w; vector<vector<ll>> dp(h + 1, vector<ll>(w + 1, 0)); for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { char c; cin >> c; if (c == '#') { dp[i + 1][j + 1] = -1; } } } dp[0][1] = 1; for (int i = 1; i <= h; ++i) { for (int j = 1; j <= w; ++j) { if (dp[i][j] < 0) { dp[i][j] = 0; continue; } dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % MOD; } } cout << dp[h][w]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif solve(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const int MOD = 1e9 + 7; void solve() { int h, w; cin >> h >> w; vector<vector<ll>> dp(h + 1, vector<ll>(w + 1, 0)); for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { char c; cin >> c; if (c == '#') { dp[i + 1][j + 1] = -1; } } } dp[0][1] = 1; for (int i = 1; i <= h; ++i) { for (int j = 1; j <= w; ++j) { if (dp[i][j] < 0) { dp[i][j] = 0; continue; } dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % MOD; } } cout << dp[h][w]; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); // #endif solve(); return 0; }
replace
35
39
35
38
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> #define N 100 + 10 #define ll long long int using namespace std; int main() { int h, w, current, last; ll table[2][N]; string map; cin >> h >> w; // initial conditions for (int i = 0; i <= w; i++) { table[0][i] = 0; table[1][i] = 0; } table[0][1] = 1LL; for (int i = 1; i <= h; i++) { current = i % 2; last = (i + 1) % 2; cin >> map; for (int j = 1; j <= w; j++) { table[current][j] = 0; if (map[j - 1] != '#') { table[current][j] = (table[last][j] + table[current][j - 1]) % ((long long)1e9 + 7); } } } cout << table[h % 2][w] << '\n'; return 0; }
#include <bits/stdc++.h> #define N 1000 + 10 #define ll long long int using namespace std; int main() { int h, w, current, last; ll table[2][N]; string map; cin >> h >> w; // initial conditions for (int i = 0; i <= w; i++) { table[0][i] = 0; table[1][i] = 0; } table[0][1] = 1LL; for (int i = 1; i <= h; i++) { current = i % 2; last = (i + 1) % 2; cin >> map; for (int j = 1; j <= w; j++) { table[current][j] = 0; if (map[j - 1] != '#') { table[current][j] = (table[last][j] + table[current][j - 1]) % ((long long)1e9 + 7); } } } cout << table[h % 2][w] << '\n'; return 0; }
replace
1
2
1
2
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fo(i, n) for (ll i = 0; i < n; i++) #define endl "\n" #define of(i, n) for (ll i = n - 1; i >= 0; i--) #define ll long long #define vec vector<ll> #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define tr(container, it) \ for (typeof(container.begin()) it = container.begin(); \ it != container.end(); it++) ll mod = 1e9 + 7; #define umap unordered_map string sp, tp; /*string st(string s, string t) { ll n = s.length(); ll m = t.length(); if(s.length()==0 || t.length()==0) {dp[n][m]=0;return "";} if(dp[s.length()][t.length()]!=0) return st(s,t); else if(s[0]==t[0]) { dp[n][m]++; s.erase(s.begin()); t.erase(t.begin()); return st(s,t); } }*/ ll ncr(ll n, ll r) { long long p = 1, k = 1; if (n - r < r) r = n - r; if (r != 0) { while (r) { p *= n; k *= r; long long m = __gcd(p, k); p /= m; k /= m; n--; r--; } } else p = 1; return p; } ll dp[1001][1001]; int main() { fio; ll n, m; cin >> n >> m; char c[n][m]; fo(i, n) { fo(j, m) { cin >> c[i + 1][j + 1]; } } ll sum = 0; dp[1][1] = 1; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (c[i][j] == '.') dp[i][j] += dp[i][j - 1] + dp[i - 1][j]; dp[i][j] = dp[i][j] % mod; } } cout << dp[n][m]; }
#include <bits/stdc++.h> using namespace std; #define fo(i, n) for (ll i = 0; i < n; i++) #define endl "\n" #define of(i, n) for (ll i = n - 1; i >= 0; i--) #define ll long long #define vec vector<ll> #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define tr(container, it) \ for (typeof(container.begin()) it = container.begin(); \ it != container.end(); it++) ll mod = 1e9 + 7; #define umap unordered_map string sp, tp; /*string st(string s, string t) { ll n = s.length(); ll m = t.length(); if(s.length()==0 || t.length()==0) {dp[n][m]=0;return "";} if(dp[s.length()][t.length()]!=0) return st(s,t); else if(s[0]==t[0]) { dp[n][m]++; s.erase(s.begin()); t.erase(t.begin()); return st(s,t); } }*/ ll ncr(ll n, ll r) { long long p = 1, k = 1; if (n - r < r) r = n - r; if (r != 0) { while (r) { p *= n; k *= r; long long m = __gcd(p, k); p /= m; k /= m; n--; r--; } } else p = 1; return p; } ll dp[1001][1001]; int main() { fio; ll n, m; cin >> n >> m; char c[n + 1][m + 1]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) cin >> c[i][j]; } ll sum = 0; dp[1][1] = 1; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (c[i][j] == '.') dp[i][j] += dp[i][j - 1] + dp[i - 1][j]; dp[i][j] = dp[i][j] % mod; } } cout << dp[n][m]; }
replace
64
67
64
68
0
p03167
C++
Runtime Error
#include <algorithm> #include <array> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <numeric> #include <queue> #include <set> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using lli = long long int; // #define DEBUG #ifdef DEBUG #define debug(var) cout << (#var) << ": " << (var) << endl; template <class T> void dump_array_impl(const T &a) { bool first = true; for (auto &&x : a) { if (!first) cout << ", "; else first = false; cout << x; } } #define debug_array(a) \ cout << (#a) << ": "; \ dump_array_impl(a); \ cout << endl #else #define debug(var) \ {} #define debug_array(a) \ {} #endif template <class T, class U> void init_n(vector<T> &v, size_t n, U x) { v = vector<T>(n, x); } template <class T> void init_n(vector<T> &v, size_t n) { init_n(v, n, T()); } template <class T> void read_n(vector<T> &v, size_t n) { v = vector<T>(n); for (lli i = 0; i < n; ++i) cin >> v[i]; } template <class T> T gabs(const T &x) { return max(x, -x); } #define abs gabs const lli mod = 1e9 + 7; lli h, w; vector<string> bd; vector<vector<lli>> c; int main() { cin >> h >> w; read_n(bd, h); for (lli i = 0; i < h; ++i) bd[i].push_back('#'); bd[h] = string(w + 1, '#'); for (lli i = 0; i < h + 1; ++i) c.emplace_back(w + 1, 0); c[0][0] = 1; queue<pair<lli, lli>> q; q.emplace(0, 0); while (!q.empty()) { auto p = q.front(); lli x = p.first, y = p.second; q.pop(); if (bd[y][x + 1] != '#') { c[y][x + 1] = (c[y][x] + c[y][x + 1]) % mod; if (bd[y][x + 1] == '.') { q.emplace(x + 1, y); bd[y][x + 1] = '*'; } } if (bd[y + 1][x] != '#') { c[y + 1][x] = (c[y][x] + c[y + 1][x]) % mod; if (bd[y + 1][x] == '.') { q.emplace(x, y + 1); bd[y + 1][x] = '*'; } } } cout << c[h - 1][w - 1] << endl; return 0; }
#include <algorithm> #include <array> #include <cassert> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <numeric> #include <queue> #include <set> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; using lli = long long int; // #define DEBUG #ifdef DEBUG #define debug(var) cout << (#var) << ": " << (var) << endl; template <class T> void dump_array_impl(const T &a) { bool first = true; for (auto &&x : a) { if (!first) cout << ", "; else first = false; cout << x; } } #define debug_array(a) \ cout << (#a) << ": "; \ dump_array_impl(a); \ cout << endl #else #define debug(var) \ {} #define debug_array(a) \ {} #endif template <class T, class U> void init_n(vector<T> &v, size_t n, U x) { v = vector<T>(n, x); } template <class T> void init_n(vector<T> &v, size_t n) { init_n(v, n, T()); } template <class T> void read_n(vector<T> &v, size_t n) { v = vector<T>(n); for (lli i = 0; i < n; ++i) cin >> v[i]; } template <class T> T gabs(const T &x) { return max(x, -x); } #define abs gabs const lli mod = 1e9 + 7; lli h, w; vector<string> bd; vector<vector<lli>> c; int main() { cin >> h >> w; read_n(bd, h); for (lli i = 0; i < h; ++i) bd[i].push_back('#'); bd.emplace_back(w + 1, '#'); for (lli i = 0; i < h + 1; ++i) c.emplace_back(w + 1, 0); c[0][0] = 1; queue<pair<lli, lli>> q; q.emplace(0, 0); while (!q.empty()) { auto p = q.front(); lli x = p.first, y = p.second; q.pop(); if (bd[y][x + 1] != '#') { c[y][x + 1] = (c[y][x] + c[y][x + 1]) % mod; if (bd[y][x + 1] == '.') { q.emplace(x + 1, y); bd[y][x + 1] = '*'; } } if (bd[y + 1][x] != '#') { c[y + 1][x] = (c[y][x] + c[y + 1][x]) % mod; if (bd[y + 1][x] == '.') { q.emplace(x, y + 1); bd[y + 1][x] = '*'; } } } cout << c[h - 1][w - 1] << endl; return 0; }
replace
62
63
62
63
-11
p03167
C++
Runtime Error
#include <bits/stdc++.h> #define ROCK \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define f first #define sec second using namespace std; typedef long long ll; const long long int linf = (ll)9e18; const int dx[8] = {0, 0, 1, -1, 1, -1, 1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, -1, 1}; const int N = 105, MOD = (int)1e9 + 7; ll n, m, dp[N][N]; char grid[N][N]; bool isvalid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m && grid[i][j] != '#'; } ll solve(int i, int j) { if (i == n - 1 && j == m - 1) return 1; ll &ret = dp[i][j]; if (~ret) return ret; ll right = 0; if (isvalid(i + 1, j)) right = solve(i + 1, j); ll down = 0; if (isvalid(i, j + 1)) down = solve(i, j + 1); return ret = (right % MOD + down % MOD) % MOD; } int main() { ROCK; memset(dp, -1, sizeof dp); cin >> n >> m; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> grid[i][j]; cout << solve(0, 0) << endl; return 0; }
#include <bits/stdc++.h> #define ROCK \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define f first #define sec second using namespace std; typedef long long ll; const long long int linf = (ll)9e18; const int dx[8] = {0, 0, 1, -1, 1, -1, 1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, -1, 1}; const int N = 1005, MOD = (int)1e9 + 7; ll n, m, dp[N][N]; char grid[N][N]; bool isvalid(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m && grid[i][j] != '#'; } ll solve(int i, int j) { if (i == n - 1 && j == m - 1) return 1; ll &ret = dp[i][j]; if (~ret) return ret; ll right = 0; if (isvalid(i + 1, j)) right = solve(i + 1, j); ll down = 0; if (isvalid(i, j + 1)) down = solve(i, j + 1); return ret = (right % MOD + down % MOD) % MOD; } int main() { ROCK; memset(dp, -1, sizeof dp); cin >> n >> m; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cin >> grid[i][j]; cout << solve(0, 0) << endl; return 0; }
replace
13
14
13
14
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define ull unsigned long long #define ll long long #define M 1000000007 #define pb emplace_back #define p_q priority_queue #define pii pair<ll, ll> #define vi vector<ll> #define vii vector<pii> #define mi map<ll, ll> #define mii map<pii, ll> #define all(a) (a).begin(), (a).end() #define sz(x) (ll) x.size() #define endl '\n' #define gcd(a, b) __gcd((a), (b)) #define lcm(a, b) ((a) * (b)) / gcd((a), (b)) #define ios \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define mp make_pair #define lb lower_bound #define ub upper_bound #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define ini(a, n, b) \ for (ll int i = 0; i < n; i++) \ a[i] = 0; #define cset(a) __builtin_popcountll(a) #define hell (ull)1e9 #define error(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ cerr << endl; \ } void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } bool g[(ll)1e3 + 2][(ll)1e3 + 2]; int dp[(ll)1e3 + 2][(ll)1e3 + 2]; signed main(void) { ios #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int h, w; cin >> h >> w; dp[1][1] = 1; rep(i, 1, h + 1) rep(j, 1, w + 1) { char c; cin >> c; if (c == '#') g[i][j] = 1; } rep(i, 1, h + 1) rep(j, 1, w + 1) { if (i == 1 && j == 1) continue; if (g[i][j]) continue; dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % M; } cout << dp[h][w] << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long #define ull unsigned long long #define ll long long #define M 1000000007 #define pb emplace_back #define p_q priority_queue #define pii pair<ll, ll> #define vi vector<ll> #define vii vector<pii> #define mi map<ll, ll> #define mii map<pii, ll> #define all(a) (a).begin(), (a).end() #define sz(x) (ll) x.size() #define endl '\n' #define gcd(a, b) __gcd((a), (b)) #define lcm(a, b) ((a) * (b)) / gcd((a), (b)) #define ios \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define mp make_pair #define lb lower_bound #define ub upper_bound #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define ini(a, n, b) \ for (ll int i = 0; i < n; i++) \ a[i] = 0; #define cset(a) __builtin_popcountll(a) #define hell (ull)1e9 #define error(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ cerr << endl; \ } void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; err(++it, args...); } bool g[(ll)1e3 + 2][(ll)1e3 + 2]; int dp[(ll)1e3 + 2][(ll)1e3 + 2]; signed main(void) { ios int h, w; cin >> h >> w; dp[1][1] = 1; rep(i, 1, h + 1) rep(j, 1, w + 1) { char c; cin >> c; if (c == '#') g[i][j] = 1; } rep(i, 1, h + 1) rep(j, 1, w + 1) { if (i == 1 && j == 1) continue; if (g[i][j]) continue; dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % M; } cout << dp[h][w] << endl; }
replace
52
58
52
53
TLE
p03167
C++
Runtime Error
#include <bits/stdc++.h> #define each(i, c) for (auto &i : c) #define unless(cond) if (!(cond)) using namespace std; typedef long long int lli; typedef unsigned long long ull; typedef complex<double> point; template <typename P, typename Q> ostream &operator<<(ostream &os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <typename P, typename Q> istream &operator>>(istream &is, pair<P, Q> &p) { is >> p.first >> p.second; return is; } template <typename T> ostream &operator<<(ostream &os, vector<T> v) { os << "("; each(i, v) os << i << ","; os << ")"; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { each(i, v) is >> i; return is; } template <typename T> inline T setmax(T &a, T b) { return a = std::max(a, b); } template <typename T> inline T setmin(T &a, T b) { return a = std::min(a, b); } int main(int argc, char *argv[]) { ios_base::sync_with_stdio(0); cin.tie(0); int h, w; while (cin >> h >> w) { const int H = 100 + 5; const int W = 100 + 5; char g[H][W]; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { cin >> g[i][j]; } } const lli mod = 1e9 + 7; static lli dp[H][W]; fill(&dp[0][0], &dp[H - 1][W - 1] + 1, 0); dp[0][0] = 1; int di[] = {0, 1}; int dj[] = {1, 0}; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { for (int d = 0; d < 2; ++d) { int ni = i + di[d]; int nj = j + dj[d]; unless(0 <= ni && ni < h) continue; unless(0 <= nj && nj < w) continue; if (g[ni][nj] == '#') continue; (dp[ni][nj] += dp[i][j]) %= mod; } } } cout << dp[h - 1][w - 1] << endl; } return 0; }
#include <bits/stdc++.h> #define each(i, c) for (auto &i : c) #define unless(cond) if (!(cond)) using namespace std; typedef long long int lli; typedef unsigned long long ull; typedef complex<double> point; template <typename P, typename Q> ostream &operator<<(ostream &os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <typename P, typename Q> istream &operator>>(istream &is, pair<P, Q> &p) { is >> p.first >> p.second; return is; } template <typename T> ostream &operator<<(ostream &os, vector<T> v) { os << "("; each(i, v) os << i << ","; os << ")"; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { each(i, v) is >> i; return is; } template <typename T> inline T setmax(T &a, T b) { return a = std::max(a, b); } template <typename T> inline T setmin(T &a, T b) { return a = std::min(a, b); } int main(int argc, char *argv[]) { ios_base::sync_with_stdio(0); cin.tie(0); int h, w; while (cin >> h >> w) { const int H = 1000 + 5; const int W = 1000 + 5; char g[H][W]; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { cin >> g[i][j]; } } const lli mod = 1e9 + 7; static lli dp[H][W]; fill(&dp[0][0], &dp[H - 1][W - 1] + 1, 0); dp[0][0] = 1; int di[] = {0, 1}; int dj[] = {1, 0}; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { for (int d = 0; d < 2; ++d) { int ni = i + di[d]; int nj = j + dj[d]; unless(0 <= ni && ni < h) continue; unless(0 <= nj && nj < w) continue; if (g[ni][nj] == '#') continue; (dp[ni][nj] += dp[i][j]) %= mod; } } } cout << dp[h - 1][w - 1] << endl; } return 0; }
replace
41
43
41
43
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; char grid[105][105]; long long int mem[105][105]; long long int n, m; long long int dp(long long int i, long long int j) { if (i == n - 1 && j == m - 1) { return 1; } if (mem[i][j] != -1) { return mem[i][j]; } long long int x = 0; if (i + 1 < n && grid[i + 1][j] == '.') { x = (x + dp(i + 1, j)) % 1000000007; } if (j + 1 < m && grid[i][j + 1] == '.') x = (x + dp(i, j + 1)) % 1000000007; mem[i][j] = x; // cout<<"i: "<<i<<" j: "<<j<<" = "<<x<<endl; return x; } int main() { cin >> n >> m; for (long long int i = 0; i < n; i++) { for (long long int j = 0; j < m; j++) { cin >> grid[i][j]; } } memset(mem, -1, sizeof(mem)); long long int ans = dp(0, 0) % 1000000007; cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; char grid[1005][1005]; long long int mem[1005][1005]; long long int n, m; long long int dp(long long int i, long long int j) { if (i == n - 1 && j == m - 1) { return 1; } if (mem[i][j] != -1) { return mem[i][j]; } long long int x = 0; if (i + 1 < n && grid[i + 1][j] == '.') { x = (x + dp(i + 1, j)) % 1000000007; } if (j + 1 < m && grid[i][j + 1] == '.') x = (x + dp(i, j + 1)) % 1000000007; mem[i][j] = x; // cout<<"i: "<<i<<" j: "<<j<<" = "<<x<<endl; return x; } int main() { cin >> n >> m; for (long long int i = 0; i < n; i++) { for (long long int j = 0; j < m; j++) { cin >> grid[i][j]; } } memset(mem, -1, sizeof(mem)); long long int ans = dp(0, 0) % 1000000007; cout << ans; return 0; }
replace
3
5
3
5
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int maxn = 110; const int INF = 1e9 + 7; char a[maxn][maxn]; int dp[maxn][maxn]; // dp[i][j]´ú±íÖÕµãΪi,jµÄ·½°¸Êý bool vis[maxn][maxn]; long long ans = 0, h, w; int main() { cin >> h >> w; for (int i = 1; i <= h; i++) { scanf("%s", a[i] + 1); } for (int i = 1; i <= w; i++) { if (a[1][i] == '.') dp[1][i] = 1; else break; } for (int i = 1; i <= h; i++) { if (a[i][1] == '.') dp[i][1] = 1; else break; } for (int i = 2; i <= h; i++) { for (int j = 2; j <= w; j++) { if (a[i][j] == '.') { dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % INF; } } } cout << dp[h][w]; return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1100; const int INF = 1e9 + 7; char a[maxn][maxn]; int dp[maxn][maxn]; // dp[i][j]´ú±íÖÕµãΪi,jµÄ·½°¸Êý bool vis[maxn][maxn]; long long ans = 0, h, w; int main() { cin >> h >> w; for (int i = 1; i <= h; i++) { scanf("%s", a[i] + 1); } for (int i = 1; i <= w; i++) { if (a[1][i] == '.') dp[1][i] = 1; else break; } for (int i = 1; i <= h; i++) { if (a[i][1] == '.') dp[i][1] = 1; else break; } for (int i = 2; i <= h; i++) { for (int j = 2; j <= w; j++) { if (a[i][j] == '.') { dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % INF; } } } cout << dp[h][w]; return 0; }
replace
2
3
2
3
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define pb push_back #define N 1000000007 string mat[1000]; vector<vector<int>> dp(1000, vector<int>(1000, -1)); int n, x, y, m; int solve(int i, int j) { if (dp[i][j] != -1) { return dp[i][j]; } if ((i == n - 1 && j == m - 1)) { return 1; } if (i >= n || j >= m || mat[i][j] == '#') { return 0; } dp[i][j] = (solve(i + 1, j) + solve(i, j + 1)) % N; return dp[i][j] % N; } int main() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> mat[i]; } cout << solve(0, 0); }
#include <bits/stdc++.h> using namespace std; #define pb push_back #define N 1000000007 string mat[1001]; vector<vector<int>> dp(1001, vector<int>(1001, -1)); int n, x, y, m; int solve(int i, int j) { if (dp[i][j] != -1) { return dp[i][j]; } if ((i == n - 1 && j == m - 1)) { return 1; } if (i >= n || j >= m || mat[i][j] == '#') { return 0; } dp[i][j] = (solve(i + 1, j) + solve(i, j + 1)) % N; return dp[i][j] % N; } int main() { cin >> n >> m; for (int i = 0; i < n; i++) { cin >> mat[i]; } cout << solve(0, 0); }
replace
4
6
4
6
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> #define mp make_pair #define fst first #define snd second #define forn(i, n) for (int i = 0; i < int(n); i++) #define forn1(i, n) for (int i = 1; i <= int(n); i++) #define popcnt __builtin_popcount using namespace std; typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<int, ll> pil; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; template <typename T> T id(T b) { return b; }; template <class It> bool all(It f, It l) { return std::all_of(f, l, id<bool>); } template <class It> bool any(It f, It l) { return std::any_of(f, l, id<bool>); } template <typename T> void chmax(T &x, T y) { if (x < y) x = y; } template <typename T> void chmin(T &x, T y) { if (x > y) x = y; } const long long MOD = 1000000007; const int MAX_HW = 1000; int h, w; string grid[MAX_HW]; ll c[MAX_HW][MAX_HW]; int dx[2] = {1, 0}; int dy[2] = {0, 1}; ll dfs(int i, int j) { if (c[i][j] >= 0) return c[i][j]; if (i == h - 1 && j == w - 1) return c[i][j] = 1; ll res = 0; forn(k, 2) { int x = i + dx[k], y = j + dy[k]; if (grid[x][y] == '.') res = (res + dfs(x, y)) % MOD; } return c[i][j] = res; } int main() { #ifdef FASTIO ios_base::sync_with_stdio(false); cin.tie(nullptr); #endif cin >> h >> w; forn(i, h) cin >> grid[i]; forn(i, h) fill_n(c[i], w, -1); cout << dfs(0, 0) << endl; return 0; }
#include <bits/stdc++.h> #define mp make_pair #define fst first #define snd second #define forn(i, n) for (int i = 0; i < int(n); i++) #define forn1(i, n) for (int i = 1; i <= int(n); i++) #define popcnt __builtin_popcount using namespace std; typedef unsigned int uint; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<int, ll> pil; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; template <typename T> T id(T b) { return b; }; template <class It> bool all(It f, It l) { return std::all_of(f, l, id<bool>); } template <class It> bool any(It f, It l) { return std::any_of(f, l, id<bool>); } template <typename T> void chmax(T &x, T y) { if (x < y) x = y; } template <typename T> void chmin(T &x, T y) { if (x > y) x = y; } const long long MOD = 1000000007; const int MAX_HW = 1000; int h, w; string grid[MAX_HW]; ll c[MAX_HW][MAX_HW]; int dx[2] = {1, 0}; int dy[2] = {0, 1}; ll dfs(int i, int j) { if (c[i][j] >= 0) return c[i][j]; if (i == h - 1 && j == w - 1) return c[i][j] = 1; ll res = 0; forn(k, 2) { int x = i + dx[k], y = j + dy[k]; if (x < h && y < w && grid[x][y] == '.') res = (res + dfs(x, y)) % MOD; } return c[i][j] = res; } int main() { #ifdef FASTIO ios_base::sync_with_stdio(false); cin.tie(nullptr); #endif cin >> h >> w; forn(i, h) cin >> grid[i]; forn(i, h) fill_n(c[i], w, -1); cout << dfs(0, 0) << endl; return 0; }
replace
52
53
52
53
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); } ll mod = 1e9 + 7; int main() { fast(); ll r, c; cin >> r >> c; ll dp[r][c]; char arr[r][c]; for (ll i = 0; i < r; i++) { for (ll j = 0; j < c; j++) cin >> arr[i][j]; } for (ll i = 0; i <= r; i++) { for (ll j = 0; j < c; j++) { dp[i][j] = 0; } } dp[r - 1][c - 1] = 1; for (ll i = r - 2; i >= 0; i--) { if (arr[i][c - 1] == '#') dp[i][c - 1] = 0; else dp[i][c - 1] = dp[i + 1][c - 1]; } for (ll i = c - 2; i >= 0; i--) { if (arr[r - 1][i] == '#') dp[r - 1][i] = 0; else dp[r - 1][i] = dp[r - 1][i + 1]; } for (ll i = r - 2; i >= 0; i--) { for (ll j = c - 2; j >= 0; j--) { if (arr[i][j] == '#') { dp[i][j] = 0; } else { dp[i][j] = (dp[i][j + 1] + dp[i + 1][j]) % mod; } } } cout << dp[0][0]; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); } ll mod = 1e9 + 7; int main() { fast(); ll r, c; cin >> r >> c; ll dp[r][c]; char arr[r][c]; for (ll i = 0; i < r; i++) { for (ll j = 0; j < c; j++) cin >> arr[i][j]; } for (ll i = 0; i < r; i++) { for (ll j = 0; j < c; j++) { dp[i][j] = 0; } } dp[r - 1][c - 1] = 1; for (ll i = r - 2; i >= 0; i--) { if (arr[i][c - 1] == '#') dp[i][c - 1] = 0; else dp[i][c - 1] = dp[i + 1][c - 1]; } for (ll i = c - 2; i >= 0; i--) { if (arr[r - 1][i] == '#') dp[r - 1][i] = 0; else dp[r - 1][i] = dp[r - 1][i + 1]; } for (ll i = r - 2; i >= 0; i--) { for (ll j = c - 2; j >= 0; j--) { if (arr[i][j] == '#') { dp[i][j] = 0; } else { dp[i][j] = (dp[i][j + 1] + dp[i + 1][j]) % mod; } } } cout << dp[0][0]; }
replace
24
25
24
25
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define make_it_fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define mp make_pair #define pb push_back #define all(x) (x).begin(), (x).end() #define ll long long #define ld long double #define endl "\n" #define ff first #define ss second void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) 20 #endif ll power(ll a, ll b, ll m = 1e9 + 7) { a %= m; if (b == 1) return a; if (b == 0) return 1; ll ret = power(a, b / 2); ret = (ret % m * ret % m) % m; if (b & 1) ret = (ret % m * a % m) % m; return ret; } ll lcm(ll a, ll b) { return (a * b) / (__gcd(a, b)); } const ll N = 1e3, M = 1e9 + 7; ll dp[N][N]; char a[N][N]; void update(ll n, ll m) { if (n == 0 || m == 0) return; int i; for (i = n; i >= 1; i--) { if (a[i][m] == '#') continue; if (a[i + 1][m] != '#') dp[i][m] += dp[i + 1][m]; if (a[i][m + 1] != '#') dp[i][m] += dp[i][m + 1]; dp[i][m] %= M; } for (i = m - 1; i >= 1; i--) { if (a[n][i] == '#') continue; if (a[n][i + 1] != '#') dp[n][i] += dp[n][i + 1]; if (a[n + 1][i] != '#') dp[n][i] += dp[n + 1][i]; dp[n][i] %= M; } update(n - 1, m - 1); } void solve() { ll n, m, i, j; cin >> n >> m; for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) { cin >> a[i][j]; } } memset(dp, 0, sizeof(dp)); dp[n][m] = 1; for (i = n - 1; i >= 1; i--) { if (a[i][m] != '#') dp[i][m] = dp[i + 1][m]; } for (i = m - 1; i >= 1; i--) { if (a[n][i] != '#') dp[n][i] = dp[n][i + 1]; } update(n - 1, m - 1); // for(i=1;i<=n;i++) // { // for(j=1;j<=m;j++) // cout<<dp[i][j]<<" "; // cout<<endl; // } cout << dp[1][1] << endl; } int main() { make_it_fast; int TEST_CASES = 1; // cin>>TEST_CASES; while (TEST_CASES--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define make_it_fast \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define mp make_pair #define pb push_back #define all(x) (x).begin(), (x).end() #define ll long long #define ld long double #define endl "\n" #define ff first #define ss second void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cerr << x; } void __print(double x) { cerr << x; } void __print(long double x) { cerr << x; } void __print(char x) { cerr << '\'' << x << '\''; } void __print(const char *x) { cerr << '\"' << x << '\"'; } void __print(const string &x) { cerr << '\"' << x << '\"'; } void __print(bool x) { cerr << (x ? "true" : "false"); } template <typename T, typename V> void __print(const pair<T, V> &x) { cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}'; } template <typename T> void __print(const T &x) { int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}"; } void _print() { cerr << "]\n"; } template <typename T, typename... V> void _print(T t, V... v) { __print(t); if (sizeof...(v)) cerr << ", "; _print(v...); } #ifndef ONLINE_JUDGE #define debug(x...) \ cerr << "[" << #x << "] = ["; \ _print(x) #else #define debug(x...) 20 #endif ll power(ll a, ll b, ll m = 1e9 + 7) { a %= m; if (b == 1) return a; if (b == 0) return 1; ll ret = power(a, b / 2); ret = (ret % m * ret % m) % m; if (b & 1) ret = (ret % m * a % m) % m; return ret; } ll lcm(ll a, ll b) { return (a * b) / (__gcd(a, b)); } const ll N = 1e3 + 5, M = 1e9 + 7; ll dp[N][N]; char a[N][N]; void update(ll n, ll m) { if (n == 0 || m == 0) return; int i; for (i = n; i >= 1; i--) { if (a[i][m] == '#') continue; if (a[i + 1][m] != '#') dp[i][m] += dp[i + 1][m]; if (a[i][m + 1] != '#') dp[i][m] += dp[i][m + 1]; dp[i][m] %= M; } for (i = m - 1; i >= 1; i--) { if (a[n][i] == '#') continue; if (a[n][i + 1] != '#') dp[n][i] += dp[n][i + 1]; if (a[n + 1][i] != '#') dp[n][i] += dp[n + 1][i]; dp[n][i] %= M; } update(n - 1, m - 1); } void solve() { ll n, m, i, j; cin >> n >> m; for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) { cin >> a[i][j]; } } memset(dp, 0, sizeof(dp)); dp[n][m] = 1; for (i = n - 1; i >= 1; i--) { if (a[i][m] != '#') dp[i][m] = dp[i + 1][m]; } for (i = m - 1; i >= 1; i--) { if (a[n][i] != '#') dp[n][i] = dp[n][i + 1]; } update(n - 1, m - 1); // for(i=1;i<=n;i++) // { // for(j=1;j<=m;j++) // cout<<dp[i][j]<<" "; // cout<<endl; // } cout << dp[1][1] << endl; } int main() { make_it_fast; int TEST_CASES = 1; // cin>>TEST_CASES; while (TEST_CASES--) { solve(); } return 0; }
replace
79
80
79
80
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define fi first #define se second #define pb push_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define loop(i, a, b) for (ll i = a; i < b; i++) #define initialize(array, size, value) \ for (ll i = 0; i < size; i++) \ array[i] = value #define couta(array, size) \ for (ll i = 0; i < size; i++) \ cout << array[i] << " " #define debug(x) cout << "x: " << x << endl #define dbug(x, y) \ cout << "x: " << x << " " \ << "y: " << y << endl #define inf (long long int)1e18 #define eps 0.000001 #define vl vector<ll> #define sl set<ll> #define pll pair<ll, ll> #define mll map<ll, ll> #define pq priority_queue<ll> #define mod 1000000007 #define MAXN 1000001 ll spf[MAXN]; ll gcd(ll a, ll b); ll palindrome(string s); ll modexp(ll a, ll b, ll m); void sieve(); ll ceil(ll a, ll b); vl getFactorization(ll x); void getZarr(string str, ll Z[]); vector<ll> prefix_function(string s); int main() { ios::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ll h, w; cin >> h >> w; char a[h + 1][w + 1]; for (ll i = 1; i <= h; i++) { for (ll j = 1; j <= w; j++) { cin >> a[i][j]; } } ll dp[h + 1][w + 1]; dp[1][1] = 1; for (ll i = 1; i <= h; i++) { for (ll j = 1; j <= w; j++) { if (a[i][j] == '#') dp[i][j] = 0; } } for (ll i = 2; i <= w; i++) { if (a[1][i] == '.') dp[1][i] = dp[1][i - 1]; } for (ll i = 2; i <= h; i++) { if (a[i][1] == '.') dp[i][1] = dp[i - 1][1]; } for (ll i = 2; i <= h; i++) { for (ll j = 2; j <= w; j++) { if (a[i][j] == '.') dp[i][j] = (dp[i - 1][j] % mod + dp[i][j - 1] % mod) % mod; } } cout << dp[h][w] % mod << endl; } ll gcd(ll a, ll b) { if (a == 0) return b; if (b == 0) return a; if (a == b) return a; if (a > b) return gcd(a % b, b); return gcd(a, b % a); } ll palindrome(string s) { ll l = 0; ll h = s.length() - 1; while (h > l) { if (s[l++] != s[h--]) { return 0; } } return 1; } ll modexp(ll a, ll b, ll m) { if (b == 0) return 1; ll temp = modexp(a, b / 2, m); temp = (temp * temp) % m; if (b & 1) return (temp * (a % m)) % m; // if b is odd a^b = a^(b/2)*a^(b/2)*a return temp; } void sieve() { spf[1] = 1; for (ll i = 2; i < MAXN; i++) spf[i] = i; for (ll i = 4; i < MAXN; i += 2) spf[i] = 2; for (ll i = 3; i * i < MAXN; i++) { if (spf[i] == i) { for (ll j = i * i; j < MAXN; j += i) if (spf[j] == j) spf[j] = i; } } } vl getFactorization(ll x) { vl ret; while (x != 1) { ret.push_back(spf[x]); x = x / spf[x]; } return ret; } ll ceil(ll a, ll b) { return a / b + (a % b != 0); } void getZarr(string str, ll Z[]) { ll n = str.length(); ll L, R, k; L = R = 0; for (ll i = 1; i < n; ++i) { if (i > R) { L = R = i; while (R < n && str[R - L] == str[R]) R++; Z[i] = R - L; R--; } else { k = i - L; if (Z[k] < R - i + 1) Z[i] = Z[k]; else { L = i; while (R < n && str[R - L] == str[R]) R++; Z[i] = R - L; R--; } } } } vector<ll> prefix_function(string s) { ll n = (ll)s.length(); vector<ll> pi(n); for (ll i = 1; i < n; i++) { ll j = pi[i - 1]; while (j > 0 && s[i] != s[j]) j = pi[j - 1]; if (s[i] == s[j]) j++; pi[i] = j; } return pi; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define fi first #define se second #define pb push_back #define mp make_pair #define lb lower_bound #define ub upper_bound #define loop(i, a, b) for (ll i = a; i < b; i++) #define initialize(array, size, value) \ for (ll i = 0; i < size; i++) \ array[i] = value #define couta(array, size) \ for (ll i = 0; i < size; i++) \ cout << array[i] << " " #define debug(x) cout << "x: " << x << endl #define dbug(x, y) \ cout << "x: " << x << " " \ << "y: " << y << endl #define inf (long long int)1e18 #define eps 0.000001 #define vl vector<ll> #define sl set<ll> #define pll pair<ll, ll> #define mll map<ll, ll> #define pq priority_queue<ll> #define mod 1000000007 #define MAXN 1000001 ll spf[MAXN]; ll gcd(ll a, ll b); ll palindrome(string s); ll modexp(ll a, ll b, ll m); void sieve(); ll ceil(ll a, ll b); vl getFactorization(ll x); void getZarr(string str, ll Z[]); vector<ll> prefix_function(string s); int main() { ios::sync_with_stdio(0); cin.tie(0); /*#ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif*/ ll h, w; cin >> h >> w; char a[h + 1][w + 1]; for (ll i = 1; i <= h; i++) { for (ll j = 1; j <= w; j++) { cin >> a[i][j]; } } ll dp[h + 1][w + 1]; dp[1][1] = 1; for (ll i = 1; i <= h; i++) { for (ll j = 1; j <= w; j++) { if (a[i][j] == '#') dp[i][j] = 0; } } for (ll i = 2; i <= w; i++) { if (a[1][i] == '.') dp[1][i] = dp[1][i - 1]; } for (ll i = 2; i <= h; i++) { if (a[i][1] == '.') dp[i][1] = dp[i - 1][1]; } for (ll i = 2; i <= h; i++) { for (ll j = 2; j <= w; j++) { if (a[i][j] == '.') dp[i][j] = (dp[i - 1][j] % mod + dp[i][j - 1] % mod) % mod; } } cout << dp[h][w] % mod << endl; } ll gcd(ll a, ll b) { if (a == 0) return b; if (b == 0) return a; if (a == b) return a; if (a > b) return gcd(a % b, b); return gcd(a, b % a); } ll palindrome(string s) { ll l = 0; ll h = s.length() - 1; while (h > l) { if (s[l++] != s[h--]) { return 0; } } return 1; } ll modexp(ll a, ll b, ll m) { if (b == 0) return 1; ll temp = modexp(a, b / 2, m); temp = (temp * temp) % m; if (b & 1) return (temp * (a % m)) % m; // if b is odd a^b = a^(b/2)*a^(b/2)*a return temp; } void sieve() { spf[1] = 1; for (ll i = 2; i < MAXN; i++) spf[i] = i; for (ll i = 4; i < MAXN; i += 2) spf[i] = 2; for (ll i = 3; i * i < MAXN; i++) { if (spf[i] == i) { for (ll j = i * i; j < MAXN; j += i) if (spf[j] == j) spf[j] = i; } } } vl getFactorization(ll x) { vl ret; while (x != 1) { ret.push_back(spf[x]); x = x / spf[x]; } return ret; } ll ceil(ll a, ll b) { return a / b + (a % b != 0); } void getZarr(string str, ll Z[]) { ll n = str.length(); ll L, R, k; L = R = 0; for (ll i = 1; i < n; ++i) { if (i > R) { L = R = i; while (R < n && str[R - L] == str[R]) R++; Z[i] = R - L; R--; } else { k = i - L; if (Z[k] < R - i + 1) Z[i] = Z[k]; else { L = i; while (R < n && str[R - L] == str[R]) R++; Z[i] = R - L; R--; } } } } vector<ll> prefix_function(string s) { ll n = (ll)s.length(); vector<ll> pi(n); for (ll i = 1; i < n; i++) { ll j = pi[i - 1]; while (j > 0 && s[i] != s[j]) j = pi[j - 1]; if (s[i] == s[j]) j++; pi[i] = j; } return pi; }
replace
44
48
44
48
-11
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int #define m 1000000007 int main() { ll i, j, a[10000][10000], dp[10000][10000] = {0}, h, w; char ch; cin >> h >> w; for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { cin >> ch; if (ch == '.') a[i][j] = 1; else a[i][j] = 0; } } dp[0][0] = 1; for (j = 1; j < w; j++) { if (a[0][j] == 1) dp[0][j] += dp[0][j - 1]; } for (i = 1; i < h; i++) { if (a[i][0] == 1) dp[i][0] += dp[i - 1][0]; } for (i = 1; i < h; i++) { for (j = 1; j < w; j++) { if (a[i][j - 1] == 1) dp[i][j] += dp[i][j - 1]; if (a[i - 1][j] == 1) dp[i][j] += dp[i - 1][j]; dp[i][j] %= m; } } cout << dp[h - 1][w - 1]; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define m 1000000007 int main() { ll i, j, a[1001][1001], dp[1001][1001] = {0}, h, w; char ch; cin >> h >> w; for (i = 0; i < h; i++) { for (j = 0; j < w; j++) { cin >> ch; if (ch == '.') a[i][j] = 1; else a[i][j] = 0; } } dp[0][0] = 1; for (j = 1; j < w; j++) { if (a[0][j] == 1) dp[0][j] += dp[0][j - 1]; } for (i = 1; i < h; i++) { if (a[i][0] == 1) dp[i][0] += dp[i - 1][0]; } for (i = 1; i < h; i++) { for (j = 1; j < w; j++) { if (a[i][j - 1] == 1) dp[i][j] += dp[i][j - 1]; if (a[i - 1][j] == 1) dp[i][j] += dp[i - 1][j]; dp[i][j] %= m; } } cout << dp[h - 1][w - 1]; }
replace
5
6
5
6
-11
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define int long long const int N = 1005; const int MOD = 1e9 + 7; int n, m; char a[N][N]; int cache[N][N]; int dp(int i, int j) { if (i > n || j > m) return 0; if (a[i][j] == '#') return 0; if (i == n && j == m) return 1; int &ans = cache[i][j]; if (ans != -1) return ans; ans = dp(i + 1, j) + dp(i, j + 1); ans %= MOD; return ans; } int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); memset(cache, -1, sizeof(cache)); cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j]; int ans = dp(1, 1); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define int long long const int N = 1005; const int MOD = 1e9 + 7; int n, m; char a[N][N]; int cache[N][N]; int dp(int i, int j) { if (i > n || j > m) return 0; if (a[i][j] == '#') return 0; if (i == n && j == m) return 1; int &ans = cache[i][j]; if (ans != -1) return ans; ans = dp(i + 1, j) + dp(i, j + 1); ans %= MOD; return ans; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); memset(cache, -1, sizeof(cache)); cin >> n >> m; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) cin >> a[i][j]; int ans = dp(1, 1); cout << ans; return 0; }
replace
28
32
28
29
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i < b; i++) #define rrep(i, a, b) for (int i = a; i >= b; i--) #define fore(i, a) for (auto &i : a) #define all(x) (x).begin(), (x).end() // #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ const int MOD = 1000000007; ll dp[1010][1010]; void _main() { int H, W; cin >> H >> W; vector<string> a(H); rep(i, 0, H) cin >> a[i]; dp[0][0] = 1; rep(i, 0, H) rep(j, 0, W) { if (a[i][j] == '#') continue; if (a[i][j + 1] == '.') dp[i][j + 1] = (dp[i][j + 1] + dp[i][j]) % MOD; if (a[i + 1][j] == '.') dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD; } cout << dp[H - 1][W - 1] << endl; }
#include <bits/stdc++.h> #define rep(i, a, b) for (int i = a; i < b; i++) #define rrep(i, a, b) for (int i = a; i >= b; i--) #define fore(i, a) for (auto &i : a) #define all(x) (x).begin(), (x).end() // #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ const int MOD = 1000000007; ll dp[1010][1010]; void _main() { int H, W; cin >> H >> W; vector<string> a(H); rep(i, 0, H) cin >> a[i]; dp[0][0] = 1; rep(i, 0, H) rep(j, 0, W) { if (a[i][j] == '#') continue; if (j + 1 < W) if (a[i][j + 1] == '.') dp[i][j + 1] = (dp[i][j + 1] + dp[i][j]) % MOD; if (i + 1 < H) if (a[i + 1][j] == '.') dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD; } cout << dp[H - 1][W - 1] << endl; }
replace
46
50
46
52
-11
p03167
C++
Runtime Error
// Grid 1 // dp conteset h #include <bits/stdc++.h> #define C continue; #define R return #define D double #define I insert #define ll long long #define ld long double #define ull unsigned long long #define ui unsigned int #define pb push_back #define pf push_front #define vi vector<int> #define vc vector<char> #define vs vector<string> #define vb vector<bool> #define vd vector<D> #define vll vector<ll> #define vull vector<ull> #define vld vector<ld> #define PQ priority_queue #define vvi vector<vector<int>> #define vvb vector<vector<bool>> #define vvc vector<vector<char>> #define vvll vector<vector<ll>> #define vvd vector<vector<D>> #define vvld vector<vector<ld>> #define all(v) (v).begin(), (v).end() #define allrev(v) (v).rbegin(), (v).rend() #define allcomp(v) v.begin(), v.end(), comp #define allrevcomp(v) v.rbegin(), v.rend(), comp #define pii pair<int, int> #define pll pair<ll, ll> #define pld pair<ld, ld> #define pDD pair<D, D> #define pipii pair<int, pii> #define pcpii pair<char, pii> #define vpld vector<pld> #define vpii vector<pii> #define vpll vector<pll> #define vpDD vector<pDD> #define vvpii vector<vector<pii>> #define vpipii vector<pipii> #define F first #define S second #define mp make_pair #define unm unordered_map #define unmii unm<int, int> #define unmll unm<ll, ll> #define unms unm<string, int> #define unmci unm<char, int> #define sortvia sort(a.begin(), a.end()); #define sortvib sort(b.begin(), b.end()); #define revsorta sort(a.begin(), a.end(), greater<int>()); #define revsortb sort(b.begin(), b.end(), greater<>()); #define loop(q, n) for (int i = q; i < n; i++) #define loop2(q, n) for (int j = 1; j < n; j++) #define test \ int t; \ cin >> t; \ while (t--) #define nextline "\n" #define tab "\t" #define space " " // vector<vector<int> > vec( n , vector<int> (m, 0)); // YES // NO // cout // true // false // yes // no const ll mod9 = 1e9 + 7; const ll maxsize = 2e9 + 1; // const ll mod =998244353; const ll mod2 = 1073741824; const ll INF = 1e18L + 5; const int two_pow_fiv = 200008; using namespace std; int n, m; vector<string> grid; ll dp[1001][1001]; bool allowed(int i, int j) { if (i >= n or j >= m) return false; else if (grid[i][j] == '#') return false; return true; } int dfs(int a, int b) { if (dp[a][b] > -1) return dp[a][b]; // if(a==n-1 and b=m-1)return dp[n-1][m-1]; // first we try with dp if not then we perform dp dp[a][b] = (dfs(a + 1, b) % mod9 + dfs(a, b + 1) % mod9) % mod9; return dp[a][b]; } int main() { ios::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif cin >> n >> m; grid.resize(n + 1); string inp; loop(0, n) { cin >> grid[i]; } for (int i = 0; i <= n + 1; i++) { for (int j = 0; j <= m + 1; j++) { if (!allowed(i, j)) dp[i][j] = 0; else dp[i][j] = -1; } } dp[n - 1][m - 1] = 1; cout << dfs(0, 0); return 0; }
// Grid 1 // dp conteset h #include <bits/stdc++.h> #define C continue; #define R return #define D double #define I insert #define ll long long #define ld long double #define ull unsigned long long #define ui unsigned int #define pb push_back #define pf push_front #define vi vector<int> #define vc vector<char> #define vs vector<string> #define vb vector<bool> #define vd vector<D> #define vll vector<ll> #define vull vector<ull> #define vld vector<ld> #define PQ priority_queue #define vvi vector<vector<int>> #define vvb vector<vector<bool>> #define vvc vector<vector<char>> #define vvll vector<vector<ll>> #define vvd vector<vector<D>> #define vvld vector<vector<ld>> #define all(v) (v).begin(), (v).end() #define allrev(v) (v).rbegin(), (v).rend() #define allcomp(v) v.begin(), v.end(), comp #define allrevcomp(v) v.rbegin(), v.rend(), comp #define pii pair<int, int> #define pll pair<ll, ll> #define pld pair<ld, ld> #define pDD pair<D, D> #define pipii pair<int, pii> #define pcpii pair<char, pii> #define vpld vector<pld> #define vpii vector<pii> #define vpll vector<pll> #define vpDD vector<pDD> #define vvpii vector<vector<pii>> #define vpipii vector<pipii> #define F first #define S second #define mp make_pair #define unm unordered_map #define unmii unm<int, int> #define unmll unm<ll, ll> #define unms unm<string, int> #define unmci unm<char, int> #define sortvia sort(a.begin(), a.end()); #define sortvib sort(b.begin(), b.end()); #define revsorta sort(a.begin(), a.end(), greater<int>()); #define revsortb sort(b.begin(), b.end(), greater<>()); #define loop(q, n) for (int i = q; i < n; i++) #define loop2(q, n) for (int j = 1; j < n; j++) #define test \ int t; \ cin >> t; \ while (t--) #define nextline "\n" #define tab "\t" #define space " " // vector<vector<int> > vec( n , vector<int> (m, 0)); // YES // NO // cout // true // false // yes // no const ll mod9 = 1e9 + 7; const ll maxsize = 2e9 + 1; // const ll mod =998244353; const ll mod2 = 1073741824; const ll INF = 1e18L + 5; const int two_pow_fiv = 200008; using namespace std; int n, m; vector<string> grid; ll dp[1005][1005]; bool allowed(int i, int j) { if (i >= n or j >= m) return false; else if (grid[i][j] == '#') return false; return true; } int dfs(int a, int b) { if (dp[a][b] > -1) return dp[a][b]; // if(a==n-1 and b=m-1)return dp[n-1][m-1]; // first we try with dp if not then we perform dp dp[a][b] = (dfs(a + 1, b) % mod9 + dfs(a, b + 1) % mod9) % mod9; return dp[a][b]; } int main() { ios::sync_with_stdio(0); cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif cin >> n >> m; grid.resize(n + 1); string inp; loop(0, n) { cin >> grid[i]; } for (int i = 0; i <= n + 1; i++) { for (int j = 0; j <= m + 1; j++) { if (!allowed(i, j)) dp[i][j] = 0; else dp[i][j] = -1; } } dp[n - 1][m - 1] = 1; cout << dfs(0, 0); return 0; }
replace
97
98
97
98
-11
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #include <algorithm> #define str(a) to_string(a) #define int long long #define pb push_back #define mp make_pair #define SORT(c) sort(c.begin(), c.end()) #define max_heap priority_queue<int> #define min_heap priority_queue<int, vector<int>, greater<int>> #define mod 1000000007 #define setbits(x) __builtin_popcount(x) #define ps(x, y) fixed << setprecision(y) << x #define start(t) \ int x; \ cin >> x; \ while (x--) #define inf LLONG_MAX #define sync \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define endl "\n" #define N 1000001 int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int h, w; cin >> h >> w; vector<vector<char>> grid(h, vector<char>(w)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) cin >> grid[i][j]; } int dp[h][w]; // dp[i][j] means number of paths from i,j to h,w dp[h - 1][w - 1] = 1; // an empty path. for (int i = h - 2; i >= 0; i--) { if (grid[i][w - 1] == '#') dp[i][w - 1] = 0; else dp[i][w - 1] = dp[i + 1][w - 1]; } for (int i = w - 2; i >= 0; i--) { if (grid[h - 1][i] == '#') dp[h - 1][i] = 0; else dp[h - 1][i] = dp[h - 1][i + 1]; } for (int i = h - 2; i >= 0; i--) { for (int j = w - 2; j >= 0; j--) { if (grid[i][j] == '#') dp[i][j] = 0; else { dp[i][j] = (dp[i + 1][j] + dp[i][j + 1]) % 1000000007; } } } cout << dp[0][0] << endl; }
#include <bits/stdc++.h> using namespace std; #include <algorithm> #define str(a) to_string(a) #define int long long #define pb push_back #define mp make_pair #define SORT(c) sort(c.begin(), c.end()) #define max_heap priority_queue<int> #define min_heap priority_queue<int, vector<int>, greater<int>> #define mod 1000000007 #define setbits(x) __builtin_popcount(x) #define ps(x, y) fixed << setprecision(y) << x #define start(t) \ int x; \ cin >> x; \ while (x--) #define inf LLONG_MAX #define sync \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) #define endl "\n" #define N 1000001 int32_t main() { // ios_base::sync_with_stdio(0); // cin.tie(0); // cout.tie(0); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif int h, w; cin >> h >> w; vector<vector<char>> grid(h, vector<char>(w)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) cin >> grid[i][j]; } int dp[h][w]; // dp[i][j] means number of paths from i,j to h,w dp[h - 1][w - 1] = 1; // an empty path. for (int i = h - 2; i >= 0; i--) { if (grid[i][w - 1] == '#') dp[i][w - 1] = 0; else dp[i][w - 1] = dp[i + 1][w - 1]; } for (int i = w - 2; i >= 0; i--) { if (grid[h - 1][i] == '#') dp[h - 1][i] = 0; else dp[h - 1][i] = dp[h - 1][i + 1]; } for (int i = h - 2; i >= 0; i--) { for (int j = w - 2; j >= 0; j--) { if (grid[i][j] == '#') dp[i][j] = 0; else { dp[i][j] = (dp[i + 1][j] + dp[i][j + 1]) % 1000000007; } } } cout << dp[0][0] << endl; }
replace
27
34
27
34
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p03167
C++
Time Limit Exceeded
#include <algorithm> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <unordered_map> #include <vector> #define int long long #define pi pair<int, int> #define endl "\n" using namespace std; const int inf = 1e15; const int size = 1e3 + 5; const int mod = 1e9 + 7; int dp[size][size]; char a[size][size]; int add(int b, int c) { if (b + c >= mod) return b + c - mod; else return b + c; } int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int h, w; cin >> h >> w; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { cin >> a[i][j]; } } dp[1][0] = 1; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { if (a[i][j] != '#') dp[i][j] = add(dp[i - 1][j], dp[i][j - 1]); // cout<<dp[i][j]<<" "; } // cout<<endl; } cout << dp[h][w] << endl; return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <unordered_map> #include <vector> #define int long long #define pi pair<int, int> #define endl "\n" using namespace std; const int inf = 1e15; const int size = 1e3 + 5; const int mod = 1e9 + 7; int dp[size][size]; char a[size][size]; int add(int b, int c) { if (b + c >= mod) return b + c - mod; else return b + c; } int32_t main() { /* #ifndef ONLINE_JUDGE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif*/ int h, w; cin >> h >> w; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { cin >> a[i][j]; } } dp[1][0] = 1; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { if (a[i][j] != '#') dp[i][j] = add(dp[i - 1][j], dp[i][j - 1]); // cout<<dp[i][j]<<" "; } // cout<<endl; } cout << dp[h][w] << endl; return 0; }
replace
28
32
28
32
TLE
p03167
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define ff first #define ss second #define ll long long #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x, y) fixed << setprecision(y) << x #define mk(arr, n, type) type *arr = new type[n]; #define w(x) \ int x; \ cin >> x; \ while (x--) // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; void sb() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int main() { sb(); int h, w; cin >> h >> w; vector<string> v; for (int i = 0; i < h; i++) { string s; cin >> s; v.push_back(s); } vector<vector<int>> dp(h, vector<int>(w, 0)); dp[0][0] = (v[0][0] == '.'); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (v[i][j] == '.') { if (i > 0) dp[i][j] = (dp[i - 1][j] % mod + dp[i][j] % mod) % mod; if (j > 0) dp[i][j] = (dp[i][j - 1] % mod + dp[i][j] % mod) % mod; } // cout<<dp[i][j]<<" "; } // cout<<endl; } cout << dp[h - 1][w - 1]; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #define ff first #define ss second #define ll long long #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define setbits(x) __builtin_popcountll(x) #define zrobits(x) __builtin_ctzll(x) #define mod 1000000007 #define inf 1e18 #define ps(x, y) fixed << setprecision(y) << x #define mk(arr, n, type) type *arr = new type[n]; #define w(x) \ int x; \ cin >> x; \ while (x--) // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; void sb() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int main() { // sb(); int h, w; cin >> h >> w; vector<string> v; for (int i = 0; i < h; i++) { string s; cin >> s; v.push_back(s); } vector<vector<int>> dp(h, vector<int>(w, 0)); dp[0][0] = (v[0][0] == '.'); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (v[i][j] == '.') { if (i > 0) dp[i][j] = (dp[i - 1][j] % mod + dp[i][j] % mod) % mod; if (j > 0) dp[i][j] = (dp[i][j - 1] % mod + dp[i][j] % mod) % mod; } // cout<<dp[i][j]<<" "; } // cout<<endl; } cout << dp[h - 1][w - 1]; }
replace
42
43
42
43
-6
terminate called after throwing an instance of 'std::length_error' what(): cannot create std::vector larger than max_size()
p03167
C++
Runtime Error
/* @author : srinathbalaji_99 */ #include <bits/stdc++.h> #define PB push_back #define MP make_pair #define endl '\n' #define MAX LLONG_MAX #define MIN LLONG_MIN #define rep(i, a, b, inc) for (long long i = a; i < b; i += inc) #define REP(i, n) rep(i, 0, n, 1) #define MEM(a, b) memset(a, (b), sizeof(a)) #define PI 3.1415926535897932384626433832795 #define MOD 1000000007 #define PLL pair<long long, long long> #define VL vector<long long> #define VS vector<string> #define VLL vector<PLL> #define VVL vector<VL> #define MPLL map<long long, long long> #define UMPLL unordered_map<long long, long long> #define SETL set<long long> #define MSETL multiset<long long> #define GCD(a, b) __gcd(a, b) #define LCM(a, b) (a * b) / GCD(a, b) #define ff first #define ss second #define pall(a) \ REP(i, sizeof(a) / sizeof(a[0])) cout << a[i] << " "; \ cout << endl; #define pvall(v) \ REP(i, v.size()) cout << v[i] << " "; \ cout << endl; #define gall(a, n) REP(i, n) cin >> a[i]; #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() typedef unsigned long long ULL; typedef long long LL; typedef long double LD; using namespace std; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); } LL dp[1001][1001]; int main() { fast(); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif LL t, n, i, j, k, x, y, c, m; cin >> n >> m; LL a[n][m]; char ch; REP(i, n) { REP(j, m) { cin >> ch; if (ch == '.') { a[i][j] = 1; } else { a[i][j] = 0; } } } REP(i, n) { REP(j, m) { if (i == 0 && j == 0) { dp[i][j] = 1; continue; } if (i == 0) { if (a[i][j] == 0) { dp[i][j] = 0; } else { dp[i][j] = dp[i][j - 1]; } continue; } if (j == 0) { if (a[i][j] == 0) { dp[i][j] = 0; } else { dp[i][j] = dp[i - 1][j]; } continue; } if (a[i][j] == 0) { dp[i][j] = 0; } else { dp[i][j] = ((dp[i - 1][j] % MOD) + (dp[i][j - 1] % MOD)) % MOD; } } } // REP(i, n){ // REP(j, m){ // cout << dp[i][j] << " "; // } // cout << endl; // } cout << dp[n - 1][m - 1]; }
/* @author : srinathbalaji_99 */ #include <bits/stdc++.h> #define PB push_back #define MP make_pair #define endl '\n' #define MAX LLONG_MAX #define MIN LLONG_MIN #define rep(i, a, b, inc) for (long long i = a; i < b; i += inc) #define REP(i, n) rep(i, 0, n, 1) #define MEM(a, b) memset(a, (b), sizeof(a)) #define PI 3.1415926535897932384626433832795 #define MOD 1000000007 #define PLL pair<long long, long long> #define VL vector<long long> #define VS vector<string> #define VLL vector<PLL> #define VVL vector<VL> #define MPLL map<long long, long long> #define UMPLL unordered_map<long long, long long> #define SETL set<long long> #define MSETL multiset<long long> #define GCD(a, b) __gcd(a, b) #define LCM(a, b) (a * b) / GCD(a, b) #define ff first #define ss second #define pall(a) \ REP(i, sizeof(a) / sizeof(a[0])) cout << a[i] << " "; \ cout << endl; #define pvall(v) \ REP(i, v.size()) cout << v[i] << " "; \ cout << endl; #define gall(a, n) REP(i, n) cin >> a[i]; #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() typedef unsigned long long ULL; typedef long long LL; typedef long double LD; using namespace std; void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); } LL dp[1001][1001]; int main() { fast(); LL t, n, i, j, k, x, y, c, m; cin >> n >> m; LL a[n][m]; char ch; REP(i, n) { REP(j, m) { cin >> ch; if (ch == '.') { a[i][j] = 1; } else { a[i][j] = 0; } } } REP(i, n) { REP(j, m) { if (i == 0 && j == 0) { dp[i][j] = 1; continue; } if (i == 0) { if (a[i][j] == 0) { dp[i][j] = 0; } else { dp[i][j] = dp[i][j - 1]; } continue; } if (j == 0) { if (a[i][j] == 0) { dp[i][j] = 0; } else { dp[i][j] = dp[i - 1][j]; } continue; } if (a[i][j] == 0) { dp[i][j] = 0; } else { dp[i][j] = ((dp[i - 1][j] % MOD) + (dp[i][j - 1] % MOD)) % MOD; } } } // REP(i, n){ // REP(j, m){ // cout << dp[i][j] << " "; // } // cout << endl; // } cout << dp[n - 1][m - 1]; }
delete
55
60
55
55
-11
p03167
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define fast \ ios::sync_with_stdio(false); \ cin.tie(0); using namespace std; const int mod = (int)1e9 + 7; ll dp[1000][1000]; int main() { fast int h, w; cin >> h >> w; vector<string> s(h + 1); for (int i = 1; i <= h; i++) cin >> s[i]; dp[1][1] = 1; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { if (s[i][j - 1] == '#' || (i == 1 && j == 1)) continue; dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod; } } cout << dp[h][w]; return 0; }
#include <bits/stdc++.h> #define ll long long #define fast \ ios::sync_with_stdio(false); \ cin.tie(0); using namespace std; const int mod = (int)1e9 + 7; ll dp[1005][1005]; int main() { fast int h, w; cin >> h >> w; vector<string> s(h + 1); for (int i = 1; i <= h; i++) cin >> s[i]; dp[1][1] = 1; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { if (s[i][j - 1] == '#' || (i == 1 && j == 1)) continue; dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod; } } cout << dp[h][w]; return 0; }
replace
7
8
7
8
0
p03167
C++
Runtime Error
#pragma GCC optimize "trapv" #include <bits/stdc++.h> #define faster \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) using namespace std; int MOD = 1e9 + 7; char ar[1001][1001]; int a[1001][1001] = {-1}; long long find(int i, int j, int h, int w) { if (a[i][j] != -1) return a[i][j]; if (ar[i][j] == '#') a[i][j] = 0; else if (i == h && j == w) a[i][j] = 1; else if (i == h) a[i][j] = find(i, j + 1, h, w); else if (j == w) a[i][j] = find(i + 1, j, h, w); else a[i][j] = (find(i + 1, j, h, w) + find(i, j + 1, h, w)) % MOD; return a[i][j]; } signed main() { faster; #ifndef ONLINE_JUDGE freopen("ip.txt", "r", stdin); freopen("op.txt", "w", stdout); #endif // int t;cin>>t; // while(t--) { int h, w; cin >> h >> w; for (int i = 1; i <= h; i++) for (int j = 1; j <= w; j++) cin >> ar[i][j], a[i][j] = -1; cout << find(1, 1, h, w) << endl; // cout<<a[4][5]<<endl; } }
#pragma GCC optimize "trapv" #include <bits/stdc++.h> #define faster \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) using namespace std; int MOD = 1e9 + 7; char ar[1001][1001]; int a[1001][1001] = {-1}; long long find(int i, int j, int h, int w) { if (a[i][j] != -1) return a[i][j]; if (ar[i][j] == '#') a[i][j] = 0; else if (i == h && j == w) a[i][j] = 1; else if (i == h) a[i][j] = find(i, j + 1, h, w); else if (j == w) a[i][j] = find(i + 1, j, h, w); else a[i][j] = (find(i + 1, j, h, w) + find(i, j + 1, h, w)) % MOD; return a[i][j]; } signed main() { faster; // #ifndef ONLINE_JUDGE // freopen("ip.txt", "r", stdin); // freopen("op.txt", "w", stdout); // #endif // int t;cin>>t; // while(t--) { int h, w; cin >> h >> w; for (int i = 1; i <= h; i++) for (int j = 1; j <= w; j++) cin >> ar[i][j], a[i][j] = -1; cout << find(1, 1, h, w) << endl; // cout<<a[4][5]<<endl; } }
replace
28
32
28
32
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> #include <climits> using namespace std; #define debug(x, y) \ cout << (#x) << " " << (#y) << " is " << (x) << " " << (y) << endl #define watch(x) cout << (#x) << " is " << (x) << endl #define fast ios_base::sync_with_stdio(false) #define fie(i, a, b) for (i = a; i < b; i++) #define MOD 1000000007 #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define ll long long #define lld long long int #define ALL(x) (x).begin(), (x).end() typedef vector<int> vi; typedef vector<vector<int>> vii; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<pair<int, int>> vpi; typedef long long LL; const lld INF = (1ll) << 56; const long long OO = 2e18; const double pi = 2 * acos(0.0); lld dp[2001][2001], n, m, c = 0; char a[1001][1001]; // TOP-DOWN lld gridOne(lld i, lld j) { lld count1 = 0, count2 = 0; if (i > n - 1 || j > m - 1) return dp[i][j] = 0; if (i == n - 1 && j == m - 1) { return dp[i][j] = (count1 + count2 + 1) % MOD; } if (dp[i][j] != -1) return dp[i][j]; if (a[i + 1][j] == '.') count1 = max(count1, gridOne(i + 1, j)); if (a[i][j + 1] == '.') count2 = max(count2, gridOne(i, j + 1)); return dp[i][j] = (count1 + count2) % MOD; } int main() { fast; cin.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif lld i, j; cin >> n >> m; memset(dp, -1, sizeof(dp)); for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { cin >> a[i][j]; } } cout << gridOne(0, 0) << endl; }
#include <bits/stdc++.h> #include <climits> using namespace std; #define debug(x, y) \ cout << (#x) << " " << (#y) << " is " << (x) << " " << (y) << endl #define watch(x) cout << (#x) << " is " << (x) << endl #define fast ios_base::sync_with_stdio(false) #define fie(i, a, b) for (i = a; i < b; i++) #define MOD 1000000007 #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define ll long long #define lld long long int #define ALL(x) (x).begin(), (x).end() typedef vector<int> vi; typedef vector<vector<int>> vii; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<pair<int, int>> vpi; typedef long long LL; const lld INF = (1ll) << 56; const long long OO = 2e18; const double pi = 2 * acos(0.0); lld dp[2001][2001], n, m, c = 0; char a[1001][1001]; // TOP-DOWN lld gridOne(lld i, lld j) { lld count1 = 0, count2 = 0; if (i > n - 1 || j > m - 1) return dp[i][j] = 0; if (i == n - 1 && j == m - 1) { return dp[i][j] = (count1 + count2 + 1) % MOD; } if (dp[i][j] != -1) return dp[i][j]; if (a[i + 1][j] == '.') count1 = max(count1, gridOne(i + 1, j)); if (a[i][j + 1] == '.') count2 = max(count2, gridOne(i, j + 1)); return dp[i][j] = (count1 + count2) % MOD; } int main() { fast; cin.tie(0); /*#ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif*/ lld i, j; cin >> n >> m; memset(dp, -1, sizeof(dp)); for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { cin >> a[i][j]; } } cout << gridOne(0, 0) << endl; }
replace
54
58
54
58
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> #include <ctype.h> #define pb push_back #define fst first #define sec second #define For(i, a, b) for (int i = a; i < b; i++) #define ll long long int #define ull unsigned long long int #define mod 1000000007 #define fo(i, n) for (ll i = 0; i < n; i++) #define endl "\n" #define rev(i, n) for (ll i = n - 1; i >= 0; i--) #define fo1(i, n) for (ll i = 1; i <= n; i++) #define boolsize 1000001 #define pi pair<ll, ll> #define vi vector<ll> #define vii vector<pi> using namespace std; template <typename T> void showvector(vector<T> v) { for (T x : v) cout << x << " "; cout << endl; } template <typename T> void showvector1(vector<T> v) { ll n = v.size(); fo1(i, n - 1) cout << v[i] << endl; } template <typename T> void showset(set<T> s) { for (T x : s) cout << x << " "; cout << endl; } template <class T> void showvectorpair(vector<T> v) { for (auto it = v.begin(); it != v.end(); it++) cout << it->first << " " << it->second << endl; cout << endl; } template <typename T, typename P> void showmap(map<T, P> m) { for (auto it = m.begin(); it != m.end(); it++) cout << it->first << " " << it->second << endl; cout << endl; } template <typename T> bool comp(T a, T b) { return (a > b); } template <class T> bool comppair(T a, T b) { if (a.first == b.first) return (a.second > b.second); return (a.first > b.first); } bool sameparity(ll a, ll b) { return (a % 2 == b % 2); } bool difparity(ll a, ll b) { return !(a % 2 == b % 2); } bool isprime(ll x) { if (x <= 1) return false; for (ll i = 2; i <= sqrt(x); i++) { if (x % i == 0) return false; } return true; } bool iseven(ll x) { return !(x % 2); } bool isodd(ll x) { return (x % 2); } /// check for test case before submitting void vfun() { ll n, k; cin >> n; vector<ll> v(n); fo(i, n) cin >> v[i]; } const ll N = 100; ll t[N][N]; char mat[N][N]; ll grid(ll i, ll j, ll n, ll m) { if (mat[i][j] == '#' || i > n || j > m) return 0; if (i == n && j == m) return 1; if (t[i][j] != -1) return t[i][j]; t[i][j] = (grid(i + 1, j, n, m) + grid(i, j + 1, n, m)); return (t[i][j] % mod); } int main() { #ifndef ONLINE_JUDGE freopen("inputh.txt", "r", stdin); freopen("outputh.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); /// cant use scanf, printf cin.tie(0); cout.tie( 0); /// no longer auto flush cout before each cin, remove for interactive // cout << fixed << setprecision(11); /// no scientific output ll test = 1; // cin>>test; while (test--) { memset(t, -1, sizeof(t)); ll n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> mat[i][j]; } } cout << grid(1, 1, n, m); // if(vfun()) // cout<<"YES\n"; // else // cout<<"NO\n"; } } /// before sub /// check for value of zero and single input in array /// loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking /// inputs /// check whether test cases are given or not
#include <bits/stdc++.h> #include <ctype.h> #define pb push_back #define fst first #define sec second #define For(i, a, b) for (int i = a; i < b; i++) #define ll long long int #define ull unsigned long long int #define mod 1000000007 #define fo(i, n) for (ll i = 0; i < n; i++) #define endl "\n" #define rev(i, n) for (ll i = n - 1; i >= 0; i--) #define fo1(i, n) for (ll i = 1; i <= n; i++) #define boolsize 1000001 #define pi pair<ll, ll> #define vi vector<ll> #define vii vector<pi> using namespace std; template <typename T> void showvector(vector<T> v) { for (T x : v) cout << x << " "; cout << endl; } template <typename T> void showvector1(vector<T> v) { ll n = v.size(); fo1(i, n - 1) cout << v[i] << endl; } template <typename T> void showset(set<T> s) { for (T x : s) cout << x << " "; cout << endl; } template <class T> void showvectorpair(vector<T> v) { for (auto it = v.begin(); it != v.end(); it++) cout << it->first << " " << it->second << endl; cout << endl; } template <typename T, typename P> void showmap(map<T, P> m) { for (auto it = m.begin(); it != m.end(); it++) cout << it->first << " " << it->second << endl; cout << endl; } template <typename T> bool comp(T a, T b) { return (a > b); } template <class T> bool comppair(T a, T b) { if (a.first == b.first) return (a.second > b.second); return (a.first > b.first); } bool sameparity(ll a, ll b) { return (a % 2 == b % 2); } bool difparity(ll a, ll b) { return !(a % 2 == b % 2); } bool isprime(ll x) { if (x <= 1) return false; for (ll i = 2; i <= sqrt(x); i++) { if (x % i == 0) return false; } return true; } bool iseven(ll x) { return !(x % 2); } bool isodd(ll x) { return (x % 2); } /// check for test case before submitting void vfun() { ll n, k; cin >> n; vector<ll> v(n); fo(i, n) cin >> v[i]; } const ll N = 1005; ll t[N][N]; char mat[N][N]; ll grid(ll i, ll j, ll n, ll m) { if (mat[i][j] == '#' || i > n || j > m) return 0; if (i == n && j == m) return 1; if (t[i][j] != -1) return t[i][j]; t[i][j] = (grid(i + 1, j, n, m) + grid(i, j + 1, n, m)); return (t[i][j] % mod); } int main() { #ifndef ONLINE_JUDGE freopen("inputh.txt", "r", stdin); freopen("outputh.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); /// cant use scanf, printf cin.tie(0); cout.tie( 0); /// no longer auto flush cout before each cin, remove for interactive // cout << fixed << setprecision(11); /// no scientific output ll test = 1; // cin>>test; while (test--) { memset(t, -1, sizeof(t)); ll n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> mat[i][j]; } } cout << grid(1, 1, n, m); // if(vfun()) // cout<<"YES\n"; // else // cout<<"NO\n"; } } /// before sub /// check for value of zero and single input in array /// loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking /// inputs /// check whether test cases are given or not
replace
69
70
69
70
TLE
p03167
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; const int INF = 1145141919; const long long INFL = 1LL << 60; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int H, W; int a[1100][1100]; long long int memo[1100][1100]; int rec(int x, int y) { if (x == 0 || x > W || y == 0 || y > H || a[y][x]) { return 0; } if (memo[y][x] != 0) { return memo[y][x]; } // cout << x << " " << y << endl; if (x == W && y == H) { return 1; } int ans = 0; ans = rec(x + 1, y) + rec(x, y + 1); return memo[y][x] = ans % 1000000007; } int main() { cin >> H >> W; char in; for (int i = 1; i <= H; ++i) { for (int j = 1; j <= W; ++j) { cin >> in; a[i][j] = (in == '.' ? 0 : 1); } } cout << rec(1, 1) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 1145141919; const long long INFL = 1LL << 60; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int H, W; int a[1100][1100]; long long int memo[1100][1100]; int rec(int x, int y) { if (x == 0 || x > W || y == 0 || y > H || a[y][x]) { return 0; } if (memo[y][x] != 0) { return memo[y][x]; } // cout << x << " " << y << endl; if (x == W && y == H) { return 1; } int ans = 0; ans = rec(x + 1, y) + rec(x, y + 1); return memo[y][x] = ans % 1000000007; } int main() { cin >> H >> W; char in; for (int i = 1; i <= H; ++i) { for (int j = 1; j <= W; ++j) { cin >> in; a[i][j] = (in == '.' ? 0 : 1); } } memo[H][W] = 1; for (int i = H; i > 0; --i) { for (int j = W; j > 0; --j) { if (!a[i][j]) { memo[i][j] += memo[i + 1][j] + memo[i][j + 1]; memo[i][j] %= 1000000007; } } } cout << memo[1][1] << endl; return 0; }
replace
51
52
51
61
TLE
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int maxn = 110, mod = 1000000007; int dp[maxn][maxn]; char a[maxn][maxn]; int main() { // freopen("demo.in", "r", stdin); // freopen("demo.out", "w", stdout); int h, w; scanf("%d%d", &h, &w); for (int i = 0; i < h; i++) { scanf("%s", a[i]); } dp[0][0] = 1; for (int i = 1; i < w; i++) if (a[0][i] == '.') dp[0][i] = dp[0][i - 1]; for (int i = 1; i < h; i++) if (a[i][0] == '.') dp[i][0] = dp[i - 1][0]; for (int i = 1; i < h; i++) for (int j = 1; j < w; j++) if (a[i][j] == '.') { dp[i][j] = (dp[i - 1][j] % mod + dp[i][j - 1] % mod) % mod; } else { dp[i][j] = 0; } // for (int i = 0; i < h; i++) { // for (int j = 0; j < w; j++) // printf("%d ", dp[i][j]); // printf("\n"); // } printf("%d\n", dp[h - 1][w - 1]); return 0; }
#include <bits/stdc++.h> using namespace std; const int maxn = 1010, mod = 1000000007; int dp[maxn][maxn]; char a[maxn][maxn]; int main() { // freopen("demo.in", "r", stdin); // freopen("demo.out", "w", stdout); int h, w; scanf("%d%d", &h, &w); for (int i = 0; i < h; i++) { scanf("%s", a[i]); } dp[0][0] = 1; for (int i = 1; i < w; i++) if (a[0][i] == '.') dp[0][i] = dp[0][i - 1]; for (int i = 1; i < h; i++) if (a[i][0] == '.') dp[i][0] = dp[i - 1][0]; for (int i = 1; i < h; i++) for (int j = 1; j < w; j++) if (a[i][j] == '.') { dp[i][j] = (dp[i - 1][j] % mod + dp[i][j - 1] % mod) % mod; } else { dp[i][j] = 0; } // for (int i = 0; i < h; i++) { // for (int j = 0; j < w; j++) // printf("%d ", dp[i][j]); // printf("\n"); // } printf("%d\n", dp[h - 1][w - 1]); return 0; }
replace
3
4
3
4
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> #define int long long int #define mod 1000000007 #define inf 1e18 #define fo(i, y, n, inc) for (int i = y; i < n + y; i += inc) #define cin(t) \ int t; \ cin >> t #define w(t) while (t--) #define nl cout << endl; #define pb push_back #define ft(i) (i & (-1 * i)) #define arrIn(arr, size) \ for (int i = 0; i < size; i++) { \ cin >> arr[i]; \ } #define arrOut(arr, size, seperater) \ for (int i = 0; i < size; i++) { \ cout << arr[i] << seperater; \ } using namespace std; int max(int a, int b) { if (a > b) return a; return b; } int min(int a, int b) { if (a < b) return a; return b; } void fastIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int h, w; char grid[1005][1005]; int solve() { int dp[h][w]; fo(i, 0, h, 1) { fo(j, 0, w, 1) { dp[i][j] = 0; } } fo(i, 0, w, 1) { if (grid[0][i] == '#') break; dp[0][i] = 1; } fo(i, 0, h, 1) { if (grid[i][0] == '#') break; dp[i][0] = 1; } fo(i, 1, h - 1, 1) { fo(j, 1, w - 1, 1) { if (grid[i][j] == '#') continue; dp[i][j] = dp[i - 1][j] + dp[i][j - 1]; dp[i][j] %= mod; } } return dp[h - 1][w - 1] % mod; } int32_t main() { fastIO(); cin >> h >> w; fo(i, 0, h, 1) { fo(j, 0, w, 1) { cin >> grid[i][j]; } } cout << solve(); nl; return 0; } // cout << "Case #" << i << ": " << answer << endl;
#include <bits/stdc++.h> #define int long long int #define mod 1000000007 #define inf 1e18 #define fo(i, y, n, inc) for (int i = y; i < n + y; i += inc) #define cin(t) \ int t; \ cin >> t #define w(t) while (t--) #define nl cout << endl; #define pb push_back #define ft(i) (i & (-1 * i)) #define arrIn(arr, size) \ for (int i = 0; i < size; i++) { \ cin >> arr[i]; \ } #define arrOut(arr, size, seperater) \ for (int i = 0; i < size; i++) { \ cout << arr[i] << seperater; \ } using namespace std; int max(int a, int b) { if (a > b) return a; return b; } int min(int a, int b) { if (a < b) return a; return b; } void fastIO() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int h, w; char grid[1005][1005]; int solve() { int dp[h][w]; fo(i, 0, h, 1) { fo(j, 0, w, 1) { dp[i][j] = 0; } } fo(i, 0, w, 1) { if (grid[0][i] == '#') break; dp[0][i] = 1; } fo(i, 0, h, 1) { if (grid[i][0] == '#') break; dp[i][0] = 1; } fo(i, 1, h - 1, 1) { fo(j, 1, w - 1, 1) { if (grid[i][j] == '#') continue; dp[i][j] = dp[i - 1][j] + dp[i][j - 1]; dp[i][j] %= mod; } } return dp[h - 1][w - 1] % mod; } int32_t main() { cin >> h >> w; fo(i, 0, h, 1) { fo(j, 0, w, 1) { cin >> grid[i][j]; } } cout << solve(); nl; return 0; } // cout << "Case #" << i << ": " << answer << endl;
delete
79
80
79
79
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; int main() { int h, w; cin >> h >> w; string arr[h]; for (int i = 0; i < h; i++) cin >> arr[i]; long long res[h][w]; res[0][0] = 1LL; for (int i = 0; i < w; i++) { for (int j = 0; j < h; j++) { if (arr[i][j] == '#') { res[i][j] = 0; continue; } if (i == 0 && j == 0) continue; long long a = 0, b = 0; if (j >= 1) a = res[i][j - 1]; if (i >= 1) b = res[i - 1][j]; res[i][j] = (a + b) % MOD; } } cout << res[h - 1][w - 1]; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; int main() { int h, w; cin >> h >> w; string arr[h]; for (int i = 0; i < h; i++) cin >> arr[i]; long long res[h][w]; res[0][0] = 1LL; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (arr[i][j] == '#') { res[i][j] = 0; continue; } if (i == 0 && j == 0) continue; long long a = 0, b = 0; if (j >= 1) a = res[i][j - 1]; if (i >= 1) b = res[i - 1][j]; res[i][j] = (a + b) % MOD; } } cout << res[h - 1][w - 1]; }
replace
14
16
14
16
-11
p03167
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; using P = pair<ll, ll>; #define all(x) (x).begin(), (x).end() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); // ll gcd(ll a, ll b){return b?gcd(b,a%b):a;} // ll lcm(ll x, ll y) {return x / gcd(x, y) * y;} const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const ll mod = 1e9 + 7; const ll inf = 1LL << 60; const long double pi = 3.14159265358979323846; // ****************************************CODE***************************************// ll h, w; vector<string> a; ll dp[1100][1100]; void add(ll &a, ll b) { a += b; if (a >= mod) a -= mod; } int main() { cin >> h >> w; for (int i = 0; i < h; i++) cin >> a[i]; dp[0][0] = 1; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (i + 1 < h && a[i + 1][j] == '.') add(dp[i + 1][j], dp[i][j]); if (j + 1 < w && a[i][j + 1] == '.') add(dp[i][j + 1], dp[i][j]); } } cout << dp[h - 1][w - 1] << endl; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; using P = pair<ll, ll>; #define all(x) (x).begin(), (x).end() #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()); // ll gcd(ll a, ll b){return b?gcd(b,a%b):a;} // ll lcm(ll x, ll y) {return x / gcd(x, y) * y;} const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; const ll mod = 1e9 + 7; const ll inf = 1LL << 60; const long double pi = 3.14159265358979323846; // ****************************************CODE***************************************// ll h, w; vector<string> a; ll dp[1100][1100]; void add(ll &a, ll b) { a += b; if (a >= mod) a -= mod; } int main() { cin >> h >> w; a.resize(h); for (int i = 0; i < h; i++) cin >> a[i]; dp[0][0] = 1; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (i + 1 < h && a[i + 1][j] == '.') add(dp[i + 1][j], dp[i][j]); if (j + 1 < w && a[i][j + 1] == '.') add(dp[i][j + 1], dp[i][j]); } } cout << dp[h - 1][w - 1] << endl; }
insert
45
45
45
46
-11
p03167
C++
Runtime Error
// Vaidik Patel(India) // DA-IICT #include <bits/stdc++.h> using namespace std; //******************************************** #include <ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set, multimap, map etc. #include <ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update using namespace __gnu_pbds; // necessary for the GNU based Policy based data // structures. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //******************************************** typedef long long ll; typedef unsigned long long ull; typedef long double ld; int INF = (int)1e9; ll INFINF = (ll)1e18 + 10; const ld PI = 3.14159265358979323846; #define precision(x, d) cout << fixed << setprecision(d) << x #define minheap priority_queue<ll, vector<ll>, greater<ll>> #define maxheap priority_queue<ll, vector<ll>, less<ll>> #define FOR(i, a, b) for (ll i = a; i < b; i++) #define rFOR(i, a, b) for (ll i = a; i >= b; i--) #define deb1(x) cout << #x << " : " << x << endl; #define deb2(x, y) cout << #x << " : " << x << "\t" << #y << " : " << y << endl; #define deb3(x, y, z) \ cout << #x << " : " << x << "\t" << #y << " : " << y << "\t" << #z << " : " \ << z << endl; #define deb4(x, y, z, w) \ cout << #x << " : " << x << "\t" << #y << " : " << y << "\t" << #z << " : " \ << z << "\t" << #w << " : " << w << endl; #define deb5(a, b, c, d, e) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl; #define deb6(a, b, c, d, e, f) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl; #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define checkbit(n, b) ((n >> b) & 1) #define mkp make_pair #define ff first #define ss second #define FIO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define TIME \ cerr << "Time Elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << "\n"; #define lc 2 * idx #define rc 2 * idx + 1 ll powermodm(ll x, ll n, ll mod) { ll result = 1; while (n > 0) { if (n % 2 == 1) result = (result * x) % mod; x = (x * x) % mod; n = n / 2; } return result; } ll GCD(ll, ll); ll LCM(ll, ll); ll power(ll, ll); ll choose(ll, ll); int ones(ll); void extendedEuclid(ll, ll); ll MMI(ll, ll); void fastscan(int &); bool checkithbit(ll, ll); // ith bit is zero or not vector<ll> SegmentTree; void Build_Segment_Tree(vector<ll> &a, ll idx, ll l, ll r); ll sum(ll idx, ll sl, ll sr, ll l, ll r); void update(ll idx, ll sl, ll sr, ll value, ll id); vector<ll> prime; void findprime(void); ll phi(ll num); vector<int> isprime; void precomputeprime(int N); vector<int> prephi; void precomputephi(int N); int read(); typedef pair<int, int> pii; typedef pair<long long, long long> pll; typedef vector<ll> vll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<vector<ll>> vvll; typedef vector<pll> vpll; typedef vector<pii> vpii; #define pb push_back #define M 1000000007 ////////////////////////////////////////////////////////////////////////////// int main() { #ifndef ONLINE_JUDGE freopen("input1.txt", "r", stdin); freopen("output1.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll h, w; cin >> h >> w; vector<vector<bool>> a(h, vector<bool>(w)); FOR(i, 0, h) { FOR(j, 0, w) { char ch; cin >> ch; if (ch == '.') { a[i][j] = 0; } else { a[i][j] = 1; } } } vll dp(w); dp[0] = 1; FOR(j, 1, w) { dp[j] = (a[0][j] ? 0 : dp[j - 1]); } FOR(i, 1, h) { FOR(j, 0, w) { dp[j] = (a[i][j] ? 0 : dp[j]); dp[j] %= M; } FOR(j, 1, w) { dp[j] = (a[i][j] ? 0 : dp[j] + dp[j - 1]); dp[j] %= M; } } cout << dp[w - 1]; return 0; } ////////////////////////////////////////////////////////////////////////// // precomputephi() void precomputephi(int N) { prephi.resize(N); FOR(i, 0, N) { prephi[i] = i; } for (int i = 1; i < N; i++) { if (isprime[i]) { for (int j = i; j < N; j += i) { prephi[j] = prephi[j] - (prephi[j] / i); } } } } // precomputedprime() void precomputeprime(int N) { isprime.resize(N); isprime.assign(N, 1); isprime[0] = 0; isprime[1] = 0; for (int i = 2; i * i <= 500005; i++) { if (isprime[i]) { for (int j = i * i; j <= 500005; j += i) { isprime[j] = 0; } } } } //"""euler totient function""": counts the number of integers between 1 and n //inclusive, which are coprime to n. ll phi(ll num) // find using factorization in O(sqrt(N))..... { ll result = num; for (ll i = 2; i * i <= num; i++) { if (num % i == 0) { while (num % i == 0) { num /= i; } result -= (result / i); } } if (num > 1) { result -= (result / num); } return result; } void findprime(void) { int N = 1e6 + 5; vector<bool> isprime(N, 1); // up to 1e6+5 number for (int i = 2; i * i <= N; i++) { if (isprime[i]) { for (int j = i * i; j <= N; j += i) { if (isprime[j]) { isprime[j] = 0; } } } } for (int i = 2; i <= N; i++) { if (isprime[i]) { prime.pb(i); } } } bool checkithbit(ll a, ll i) { if (a & (1 << i)) { return true; } else { return false; } } ll GCD(ll a, ll b) { if (b == 0) return a; else return GCD(b, a % b); } ll LCM(ll a, ll b) { return (max(a, b) / GCD(a, b)) * min(a, b); } ll power(ll a, ll n) { unsigned long long int result = 1, x = a; while (n > 0) { if (n % 2 == 1) result = result * x; x = x * x; n = n / 2; } return result; } ll choose(ll n, ll k) { if (k == 0) return 1; return (n * choose(n - 1, k - 1)) / k; } int ones(ll n) { int c = 0; while (n) { n = n & (n - 1); c++; } return c; } // store gcd of a,b in d // store solution of a*x + b*y = d in x,y // if gcd(a,b)=1 then x = a^(-1)(mod b) and y = b^(-1)(mod a) ll d, x, y; void extendedEuclid(ll A, ll B) { if (B == 0) { d = A; x = 1; y = 0; } else { extendedEuclid(B, A % B); int temp = x; x = y; y = temp - (A / B) * y; } } // return modulo inverse of a wrt modulo p(should be prime) // retunt -1 if modulo inverse does not exist ll MMI(ll a, ll p) { extendedEuclid(a, p); if (d == 1 && p != 1) return ((x % p) + p) % p; else return -1; } // Fastest way to read Input void fastscan(int &number) { bool negative = false; register int c; number = 0; c = getchar(); if (c == '-') { negative = true; c = getchar(); } for (; (c > 47 && c < 58); c = getchar()) number = number * 10 + c - 48; if (negative) number *= -1; } inline int read() { int ret = 0, t = 1; char c = getchar(); while ((c < '0' || c > '9') && c != '-') c = getchar(); if (c == '-') t = -1, c = getchar(); while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar(); return ret * t; } void Build_Segment_Tree(vector<ll> &a, ll idx, ll l, ll r) // where l and r is query range. { if (l == r) { SegmentTree[idx] = a[l]; } else { ll mid = (l + r) / 2ll; Build_Segment_Tree(a, (2ll * idx), l, mid); Build_Segment_Tree(a, (2ll * idx) + 1, mid + 1, r); SegmentTree[idx] = SegmentTree[2ll * idx] + SegmentTree[2ll * idx + 1]; } } ll sum(ll idx, ll sl, ll sr, ll l, ll r) // here [sl...sr] segment range associate at idx index. where l and // r is query range. { if (l > r) { return 0; } if (sl == l && sr == r) { return SegmentTree[idx]; } ll mid = (sl + sr) / 2; return sum(2ll * idx, sl, mid, l, min(r, mid)) + sum(2ll * idx + 1, mid + 1, sr, max(mid + 1, l), r); } void update(ll idx, ll sl, ll sr, ll value, ll id) { if (sl == sr && sl == id) { SegmentTree[idx] = value; } else { ll mid = (sl + sr) / 2ll; if (id <= mid) { update(2ll * idx, sl, mid, value, id); } else { update(2ll * idx + 1, mid + 1, sr, value, id); } SegmentTree[idx] = SegmentTree[2ll * idx] + SegmentTree[2ll * idx + 1]; } } /* note: //a.resize(unique(a.begin(), a.end()) - a.begin()); use for create array unique element... //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); shuffle(g1.begin(), g1.end(), rng);(g1 is array name) for choose random number //int grand(int x) { return uniform_int_distribution<int>(0, x - 1)(rng); } //use once(num) give no of 1 in its binary form //use give (int)log2(num)+1 give no of digits in its binary form //bitset<64>(num).to_string() convert decimal to num64 bit binary number //stoull(str, nullptr, 2) convert str in binary form to decimal number // "max" priority queue: priority_queue<ll, vector<ll>, less<ll> >pq; #select max element as top()# // "min" priority queue: priority_queue<ll, vector<ll>, greater< ll> >pq; #select min element as top()# //set<int> inbuit sort accending order (set<int,less<int>>) //set<int,greater<int>> sort element in decreasing order // int __builtin_popcount(unsigned int) --->It returns the numbers of set bits in an integer (the number of ones in the binary representation of the integer). ///for finding xnor from xor x1=Xor x2=Xnor ll x1=a ^ b; ll num=max(a,b); ll xx=log2(num)+ 1; (length of num in binary form) ****ll t=(1 << xx) - 1; (set all xx length bits to 1) ll x2=x1 ^ t; (get xnor via xor using t) --->Dilworth's theorem:- this theorem says that the minimum number of non-decreasing sequences we need to cover the whole sequence equals the length of least decreasing subsequence. ----->a + b = (a xor b) +( 2 * (a & b)); ///very imp */
// Vaidik Patel(India) // DA-IICT #include <bits/stdc++.h> using namespace std; //******************************************** #include <ext/pb_ds/assoc_container.hpp> // include the associative containers or group of templates such as set, multimap, map etc. #include <ext/pb_ds/tree_policy.hpp> // include the tree_order_statistics_node update using namespace __gnu_pbds; // necessary for the GNU based Policy based data // structures. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; //******************************************** typedef long long ll; typedef unsigned long long ull; typedef long double ld; int INF = (int)1e9; ll INFINF = (ll)1e18 + 10; const ld PI = 3.14159265358979323846; #define precision(x, d) cout << fixed << setprecision(d) << x #define minheap priority_queue<ll, vector<ll>, greater<ll>> #define maxheap priority_queue<ll, vector<ll>, less<ll>> #define FOR(i, a, b) for (ll i = a; i < b; i++) #define rFOR(i, a, b) for (ll i = a; i >= b; i--) #define deb1(x) cout << #x << " : " << x << endl; #define deb2(x, y) cout << #x << " : " << x << "\t" << #y << " : " << y << endl; #define deb3(x, y, z) \ cout << #x << " : " << x << "\t" << #y << " : " << y << "\t" << #z << " : " \ << z << endl; #define deb4(x, y, z, w) \ cout << #x << " : " << x << "\t" << #y << " : " << y << "\t" << #z << " : " \ << z << "\t" << #w << " : " << w << endl; #define deb5(a, b, c, d, e) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl; #define deb6(a, b, c, d, e, f) \ cout << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << endl; #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define checkbit(n, b) ((n >> b) & 1) #define mkp make_pair #define ff first #define ss second #define FIO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define TIME \ cerr << "Time Elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << "\n"; #define lc 2 * idx #define rc 2 * idx + 1 ll powermodm(ll x, ll n, ll mod) { ll result = 1; while (n > 0) { if (n % 2 == 1) result = (result * x) % mod; x = (x * x) % mod; n = n / 2; } return result; } ll GCD(ll, ll); ll LCM(ll, ll); ll power(ll, ll); ll choose(ll, ll); int ones(ll); void extendedEuclid(ll, ll); ll MMI(ll, ll); void fastscan(int &); bool checkithbit(ll, ll); // ith bit is zero or not vector<ll> SegmentTree; void Build_Segment_Tree(vector<ll> &a, ll idx, ll l, ll r); ll sum(ll idx, ll sl, ll sr, ll l, ll r); void update(ll idx, ll sl, ll sr, ll value, ll id); vector<ll> prime; void findprime(void); ll phi(ll num); vector<int> isprime; void precomputeprime(int N); vector<int> prephi; void precomputephi(int N); int read(); typedef pair<int, int> pii; typedef pair<long long, long long> pll; typedef vector<ll> vll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<vector<ll>> vvll; typedef vector<pll> vpll; typedef vector<pii> vpii; #define pb push_back #define M 1000000007 ////////////////////////////////////////////////////////////////////////////// int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll h, w; cin >> h >> w; vector<vector<bool>> a(h, vector<bool>(w)); FOR(i, 0, h) { FOR(j, 0, w) { char ch; cin >> ch; if (ch == '.') { a[i][j] = 0; } else { a[i][j] = 1; } } } vll dp(w); dp[0] = 1; FOR(j, 1, w) { dp[j] = (a[0][j] ? 0 : dp[j - 1]); } FOR(i, 1, h) { FOR(j, 0, w) { dp[j] = (a[i][j] ? 0 : dp[j]); dp[j] %= M; } FOR(j, 1, w) { dp[j] = (a[i][j] ? 0 : dp[j] + dp[j - 1]); dp[j] %= M; } } cout << dp[w - 1]; return 0; } ////////////////////////////////////////////////////////////////////////// // precomputephi() void precomputephi(int N) { prephi.resize(N); FOR(i, 0, N) { prephi[i] = i; } for (int i = 1; i < N; i++) { if (isprime[i]) { for (int j = i; j < N; j += i) { prephi[j] = prephi[j] - (prephi[j] / i); } } } } // precomputedprime() void precomputeprime(int N) { isprime.resize(N); isprime.assign(N, 1); isprime[0] = 0; isprime[1] = 0; for (int i = 2; i * i <= 500005; i++) { if (isprime[i]) { for (int j = i * i; j <= 500005; j += i) { isprime[j] = 0; } } } } //"""euler totient function""": counts the number of integers between 1 and n //inclusive, which are coprime to n. ll phi(ll num) // find using factorization in O(sqrt(N))..... { ll result = num; for (ll i = 2; i * i <= num; i++) { if (num % i == 0) { while (num % i == 0) { num /= i; } result -= (result / i); } } if (num > 1) { result -= (result / num); } return result; } void findprime(void) { int N = 1e6 + 5; vector<bool> isprime(N, 1); // up to 1e6+5 number for (int i = 2; i * i <= N; i++) { if (isprime[i]) { for (int j = i * i; j <= N; j += i) { if (isprime[j]) { isprime[j] = 0; } } } } for (int i = 2; i <= N; i++) { if (isprime[i]) { prime.pb(i); } } } bool checkithbit(ll a, ll i) { if (a & (1 << i)) { return true; } else { return false; } } ll GCD(ll a, ll b) { if (b == 0) return a; else return GCD(b, a % b); } ll LCM(ll a, ll b) { return (max(a, b) / GCD(a, b)) * min(a, b); } ll power(ll a, ll n) { unsigned long long int result = 1, x = a; while (n > 0) { if (n % 2 == 1) result = result * x; x = x * x; n = n / 2; } return result; } ll choose(ll n, ll k) { if (k == 0) return 1; return (n * choose(n - 1, k - 1)) / k; } int ones(ll n) { int c = 0; while (n) { n = n & (n - 1); c++; } return c; } // store gcd of a,b in d // store solution of a*x + b*y = d in x,y // if gcd(a,b)=1 then x = a^(-1)(mod b) and y = b^(-1)(mod a) ll d, x, y; void extendedEuclid(ll A, ll B) { if (B == 0) { d = A; x = 1; y = 0; } else { extendedEuclid(B, A % B); int temp = x; x = y; y = temp - (A / B) * y; } } // return modulo inverse of a wrt modulo p(should be prime) // retunt -1 if modulo inverse does not exist ll MMI(ll a, ll p) { extendedEuclid(a, p); if (d == 1 && p != 1) return ((x % p) + p) % p; else return -1; } // Fastest way to read Input void fastscan(int &number) { bool negative = false; register int c; number = 0; c = getchar(); if (c == '-') { negative = true; c = getchar(); } for (; (c > 47 && c < 58); c = getchar()) number = number * 10 + c - 48; if (negative) number *= -1; } inline int read() { int ret = 0, t = 1; char c = getchar(); while ((c < '0' || c > '9') && c != '-') c = getchar(); if (c == '-') t = -1, c = getchar(); while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar(); return ret * t; } void Build_Segment_Tree(vector<ll> &a, ll idx, ll l, ll r) // where l and r is query range. { if (l == r) { SegmentTree[idx] = a[l]; } else { ll mid = (l + r) / 2ll; Build_Segment_Tree(a, (2ll * idx), l, mid); Build_Segment_Tree(a, (2ll * idx) + 1, mid + 1, r); SegmentTree[idx] = SegmentTree[2ll * idx] + SegmentTree[2ll * idx + 1]; } } ll sum(ll idx, ll sl, ll sr, ll l, ll r) // here [sl...sr] segment range associate at idx index. where l and // r is query range. { if (l > r) { return 0; } if (sl == l && sr == r) { return SegmentTree[idx]; } ll mid = (sl + sr) / 2; return sum(2ll * idx, sl, mid, l, min(r, mid)) + sum(2ll * idx + 1, mid + 1, sr, max(mid + 1, l), r); } void update(ll idx, ll sl, ll sr, ll value, ll id) { if (sl == sr && sl == id) { SegmentTree[idx] = value; } else { ll mid = (sl + sr) / 2ll; if (id <= mid) { update(2ll * idx, sl, mid, value, id); } else { update(2ll * idx + 1, mid + 1, sr, value, id); } SegmentTree[idx] = SegmentTree[2ll * idx] + SegmentTree[2ll * idx + 1]; } } /* note: //a.resize(unique(a.begin(), a.end()) - a.begin()); use for create array unique element... //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); shuffle(g1.begin(), g1.end(), rng);(g1 is array name) for choose random number //int grand(int x) { return uniform_int_distribution<int>(0, x - 1)(rng); } //use once(num) give no of 1 in its binary form //use give (int)log2(num)+1 give no of digits in its binary form //bitset<64>(num).to_string() convert decimal to num64 bit binary number //stoull(str, nullptr, 2) convert str in binary form to decimal number // "max" priority queue: priority_queue<ll, vector<ll>, less<ll> >pq; #select max element as top()# // "min" priority queue: priority_queue<ll, vector<ll>, greater< ll> >pq; #select min element as top()# //set<int> inbuit sort accending order (set<int,less<int>>) //set<int,greater<int>> sort element in decreasing order // int __builtin_popcount(unsigned int) --->It returns the numbers of set bits in an integer (the number of ones in the binary representation of the integer). ///for finding xnor from xor x1=Xor x2=Xnor ll x1=a ^ b; ll num=max(a,b); ll xx=log2(num)+ 1; (length of num in binary form) ****ll t=(1 << xx) - 1; (set all xx length bits to 1) ll x2=x1 ^ t; (get xnor via xor using t) --->Dilworth's theorem:- this theorem says that the minimum number of non-decreasing sequences we need to cover the whole sequence equals the length of least decreasing subsequence. ----->a + b = (a xor b) +( 2 * (a & b)); ///very imp */
delete
98
104
98
98
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p03167
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <tuple> #include <vector> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (n); i++) #define reps(i, f, n) for (ll i = (f); i < (n); i++) #define repr(i, n) for (ll i = n; i >= 0; i--) #define repv(v) for (auto it = (v).begin(); it != (v).end(); it++) #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #define pb push_back #define INIT \ cin.tie(0); \ ios::sync_with_stdio(false); template <class T> inline bool chmax(T &a, T b) { return a = (a < b) ? b : a; } template <class T> inline bool chmin(T &a, T b) { return a = (a > b) ? b : a; } ll const INF = 1LL << 60; ll const MOD = 1000000007; ll const MAX_N = 100; ll const MAX_M = 100; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % MOD + MOD) % MOD) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint &operator-=(const mint a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(MOD - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } // int dx[2] = {1, 0}; // int dy[2] = {0, 1}; mint dp[MAX_N][MAX_M]; int main() { INIT; ll H, W; cin >> H >> W; vector<string> a(H); rep(i, H) { cin >> a[i]; } rep(i, H) rep(j, W) dp[i][j] = 0; dp[0][0] = 1; rep(i, H) { rep(j, W) { if (i + 1 < H && a[i + 1][j] != '#') { dp[i + 1][j] += dp[i][j]; } if (j + 1 < W && a[i][j + 1] != '#') { dp[i][j + 1] += dp[i][j]; } } } // rep(i, H) { // rep(j, W) { cout << dp[i][j] << " "; } // cout << endl; // } cout << dp[H - 1][W - 1] << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <tuple> #include <vector> using namespace std; typedef long long ll; #define rep(i, n) for (ll i = 0; i < (n); i++) #define reps(i, f, n) for (ll i = (f); i < (n); i++) #define repr(i, n) for (ll i = n; i >= 0; i--) #define repv(v) for (auto it = (v).begin(); it != (v).end(); it++) #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #define pb push_back #define INIT \ cin.tie(0); \ ios::sync_with_stdio(false); template <class T> inline bool chmax(T &a, T b) { return a = (a < b) ? b : a; } template <class T> inline bool chmin(T &a, T b) { return a = (a > b) ? b : a; } ll const INF = 1LL << 60; ll const MOD = 1000000007; ll const MAX_N = 1005; ll const MAX_M = 1005; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % MOD + MOD) % MOD) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint &operator-=(const mint a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(MOD - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } // int dx[2] = {1, 0}; // int dy[2] = {0, 1}; mint dp[MAX_N][MAX_M]; int main() { INIT; ll H, W; cin >> H >> W; vector<string> a(H); rep(i, H) { cin >> a[i]; } rep(i, H) rep(j, W) dp[i][j] = 0; dp[0][0] = 1; rep(i, H) { rep(j, W) { if (i + 1 < H && a[i + 1][j] != '#') { dp[i + 1][j] += dp[i][j]; } if (j + 1 < W && a[i][j + 1] != '#') { dp[i][j + 1] += dp[i][j]; } } } // rep(i, H) { // rep(j, W) { cout << dp[i][j] << " "; } // cout << endl; // } cout << dp[H - 1][W - 1] << endl; return 0; }
replace
34
36
34
36
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; const int mod = 1'000'000'007; struct mint { ll x; mint(ll x = 0) : x(x % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; bool fi[1001][1001]; mint dp[2][1001]; int main() { int h, w; cin >> h >> w; string s; rep(i, h) { cin >> s; rep(j, w) if (s.compare(j, 1, ".") == 0) fi[i][j] = false; else fi[i][j] = true; } rep(i, h) fi[i][w] = true; rep(i, w - 1) fi[h][i] = true; fi[h][w - 1] = false; // rep(i, h+1) {rep(j, w+1) cout << fi[i][j]; cout << endl;} rep(i, w + 1) dp[0][i] = 1; int odd = (h - 1) % 2; int j, k; for (int i = h - 1; i >= 0; i--) { j = (i + 1 + odd) % 2; k = (i + odd) % 2; for (int l = w - 1; l >= 0; l--) { mint d = 0; if (fi[i][l] == true) dp[j][l] = d; else { if (fi[i + 1][l] == false) d += dp[k][l]; if (fi[i][l + 1] == false) d += dp[j][l + 1]; dp[j][l] = d; } } // rep(m, w) cout << dp[j][m]; cout << endl; } cout << dp[(odd - 1) % 2][0].x << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; const int mod = 1'000'000'007; struct mint { ll x; mint(ll x = 0) : x(x % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; bool fi[1001][1001]; mint dp[2][1001]; int main() { int h, w; cin >> h >> w; string s; rep(i, h) { cin >> s; rep(j, w) if (s.compare(j, 1, ".") == 0) fi[i][j] = false; else fi[i][j] = true; } rep(i, h) fi[i][w] = true; rep(i, w - 1) fi[h][i] = true; fi[h][w - 1] = false; // rep(i, h+1) {rep(j, w+1) cout << fi[i][j]; cout << endl;} rep(i, w + 1) dp[0][i] = 1; int odd = (h - 1) % 2; int j, k; for (int i = h - 1; i >= 0; i--) { j = (i + 1 + odd) % 2; k = (i + odd) % 2; for (int l = w - 1; l >= 0; l--) { mint d = 0; if (fi[i][l] == true) dp[j][l] = d; else { if (fi[i + 1][l] == false) d += dp[k][l]; if (fi[i][l + 1] == false) d += dp[j][l + 1]; dp[j][l] = d; } } // rep(m, w) cout << dp[j][m]; cout << endl; } cout << dp[(odd + 1) % 2][0].x << endl; }
replace
92
93
92
93
0
p03167
C++
Runtime Error
#include <iostream> #include <math.h> #include <vector> using namespace std; int main() { int H; int W; cin >> H >> W; vector<string> a(H); vector<vector<int>> cnt(H, vector<int>(H, 0)); for (int i = 0; i < H; ++i) { cin >> a[i]; } for (int i = 0; i < H; ++i) { if (a[i][0] == '.') cnt[i][0] = 1; else break; } for (int i = 0; i < W; ++i) { if (a[0][i] == '.') cnt[0][i] = 1; else break; } int mod = pow(10, 9) + 7; for (int i = 1; i < H; ++i) { for (int j = 1; j < W; ++j) { if (a[i][j] == '.') { cnt[i][j] = (cnt[i - 1][j] + cnt[i][j - 1]) % mod; } } } cout << cnt[H - 1][W - 1]; }
#include <iostream> #include <math.h> #include <vector> using namespace std; int main() { int H; int W; cin >> H >> W; vector<string> a(H); vector<vector<int>> cnt(H, vector<int>(W, 0)); for (int i = 0; i < H; ++i) { cin >> a[i]; } for (int i = 0; i < H; ++i) { if (a[i][0] == '.') cnt[i][0] = 1; else break; } for (int i = 0; i < W; ++i) { if (a[0][i] == '.') cnt[0][i] = 1; else break; } int mod = pow(10, 9) + 7; for (int i = 1; i < H; ++i) { for (int j = 1; j < W; ++j) { if (a[i][j] == '.') { cnt[i][j] = (cnt[i - 1][j] + cnt[i][j - 1]) % mod; } } } cout << cnt[H - 1][W - 1]; }
replace
11
12
11
12
0
p03167
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long int #define Fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); #define MOD 1000000007 using namespace std; int m, n; int arr[1001][1001]; ll solve(int i, int j) { if (i == m - 1 && j == n - 1) return 1; if (i > m - 1 || j > n - 1) return 0; ll ans = 0; if (arr[i + 1][j]) ans += solve(i + 1, j) % MOD; if (arr[i][j + 1]) ans += solve(i, j + 1) % MOD; return ans % MOD; } int main() { Fast cin >> m >> n; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { char x; cin >> x; if (x == '.') arr[i][j] = 1; else arr[i][j] = 0; } } cout << solve(0, 0); }
#include <bits/stdc++.h> #define ll long long int #define Fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); #define MOD 1000000007 using namespace std; int m, n; int arr[1001][1001]; ll solve(int i, int j) { if (i == m - 1 && j == n - 1) return 1; if (i > m - 1 || j > n - 1) return 0; ll ans = 0; if (arr[i + 1][j]) ans += solve(i + 1, j) % MOD; if (arr[i][j + 1]) ans += solve(i, j + 1) % MOD; return ans % MOD; } int main() { Fast cin >> m >> n; for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { char x; cin >> x; if (x == '.') arr[i][j] = 1; else arr[i][j] = 0; } } // cout<<solve(0, 0)<<endl; ll dp[m][n]; bool chk = false; for (int i = 0; i < n; i++) { if (arr[0][i] == 0) chk = true; if (chk) dp[0][i] = 0; else dp[0][i] = 1; } chk = false; for (int i = 0; i < m; i++) { if (arr[i][0] == 0) chk = true; if (chk) dp[i][0] = 0; else dp[i][0] = 1; } for (int i = 1; i < m; i++) { for (int j = 1; j < n; j++) { if (arr[i][j] == 0) dp[i][j] = 0; else dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD; } } cout << dp[m - 1][n - 1]; }
replace
41
42
41
76
TLE
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long int ll; const int N = 30, M = 1000000007; string s[N]; int i, j, n, m, dp[N][N]; bool vis[N][N]; int play(int x, int y) { if (x == n || y == m) return 0; if (s[x][y] == '#') return 0; if (vis[x][y]) return dp[x][y]; vis[x][y] = true; if (x == n - 1 && y == m - 1) return dp[x][y] = 1; return dp[x][y] = (play(x + 1, y) + play(x, y + 1)) % M; } int main() { ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(NULL); cin >> n >> m; for (i = 0; i < n; ++i) for (j = 0; j < m; ++j) vis[i][j] = false; for (i = 0; i < n; ++i) cin >> s[i]; cout << play(0, 0); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; const int N = 1030, M = 1000000007; string s[N]; int i, j, n, m, dp[N][N]; bool vis[N][N]; int play(int x, int y) { if (x == n || y == m) return 0; if (s[x][y] == '#') return 0; if (vis[x][y]) return dp[x][y]; vis[x][y] = true; if (x == n - 1 && y == m - 1) return dp[x][y] = 1; return dp[x][y] = (play(x + 1, y) + play(x, y + 1)) % M; } int main() { ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(NULL); cin >> n >> m; for (i = 0; i < n; ++i) for (j = 0; j < m; ++j) vis[i][j] = false; for (i = 0; i < n; ++i) cin >> s[i]; cout << play(0, 0); return 0; }
replace
3
4
3
4
0
p03167
C++
Time Limit Exceeded
// --------------------<optimizations>-------------------- #pragma GCC optimize("O3") //(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\ #pragma comment(linker, "/stack:200000000") //(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\ #pragma GCC optimize("unroll-loops") // -------------------</optimizations>-------------------- #include <bits/stdc++.h> using namespace std; #define int long long #define d long double #define pii pair<int, int> #define pb push_back #define pf push_front #define cases \ int tc; \ cin >> tc; \ while (tc--) #define N 100003 #define M 1003 #define inf LLONG_MAX #define hahaha \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); int mod = 1e9 + 7; // int mod=998244353; char a[M][M]; int n, m, ans = 0, dp[M][M]; int recur(int i, int j, int &cnt) { if (dp[i][j]) return dp[i][j]; if (i == n and j == m) { cnt = (cnt + 1) % mod; return dp[i][j] = cnt; } if (a[i][j + 1] == '.') dp[i][j] = (dp[i][j] + recur(i, j + 1, cnt)) % mod; if (a[i + 1][j] == '.') dp[i][j] = (dp[i][j] + recur(i + 1, j, cnt)) % mod; return dp[i][j]; } signed main() { hahaha memset(dp, 0, sizeof dp); cin >> n >> m; int i, j, k; for (i = 1; i <= n; ++i) for (j = 1; j <= m; ++j) cin >> a[i][j]; int cnt = 0; cout << recur(1, 1, cnt); return 0; }
// --------------------<optimizations>-------------------- #pragma GCC optimize("O3") //(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\ #pragma comment(linker, "/stack:200000000") //(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\ #pragma GCC optimize("unroll-loops") // -------------------</optimizations>-------------------- #include <bits/stdc++.h> using namespace std; #define int long long #define d long double #define pii pair<int, int> #define pb push_back #define pf push_front #define cases \ int tc; \ cin >> tc; \ while (tc--) #define N 100003 #define M 1003 #define inf LLONG_MAX #define hahaha \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); int mod = 1e9 + 7; // int mod=998244353; char a[M][M]; int n, m, ans = 0, dp[M][M]; int recur(int i, int j, int &cnt) { if (dp[i][j]) return dp[i][j]; if (i == n and j == m) { cnt = (cnt + 1) % mod; return dp[i][j] = cnt; } if (a[i][j + 1] == '.') dp[i][j] = (dp[i][j] + recur(i, j + 1, cnt)) % mod; if (a[i + 1][j] == '.') dp[i][j] = (dp[i][j] + recur(i + 1, j, cnt)) % mod; return dp[i][j]; } signed main() { hahaha memset(dp, 0, sizeof dp); cin >> n >> m; int i, j, k; for (i = 1; i <= n; ++i) for (j = 1; j <= m; ++j) cin >> a[i][j]; dp[1][1] = 1; for (i = 1; i <= n; ++i) for (j = 1; j <= m; ++j) if (a[i][j] == '.') dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod, dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod; cout << dp[n][m]; // int cnt=0; // cout<<recur(1,1,cnt); return 0; }
replace
58
60
58
68
TLE
p03167
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; typedef long long ll; typedef long double ld; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; ll exp(ll x, ll y) { if (y == 0) return 1; if (y % 2 == 1) return x * exp(x, y / 2) * exp(x, y / 2); return exp(x, y / 2) * exp(x, y / 2); } ll exp(ll x, ll y, ll modd) { if (y == 0) return 1; ll t = exp(x, y / 2, modd); t = t % modd; t = t * t; t = t % modd; if (y % 2 == 1) return (x * t) % modd; return t % modd; } #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") #pragma GCC target("sse4") #define ios \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define so sizeof #define pb push_back #define cl clear(); #define vl vector<ll> #define sz size() #define len length() #define emp empty() #define el \ endl; \ cout.flush() #define be begin() #define fi first #define se second #define br break #define en end() #define ro return 0 #define eb emplace_back #define con continue #define ms(x) memset(x, 0ll, so x) #define all(x) (x).be, (x).en #define acc(x) accumulate((x).be, (x).en, 0ll) #define forn(i, a, b) for (ll i = a; i <= b; ++i) #define revn(i, a, b) for (ll i = a; i >= b; --i) #define rng_58 \ mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #define vs vector<string> #define vsi vector<pair<string, int>> #define vll vector<pair<ll, ll>> #define vlll vector<pair<ll, pair<ll, ll>>> #define vlvl vector < pair < pair<ll, ll>, ll >>> #define pll pair<ll, ll> #define plll pair<ll, pair<ll, ll>> #define plvl pair<pair<ll, ll>, ll> #define mp make_pair #define trace3(a, b, c) \ cerr << "a is " << a << " b is " << b << " c is " << c << el; #define trace4(a, b, c, d) \ cerr << "a is " << a << " b is " << b << " c is " << c << " d is " << d << el; #define trace5(a, b, c, d, e) \ cerr << "a is " << a << " b is " << b << " c is " << c << " d is " << d \ << " e is " << e << el; #define trace6(a, b, c, d, e, f) \ cerr << "a is " << a << " b is " << b << " c is " << c << " d is " << d \ << " e is " << e << " f is " << f << el; const int mod = 1e9 + 7; int main() { ios; int n, h; cin >> n >> h; vector<vector<char>> grid(n, vector<char>(h)); vector<vector<int>> dp(n, vector<int>(h, 0)); for (int i = 0; i < n; i++) for (int j = 0; j < h; j++) cin >> grid[i][j]; for (int i = 1; i < h; i++) { if (grid[0][i] == '#') break; dp[0][i] = 1; } for (int i = 1; i < h; i++) { if (grid[i][0] == '#') break; dp[i][0] = 1; } for (int i = 1; i < n; i++) for (int j = 1; j < h; j++) { if (grid[i][j] == '.') dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod; else dp[i][j] = 0; } cout << dp[n - 1][h - 1] % mod; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; typedef long long ll; typedef long double ld; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; ll exp(ll x, ll y) { if (y == 0) return 1; if (y % 2 == 1) return x * exp(x, y / 2) * exp(x, y / 2); return exp(x, y / 2) * exp(x, y / 2); } ll exp(ll x, ll y, ll modd) { if (y == 0) return 1; ll t = exp(x, y / 2, modd); t = t % modd; t = t * t; t = t % modd; if (y % 2 == 1) return (x * t) % modd; return t % modd; } #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") #pragma GCC target("sse4") #define ios \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define so sizeof #define pb push_back #define cl clear(); #define vl vector<ll> #define sz size() #define len length() #define emp empty() #define el \ endl; \ cout.flush() #define be begin() #define fi first #define se second #define br break #define en end() #define ro return 0 #define eb emplace_back #define con continue #define ms(x) memset(x, 0ll, so x) #define all(x) (x).be, (x).en #define acc(x) accumulate((x).be, (x).en, 0ll) #define forn(i, a, b) for (ll i = a; i <= b; ++i) #define revn(i, a, b) for (ll i = a; i >= b; --i) #define rng_58 \ mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()) #define vs vector<string> #define vsi vector<pair<string, int>> #define vll vector<pair<ll, ll>> #define vlll vector<pair<ll, pair<ll, ll>>> #define vlvl vector < pair < pair<ll, ll>, ll >>> #define pll pair<ll, ll> #define plll pair<ll, pair<ll, ll>> #define plvl pair<pair<ll, ll>, ll> #define mp make_pair #define trace3(a, b, c) \ cerr << "a is " << a << " b is " << b << " c is " << c << el; #define trace4(a, b, c, d) \ cerr << "a is " << a << " b is " << b << " c is " << c << " d is " << d << el; #define trace5(a, b, c, d, e) \ cerr << "a is " << a << " b is " << b << " c is " << c << " d is " << d \ << " e is " << e << el; #define trace6(a, b, c, d, e, f) \ cerr << "a is " << a << " b is " << b << " c is " << c << " d is " << d \ << " e is " << e << " f is " << f << el; const int mod = 1e9 + 7; int main() { ios; int n, h; cin >> n >> h; vector<vector<char>> grid(n, vector<char>(h)); vector<vector<int>> dp(n, vector<int>(h, 0)); for (int i = 0; i < n; i++) for (int j = 0; j < h; j++) cin >> grid[i][j]; for (int i = 1; i < h; i++) { if (grid[0][i] == '#') break; dp[0][i] = 1; } for (int i = 1; i < n; i++) { if (grid[i][0] == '#') break; dp[i][0] = 1; } for (int i = 1; i < n; i++) for (int j = 1; j < h; j++) { if (grid[i][j] == '.') dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod; else dp[i][j] = 0; } cout << dp[n - 1][h - 1] % mod; return 0; }
replace
101
102
101
102
-11
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define int long long int #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define mod 1000000007 #define endl '\n' #define rep(i, a, b) for (int i = a; i < b; i++) int n, m; int rec(vector<vector<char>> &a, int i, int j, vector<vector<int>> &dp) { if (i > n or j > m or a[i][j] == '#') { return 0; } if (i == n - 1 and j == m - 1) { return 1; } if (dp[i][j] != -1) { return dp[i][j]; } int x = rec(a, i + 1, j, dp); int y = rec(a, i, j + 1, dp); return dp[i][j] = (x % mod + y % mod) % mod; } void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int32_t main() { c_p_c(); cin >> n >> m; vector<vector<char>> a(n + 1, vector<char>(n + 1, -1)); rep(i, 0, n) { rep(j, 0, m) { cin >> a[i][j]; } } vector<vector<int>> dp(n + 1, vi(m + 1, -1)); cout << rec(a, 0, 0, dp) % mod; return 0; }
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define int long long int #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define mii map<int, int> #define pqb priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define mod 1000000007 #define endl '\n' #define rep(i, a, b) for (int i = a; i < b; i++) int n, m; int rec(vector<vector<char>> &a, int i, int j, vector<vector<int>> &dp) { if (i > n or j > m or a[i][j] == '#') { return 0; } if (i == n - 1 and j == m - 1) { return 1; } if (dp[i][j] != -1) { return dp[i][j]; } int x = rec(a, i + 1, j, dp); int y = rec(a, i, j + 1, dp); return dp[i][j] = (x % mod + y % mod) % mod; } void c_p_c() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int32_t main() { c_p_c(); cin >> n >> m; vector<vector<char>> a(n + 1, vector<char>(m + 1, -1)); rep(i, 0, n) { rep(j, 0, m) { cin >> a[i][j]; } } vector<vector<int>> dp(n + 1, vi(m + 1, -1)); cout << rec(a, 0, 0, dp) % mod; return 0; }
replace
46
47
46
47
0
p03167
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define read freopen("in.in", "r", stdin) #define write freopen("out.out", "w", stdout) #define FastIO ios::sync_with_stdio(0) #define All(a) a.begin(), a.end() #define PI 3.1415926535897932385 #define INF 1000000000 #define eps 1e-7 #define Clear(a) memset(a, 0, sizeof(a)) #define MOD 1000000007 typedef vector<int> vi; typedef pair<pair<int, int>, int> pii; typedef unsigned long long ull; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; ll GCD(ll a, ll b) { if (b == 0) return a; return GCD(b, a % b); } ll LCM(ll a, ll b) { return (a / GCD(a, b)) * b; } pair<ll, pair<ll, ll>> extendedEuclid(ll a, ll b) { if (a == 0) return make_pair(b, make_pair(0, 1)); pair<ll, pair<ll, ll>> p; p = extendedEuclid(b % a, a); return make_pair( p.first, make_pair(p.second.second - p.second.first * (b / a), p.second.first)); } ll modInverse(ll a, ll m) { return (extendedEuclid(a, m).second.first + m) % m; } ll inverseMod(ll x, ll y, ll z) { return ((x % z) * modInverse(y, z)) % z; } ll BigMod(ll x, ll y) { if (y == 0) return 1; if (x == 1) return 1; if (y == 1) return x; ll ans = BigMod(x, y / 2) % MOD; if (y & 1) return ((x % MOD * ans % MOD) % MOD * ans % MOD) % MOD; return (ans % MOD * ans % MOD) % MOD; } int n, m; int in[1001][1001]; int dp[1001][1001]; int val(int x, int y) { return x >= 0 && y >= 0 && x < n && y < m && in[x][y] == 0; } int solve(int x, int y) { if (x == n - 1 && y == m - 1) return 1; ; if (dp[x][y] != -1) return dp[x][y]; int ans = 0; for (int c = 0; c < 2; c++) { int xx = x + dx[c], yy = y + dy[c]; if (val(xx, yy)) ans += solve(xx, yy); ans %= MOD; } return dp[x][y] = ans % MOD; } int main() { FastIO; #ifndef ONLINE_JUDGE freopen("in.in", "r", stdin); // freopen("out.out", "w", stdout); #endif cin >> n >> m; for (int c = 0; c < n; c++) { for (int i = 0; i < m; i++) { char x; cin >> x; if (x == '.') in[c][i] = 0; else in[c][i] = 1; } } memset(dp, -1, sizeof dp); cout << solve(0, 0) % MOD << " "; // cout << dp[n - 1][m - 1]+1 << endl; return 0; }
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define read freopen("in.in", "r", stdin) #define write freopen("out.out", "w", stdout) #define FastIO ios::sync_with_stdio(0) #define All(a) a.begin(), a.end() #define PI 3.1415926535897932385 #define INF 1000000000 #define eps 1e-7 #define Clear(a) memset(a, 0, sizeof(a)) #define MOD 1000000007 typedef vector<int> vi; typedef pair<pair<int, int>, int> pii; typedef unsigned long long ull; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; ll GCD(ll a, ll b) { if (b == 0) return a; return GCD(b, a % b); } ll LCM(ll a, ll b) { return (a / GCD(a, b)) * b; } pair<ll, pair<ll, ll>> extendedEuclid(ll a, ll b) { if (a == 0) return make_pair(b, make_pair(0, 1)); pair<ll, pair<ll, ll>> p; p = extendedEuclid(b % a, a); return make_pair( p.first, make_pair(p.second.second - p.second.first * (b / a), p.second.first)); } ll modInverse(ll a, ll m) { return (extendedEuclid(a, m).second.first + m) % m; } ll inverseMod(ll x, ll y, ll z) { return ((x % z) * modInverse(y, z)) % z; } ll BigMod(ll x, ll y) { if (y == 0) return 1; if (x == 1) return 1; if (y == 1) return x; ll ans = BigMod(x, y / 2) % MOD; if (y & 1) return ((x % MOD * ans % MOD) % MOD * ans % MOD) % MOD; return (ans % MOD * ans % MOD) % MOD; } int n, m; int in[1001][1001]; int dp[1001][1001]; int val(int x, int y) { return x >= 0 && y >= 0 && x < n && y < m && in[x][y] == 0; } int solve(int x, int y) { if (x == n - 1 && y == m - 1) return 1; ; if (dp[x][y] != -1) return dp[x][y]; int ans = 0; for (int c = 0; c < 2; c++) { int xx = x + dx[c], yy = y + dy[c]; if (val(xx, yy)) ans += solve(xx, yy); ans %= MOD; } return dp[x][y] = ans % MOD; } int main() { FastIO; cin >> n >> m; for (int c = 0; c < n; c++) { for (int i = 0; i < m; i++) { char x; cin >> x; if (x == '.') in[c][i] = 0; else in[c][i] = 1; } } memset(dp, -1, sizeof dp); cout << solve(0, 0) % MOD << " "; // cout << dp[n - 1][m - 1]+1 << endl; return 0; }
delete
83
87
83
83
0
p03167
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 1055; char mat[N][N]; int dp[N][N], n, m; const int dx[2] = {1, 0}; const int dy[2] = {0, 1}; const int MOD = 1e9 + 7; int sol(int i, int j) { if (i == n - 1 && j == m - 1) return 1; int ans = dp[i][j]; if (ans != -1) return ans; ans = 0; for (int k = 0; k < 2; k++) { int x = i + dx[k]; int y = j + dy[k]; if (x >= 0 && y >= 0 && x < n && y < m && mat[x][y] == '.') { ans = (ans + sol(x, y)) % MOD; } } return ans; } void solve() { cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> mat[i][j]; } } memset(dp, -1, sizeof(dp)); cout << sol(0, 0) << "\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; // cin>>t; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 1055; char mat[N][N]; int dp[N][N], n, m; const int dx[2] = {1, 0}; const int dy[2] = {0, 1}; const int MOD = 1e9 + 7; int sol(int i, int j) { if (i == n - 1 && j == m - 1) return 1; int &ans = dp[i][j]; if (ans != -1) return ans; ans = 0; for (int k = 0; k < 2; k++) { int x = i + dx[k]; int y = j + dy[k]; if (x >= 0 && y >= 0 && x < n && y < m && mat[x][y] == '.') { ans = (ans + sol(x, y)) % MOD; } } return ans; } void solve() { cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> mat[i][j]; } } memset(dp, -1, sizeof(dp)); cout << sol(0, 0) << "\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t = 1; // cin>>t; while (t--) { solve(); } }
replace
16
17
16
17
TLE
p03167
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; // ascending order #define vsort(v) sort(v.begin(), v.end()) // descending order #define vsort_r(v) sort(v.begin(), v.end(), greater<int>()) #define vunique(v) unique(v.begin(), v.end()) #define mp make_pair #define ts(x) to_string(x) #define rep(i, a, b) for (int i = (int)a; i < (int)b; i++) #define repm(i, a, b) for (int i = (int)a; i > (int)b; i--) #define bit(a) bitset<8>(a) #define des_priority_queue priority_queue<int, vector<int>, greater<int>> #define all(v) (v).begin(), (v).end() typedef long long ll; typedef pair<int, int> P; const ll INF = 1e18; int main() { cin.tie(0); ios::sync_with_stdio(false); int H, W; cin >> H >> W; char a[H + 2][W + 2]; rep(j, 0, W + 2) a[0][j] = a[H + 2][j] = '#'; rep(i, 0, H + 2) a[i][0] = a[i][W + 2] = '#'; rep(i, 1, H + 1) rep(j, 1, W + 1) cin >> a[i][j]; ll dp[H + 1][W + 1]; rep(i, 0, H + 1) rep(j, 0, W + 1) dp[i][j] = 0ll; dp[0][0] = 1ll; dp[1][1] = 1ll; int mod = 1e9 + 7; rep(i, 1, H + 1) rep(j, 1, W + 1) { if (i + 1 <= H) { if (a[i + 1][j] == '.') { (dp[i + 1][j] += dp[i][j]) %= mod; } } if (j + 1 <= W) { if (a[i][j + 1] == '.') { (dp[i][j + 1] += dp[i][j]) %= mod; } } } cout << dp[H][W] % mod << endl; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; // ascending order #define vsort(v) sort(v.begin(), v.end()) // descending order #define vsort_r(v) sort(v.begin(), v.end(), greater<int>()) #define vunique(v) unique(v.begin(), v.end()) #define mp make_pair #define ts(x) to_string(x) #define rep(i, a, b) for (int i = (int)a; i < (int)b; i++) #define repm(i, a, b) for (int i = (int)a; i > (int)b; i--) #define bit(a) bitset<8>(a) #define des_priority_queue priority_queue<int, vector<int>, greater<int>> #define all(v) (v).begin(), (v).end() typedef long long ll; typedef pair<int, int> P; const ll INF = 1e18; int main() { cin.tie(0); ios::sync_with_stdio(false); int H, W; cin >> H >> W; char a[H + 2][W + 2]; rep(j, 0, W + 2) a[0][j] = a[H + 1][j] = '#'; rep(i, 0, H + 2) a[i][0] = a[i][W + 1] = '#'; rep(i, 1, H + 1) rep(j, 1, W + 1) cin >> a[i][j]; ll dp[H + 1][W + 1]; rep(i, 0, H + 1) rep(j, 0, W + 1) dp[i][j] = 0ll; dp[0][0] = 1ll; dp[1][1] = 1ll; int mod = 1e9 + 7; rep(i, 1, H + 1) rep(j, 1, W + 1) { if (i + 1 <= H) { if (a[i + 1][j] == '.') { (dp[i + 1][j] += dp[i][j]) %= mod; } } if (j + 1 <= W) { if (a[i][j + 1] == '.') { (dp[i][j + 1] += dp[i][j]) %= mod; } } } cout << dp[H][W] % mod << endl; }
replace
37
39
37
39
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define FAST \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); ll mod = 1000000007; ll INF = 1e9 + 5; ll M = 1e9 + 7; int main() { FAST; ll h, w; cin >> h >> w; vector<vector<char>> a(h, vector<char>(w)); vector<vector<ll>> dp(h + 1, vector<ll>(w + 1, 0)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> a[i][j]; } } ll c = 1; for (int i = 1; i <= h; i++) { if (a[0][i - 1] == '#' || c == 0) { dp[1][i] = 0; c = 0; } else { dp[1][i] = 1; } } c = 1; for (int i = 1; i <= h; i++) { if (a[i - 1][0] == '#' || c == 0) { dp[i][1] = 0; c = 0; } else { dp[i][1] = 1; } } for (int i = 2; i <= h; i++) { for (int j = 2; j <= w; j++) { if (a[i - 1][j - 1] == '#') { dp[i][j] = 0; } else { dp[i][j] = (dp[i - 1][j] % M + dp[i][j - 1] % M) % M; } } } cout << dp[h][w] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define FAST \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); ll mod = 1000000007; ll INF = 1e9 + 5; ll M = 1e9 + 7; int main() { FAST; ll h, w; cin >> h >> w; vector<vector<char>> a(h, vector<char>(w)); vector<vector<ll>> dp(h + 1, vector<ll>(w + 1, 0)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { cin >> a[i][j]; } } ll c = 1; for (int i = 1; i <= w; i++) { if (a[0][i - 1] == '#' || c == 0) { dp[1][i] = 0; c = 0; } else { dp[1][i] = 1; } } c = 1; for (int i = 1; i <= h; i++) { if (a[i - 1][0] == '#' || c == 0) { dp[i][1] = 0; c = 0; } else { dp[i][1] = 1; } } for (int i = 2; i <= h; i++) { for (int j = 2; j <= w; j++) { if (a[i - 1][j - 1] == '#') { dp[i][j] = 0; } else { dp[i][j] = (dp[i - 1][j] % M + dp[i][j - 1] % M) % M; } } } cout << dp[h][w] << endl; return 0; }
replace
24
25
24
25
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> dp(n, 0), ndp(dp); dp[0] = 1; for (int i = 0; i < n; ++i) { string now; cin >> now; for (int j = 0; j < m; ++j) { if (now[j] == '#') ndp[j] = 0; else { ndp[j] = dp[j]; if (j > 0) ndp[j] += ndp[j - 1]; ndp[j] %= 1000000007; } } swap(dp, ndp); } cout << dp[m - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<int> dp(m, 0), ndp(dp); dp[0] = 1; for (int i = 0; i < n; ++i) { string now; cin >> now; for (int j = 0; j < m; ++j) { if (now[j] == '#') ndp[j] = 0; else { ndp[j] = dp[j]; if (j > 0) ndp[j] += ndp[j - 1]; ndp[j] %= 1000000007; } } swap(dp, ndp); } cout << dp[m - 1] << endl; return 0; }
replace
8
9
8
9
0
p03167
C++
Runtime Error
// Medha's code : #include <bits/stdc++.h> using namespace std; typedef long long int ll; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define INF 0x3f3f3f3f3f #define MOD 1000000007 int main() { fastio; ll h, w; cin >> h >> w; vector<vector<bool>> grid(h + 5, vector<bool>(w + 5)); vector<vector<ll>> count(h + 5, vector<ll>(w + 5)); char x; for (ll i = 1; i <= h; i++) { for (ll j = 1; j <= w; j++) { cin >> x; if (x == '.') grid[i][j] = true; else grid[i][j] = false; } } ll k = 1; while (grid[k][1] == true) { count[k][1] = 1; k++; } for (ll i = k; i <= w; i++) { count[i][1] = 0; } k = 1; while (grid[1][k] == true) { count[1][k] = 1; k++; } for (ll i = k; i <= w; i++) { count[1][i] = 0; } for (ll i = 2; i <= h; i++) { for (ll j = 2; j <= w; j++) { if (grid[i][j] == true) { count[i][j] = ((count[i][j - 1]) % MOD + (count[i - 1][j]) % MOD) % MOD; } else { count[i][j] = 0; } } } cout << (count[h][w]) % MOD; return 0; }
// Medha's code : #include <bits/stdc++.h> using namespace std; typedef long long int ll; #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define INF 0x3f3f3f3f3f #define MOD 1000000007 int main() { fastio; ll h, w; cin >> h >> w; vector<vector<bool>> grid(h + 5, vector<bool>(w + 5)); vector<vector<ll>> count(h + 5, vector<ll>(w + 5)); char x; for (ll i = 1; i <= h; i++) { for (ll j = 1; j <= w; j++) { cin >> x; if (x == '.') grid[i][j] = true; else grid[i][j] = false; } } ll k = 1; while (grid[k][1] == true) { count[k][1] = 1; k++; } for (ll i = k; i <= h; i++) { count[i][1] = 0; } k = 1; while (grid[1][k] == true) { count[1][k] = 1; k++; } for (ll i = k; i <= w; i++) { count[1][i] = 0; } for (ll i = 2; i <= h; i++) { for (ll j = 2; j <= w; j++) { if (grid[i][j] == true) { count[i][j] = ((count[i][j - 1]) % MOD + (count[i - 1][j]) % MOD) % MOD; } else { count[i][j] = 0; } } } cout << (count[h][w]) % MOD; return 0; }
replace
41
42
41
42
0
p03167
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long #define F(i, a, b) for (i = a; i <= b; i++) #define RF(i, a, b) for (i = a; i >= b; i--) #define sz(a) sizeof(a) #define next_line cout << '\n' #define space cout << ' ' #define deb(a) cout << #a << ' ' << a using namespace std; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<char, int> pci; typedef map<int, int> mii; typedef map<ll, ll> mll; typedef map<char, int> mci; typedef unordered_map<int, int> umii; typedef unordered_map<ll, ll> umll; typedef unordered_map<char, int> umci; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; ll mod = 1e9 + 7LL; vector<ll> dp(1000001, -1LL); ll n, m, i, j; ll NumberOfWays(ll st_i, ll st_j, vector<vector<char>> Grid) { if ((st_i >= n) || (st_j >= m)) return 0LL; ll indx = (st_i * m + st_j); if (dp[indx] != -1LL) return dp[indx]; if (Grid[st_i][st_j] == '#') return 0LL; if ((st_i == (n - 1LL)) && (st_j == (m - 1LL))) return 1LL; // deb(indx);space;deb(dp[indx]); // next_line; dp[indx] = (NumberOfWays(st_i, st_j + 1LL, Grid) + NumberOfWays(st_i + 1LL, st_j, Grid)) % mod; return dp[indx]; } void solve() { cin >> n >> m; vector<vector<char>> Grid(n, vector<char>(m)); F(i, 0LL, n - 1LL) { F(j, 0LL, m - 1LL) { cin >> Grid[i][j]; } } cout << NumberOfWays(0LL, 0LL, Grid) << '\n'; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #else // #endif solve(); }
#include <bits/stdc++.h> #define ll long long #define F(i, a, b) for (i = a; i <= b; i++) #define RF(i, a, b) for (i = a; i >= b; i--) #define sz(a) sizeof(a) #define next_line cout << '\n' #define space cout << ' ' #define deb(a) cout << #a << ' ' << a using namespace std; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<char, int> pci; typedef map<int, int> mii; typedef map<ll, ll> mll; typedef map<char, int> mci; typedef unordered_map<int, int> umii; typedef unordered_map<ll, ll> umll; typedef unordered_map<char, int> umci; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; ll mod = 1e9 + 7LL; vector<ll> dp(1000001, -1LL); ll n, m, i, j; ll NumberOfWays(ll st_i, ll st_j, vector<vector<char>> &Grid) { if ((st_i >= n) || (st_j >= m)) return 0LL; ll indx = (st_i * m + st_j); if (dp[indx] != -1LL) return dp[indx]; if (Grid[st_i][st_j] == '#') return 0LL; if ((st_i == (n - 1LL)) && (st_j == (m - 1LL))) return 1LL; // deb(indx);space;deb(dp[indx]); // next_line; dp[indx] = (NumberOfWays(st_i, st_j + 1LL, Grid) + NumberOfWays(st_i + 1LL, st_j, Grid)) % mod; return dp[indx]; } void solve() { cin >> n >> m; vector<vector<char>> Grid(n, vector<char>(m)); F(i, 0LL, n - 1LL) { F(j, 0LL, m - 1LL) { cin >> Grid[i][j]; } } cout << NumberOfWays(0LL, 0LL, Grid) << '\n'; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #else // #endif solve(); }
replace
25
26
25
26
TLE
p03167
C++
Runtime Error
/* dp[i][j] = no. of ways to reach (H, W) from (i, j) */ #include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; int main() { int H, W; vector<vector<ll>> dp; vector<string> a; cin >> H >> W; a.assign(H + 1, ""); dp.assign(H + 1, vector<ll>(H + 1, 0)); for (int i = 0; i < H; i++) { cin >> a[i]; } for (int i = W - 1; i >= 0; i--) { if (a[H - 1][i] != '#') dp[H - 1][i] = 1; else break; } for (int i = H - 1; i >= 0; i--) { if (a[i][W - 1] != '#') dp[i][W - 1] = 1; else break; } for (int i = H - 2; i >= 0; i--) { for (int j = W - 2; j >= 0; j--) { if (a[i][j] != '#') dp[i][j] = (dp[i + 1][j] + dp[i][j + 1]) % mod; } } cout << dp[0][0] << "\n"; /*for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ cout<<dp[i][j]<<" "; } cout<<"\n"; }*/ return 0; }
/* dp[i][j] = no. of ways to reach (H, W) from (i, j) */ #include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; int main() { int H, W; vector<vector<ll>> dp; vector<string> a; cin >> H >> W; a.assign(H + 1, ""); dp.assign(H + 1, vector<ll>(W + 1, 0)); for (int i = 0; i < H; i++) { cin >> a[i]; } for (int i = W - 1; i >= 0; i--) { if (a[H - 1][i] != '#') dp[H - 1][i] = 1; else break; } for (int i = H - 1; i >= 0; i--) { if (a[i][W - 1] != '#') dp[i][W - 1] = 1; else break; } for (int i = H - 2; i >= 0; i--) { for (int j = W - 2; j >= 0; j--) { if (a[i][j] != '#') dp[i][j] = (dp[i + 1][j] + dp[i][j + 1]) % mod; } } cout << dp[0][0] << "\n"; /*for(int i=0;i<H;i++){ for(int j=0;j<W;j++){ cout<<dp[i][j]<<" "; } cout<<"\n"; }*/ return 0; }
replace
18
19
18
19
0
p03167
C++
Runtime Error
#include <algorithm> #include <cassert> #include <climits> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <vector> #define ll long long using namespace std; const int mod = 1e9 + 7; int main() { freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); int h, w; scanf("%d %d", &h, &w); vector<vector<char>> a(h + 1, vector<char>(w + 1)); for (int i = 1; i <= h; i++) for (int j = 1; j <= w; j++) scanf(" %c", &a[i][j]); vector<vector<int>> cnt(h + 1, vector<int>(w + 1, 0)); cnt[1][1] = 1; if (a[1][1] == '#' || a[h][w] == '#') { printf("0"); return 0; } for (int j = 2; j <= w; j++) { if (a[1][j] != '#') { cnt[1][j] += (cnt[1][j - 1]) % mod; } } for (int i = 2; i <= h; i++) { if (a[i][1] != '#') { cnt[i][1] += (cnt[i - 1][1]) % mod; } } for (int i = 2; i <= h; i++) { for (int j = 2; j <= w; j++) { if (a[i][j] != '#') { cnt[i][j] = (cnt[i - 1][j] + cnt[i][j - 1]) % mod; } } } printf("%d", cnt[h][w] % mod); return 0; }
#include <algorithm> #include <cassert> #include <climits> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <vector> #define ll long long using namespace std; const int mod = 1e9 + 7; int main() { // freopen("input.txt", "rt", stdin); // freopen("output.txt", "wt", stdout); int h, w; scanf("%d %d", &h, &w); vector<vector<char>> a(h + 1, vector<char>(w + 1)); for (int i = 1; i <= h; i++) for (int j = 1; j <= w; j++) scanf(" %c", &a[i][j]); vector<vector<int>> cnt(h + 1, vector<int>(w + 1, 0)); cnt[1][1] = 1; if (a[1][1] == '#' || a[h][w] == '#') { printf("0"); return 0; } for (int j = 2; j <= w; j++) { if (a[1][j] != '#') { cnt[1][j] += (cnt[1][j - 1]) % mod; } } for (int i = 2; i <= h; i++) { if (a[i][1] != '#') { cnt[i][1] += (cnt[i - 1][1]) % mod; } } for (int i = 2; i <= h; i++) { for (int j = 2; j <= w; j++) { if (a[i][j] != '#') { cnt[i][j] = (cnt[i - 1][j] + cnt[i][j - 1]) % mod; } } } printf("%d", cnt[h][w] % mod); return 0; }
replace
24
26
24
26
-6
terminate called after throwing an instance of 'std::length_error' what(): cannot create std::vector larger than max_size()
p03167
C++
Runtime Error
#include <bits/stdc++.h> #define debug(x) cout << #x << "::" << x << endl; using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; void solve() { int h, w; cin >> h >> w; vector<string> v(h); for (int i = 0; i < h; i++) { cin >> v[i]; } vector<vector<int>> dp(h, vector<int>(w, 0)); dp[0][0] = 1; for (int i = 1; i < h; i++) { if (v[i][0] == '.') { dp[i][0] = dp[i - 1][0]; } } for (int j = 1; j < w; j++) { if (v[0][j] == '.') { dp[0][j] = dp[0][j - 1]; } } for (int i = 1; i < h; i++) { for (int j = 1; j < w; j++) { if (v[i][j] == '.') { dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD; } } } cout << dp[h - 1][w - 1] << '\n'; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif int t; t = 1; while (t--) solve(); return 0; }
#include <bits/stdc++.h> #define debug(x) cout << #x << "::" << x << endl; using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; void solve() { int h, w; cin >> h >> w; vector<string> v(h); for (int i = 0; i < h; i++) { cin >> v[i]; } vector<vector<int>> dp(h, vector<int>(w, 0)); dp[0][0] = 1; for (int i = 1; i < h; i++) { if (v[i][0] == '.') { dp[i][0] = dp[i - 1][0]; } } for (int j = 1; j < w; j++) { if (v[0][j] == '.') { dp[0][j] = dp[0][j - 1]; } } for (int i = 1; i < h; i++) { for (int j = 1; j < w; j++) { if (v[i][j] == '.') { dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD; } } } cout << dp[h - 1][w - 1] << '\n'; } int main() { int t; t = 1; while (t--) solve(); return 0; }
delete
35
39
35
35
-11
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int mod = 1e9 + 7; int dp[1000][1000]; int main() { int t, h, w; char st[1003][1003]; cin >> h >> w; for (int i = 0; i < h; i++) { scanf("%s", st[i]); } dp[0][0] = 1; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { int c1 = j + 1; int r1 = i + 1; if (st[i][j] == '.') { if (st[i][c1] != '#') { dp[i][c1] += dp[i][j]; if (dp[i][c1] >= mod) dp[i][c1] -= mod; } if (st[r1][j] != '#') { dp[r1][j] += dp[i][j]; if (dp[r1][j] >= mod) dp[r1][j] -= mod; } } } } cout << dp[h - 1][w - 1] << endl; }
#include <bits/stdc++.h> using namespace std; int mod = 1e9 + 7; int dp[1005][1005]; int main() { int t, h, w; char st[1003][1003]; cin >> h >> w; for (int i = 0; i < h; i++) { scanf("%s", st[i]); } dp[0][0] = 1; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { int c1 = j + 1; int r1 = i + 1; if (st[i][j] == '.') { if (st[i][c1] != '#') { dp[i][c1] += dp[i][j]; if (dp[i][c1] >= mod) dp[i][c1] -= mod; } if (st[r1][j] != '#') { dp[r1][j] += dp[i][j]; if (dp[r1][j] >= mod) dp[r1][j] -= mod; } } } } cout << dp[h - 1][w - 1] << endl; }
replace
3
4
3
4
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define mod 1000000007 int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); ll m, n; cin >> m >> n; ll dp[m][n]; string h[m]; for (ll i = 0; i < m; i++) cin >> h[i]; int f = 0; for (ll i = 0; i < n; i++) { if (h[0][i] == '#') { dp[0][i] = 0; f = 1; continue; } if (f == 0) dp[0][i] = 1; else dp[0][i] = 0; } f = 0; for (ll i = 0; i < n; i++) { if (h[i][0] == '#') { dp[i][0] = 0; f = 1; continue; } if (f == 0) dp[i][0] = 1; else dp[i][0] = 0; } for (ll i = 1; i < m; i++) { for (ll j = 1; j < n; j++) { if (h[i][j] == '#') dp[i][j] = 0; else dp[i][j] = ((dp[i - 1][j]) % mod + (dp[i][j - 1]) % mod) % mod; } } cout << dp[m - 1][n - 1]; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define mod 1000000007 int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); ll m, n; cin >> m >> n; ll dp[m][n]; string h[m]; for (ll i = 0; i < m; i++) cin >> h[i]; int f = 0; for (ll i = 0; i < n; i++) { if (h[0][i] == '#') { dp[0][i] = 0; f = 1; continue; } if (f == 0) dp[0][i] = 1; else dp[0][i] = 0; } f = 0; for (ll i = 0; i < m; i++) { if (h[i][0] == '#') { dp[i][0] = 0; f = 1; continue; } if (f == 0) dp[i][0] = 1; else dp[i][0] = 0; } for (ll i = 1; i < m; i++) { for (ll j = 1; j < n; j++) { if (h[i][j] == '#') dp[i][j] = 0; else dp[i][j] = ((dp[i - 1][j]) % mod + (dp[i][j - 1]) % mod) % mod; } } cout << dp[m - 1][n - 1]; }
replace
29
30
29
30
-11
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define im 2147483647 #define lm 9223372036854775807 #define ll long long #define ii pair<int, int> #define debug(index, num) cerr << "Case #" << index << ": " << num << endl #define be(x) x.begin(), x.end() #define rbe(x) x.rbegin(), x.rend() #define pb push_back const ll MOD = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; vector<vector<char>> g(n + 2, vector<char>(n + 2, '#')); vector<vector<ll>> dp(n + 2, vector<ll>(m + 2, 0)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> g[i][j]; } } dp[1][1] = 1; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (g[i][j] == '#') dp[i][j] = 0; else dp[i][j] += dp[i - 1][j] + dp[i][j - 1]; if (dp[i][j] >= MOD) dp[i][j] -= MOD; } } cout << dp[n][m]; }
#include <bits/stdc++.h> using namespace std; #define im 2147483647 #define lm 9223372036854775807 #define ll long long #define ii pair<int, int> #define debug(index, num) cerr << "Case #" << index << ": " << num << endl #define be(x) x.begin(), x.end() #define rbe(x) x.rbegin(), x.rend() #define pb push_back const ll MOD = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, m; cin >> n >> m; vector<vector<char>> g(n + 2, vector<char>(m + 2, '#')); vector<vector<ll>> dp(n + 2, vector<ll>(m + 2, 0)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { cin >> g[i][j]; } } dp[1][1] = 1; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { if (g[i][j] == '#') dp[i][j] = 0; else dp[i][j] += dp[i - 1][j] + dp[i][j - 1]; if (dp[i][j] >= MOD) dp[i][j] -= MOD; } } cout << dp[n][m]; }
replace
17
18
17
18
0
p03167
C++
Runtime Error
/****************************************************************************** Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debug online from anywhere in world. *******************************************************************************/ #include <cstdlib> #include <iostream> #include <stdio.h> using namespace std; int main() { int i, h, w, j; char t; scanf("%d %d ", &h, &w); int a[h + 1][w + 1]; for (i = 0; i <= w; i++) { a[0][i] = 0; } for (j = 0; j <= h; j++) { a[j][0] = 0; } for (i = 1; i <= h; i++) { for (j = 1; j <= w; j++) { scanf("%c", &t); if (t == '.') { a[i][j] = ((a[i][j - 1]) + (a[i - 1][j])); } else { a[i][j] = 0; } a[1][1] = 1; a[i][j] = a[i][j] % 1000000007; } scanf("%c", &t); } for (i = 0; i <= w; i++) { for (j = 0; j <= h; j++) { printf("%d ", a[i][j]); } printf("\n"); } }
/****************************************************************************** Welcome to GDB Online. GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl, C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog. Code, Compile, Run and Debug online from anywhere in world. *******************************************************************************/ #include <cstdlib> #include <iostream> #include <stdio.h> using namespace std; int main() { int i, h, w, j; char t; scanf("%d %d ", &h, &w); int a[h + 1][w + 1]; for (i = 0; i <= w; i++) { a[0][i] = 0; } for (j = 0; j <= h; j++) { a[j][0] = 0; } for (i = 1; i <= h; i++) { for (j = 1; j <= w; j++) { scanf("%c", &t); if (t == '.') { a[i][j] = ((a[i][j - 1]) + (a[i - 1][j])); } else { a[i][j] = 0; } a[1][1] = 1; a[i][j] = a[i][j] % 1000000007; } scanf("%c", &t); } printf("%d ", a[h][w]); }
replace
42
49
42
43
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define endl "\n" #define vi vector<int> #define vvi vector<vector<int>> #define FASTIO \ ios_base::sync_with_stdio(NULL); \ cin.tie(NULL); #define FOR(i, n) for (int i = 0; i < n; i++) #define FORE(i, a, b) for (int i = a; i <= b; i++) #define pb push_back #define MOD 1000000007 using namespace std; void init() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } // code from below void solve() { int n, m; cin >> n >> m; char arr[n][m]; FOR(i, n) FOR(j, m) cin >> arr[i][j]; int dp[n][m]; memset(dp, 0, sizeof(dp)); // dp[i][j] denotes no. of ways to go from i,j to n,m // fill the last row with 1 and last col with 1 for (int i = m - 1; i >= 0 and arr[n - 1][i] != '#'; i--) dp[n - 1][i] = 1; for (int i = n - 1; i >= 0 and arr[m - 1][i] != '#'; i--) dp[i][m - 1] = 1; // fill the remaining dp array for (int i = n - 2; i >= 0; i--) { for (int j = m - 2; j >= 0; j--) { if (arr[i][j] != '#') { dp[i][j] = ((ll)dp[i + 1][j] + (ll)dp[i][j + 1]) % MOD; } } } // for(int i=0;i<n;i++,cout<<endl) // for(int j=0;j<m;j++) // cout<<dp[i][j]<<" "; cout << dp[0][0] << endl; } int main() { int t = 1; // cin>>t; // cin.ignore(numeric_limits<streamsize>::max(),'\n'); while (t--) solve(); }
#include <bits/stdc++.h> #define ll long long #define endl "\n" #define vi vector<int> #define vvi vector<vector<int>> #define FASTIO \ ios_base::sync_with_stdio(NULL); \ cin.tie(NULL); #define FOR(i, n) for (int i = 0; i < n; i++) #define FORE(i, a, b) for (int i = a; i <= b; i++) #define pb push_back #define MOD 1000000007 using namespace std; void init() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } // code from below void solve() { int n, m; cin >> n >> m; char arr[n][m]; FOR(i, n) FOR(j, m) cin >> arr[i][j]; int dp[n][m]; memset(dp, 0, sizeof(dp)); // dp[i][j] denotes no. of ways to go from i,j to n,m // fill the last row with 1 and last col with 1 for (int i = m - 1; i >= 0 and arr[n - 1][i] != '#'; i--) dp[n - 1][i] = 1; for (int i = n - 1; i >= 0 and arr[i][m - 1] != '#'; i--) dp[i][m - 1] = 1; // fill the remaining dp array for (int i = n - 2; i >= 0; i--) { for (int j = m - 2; j >= 0; j--) { if (arr[i][j] != '#') { dp[i][j] = ((ll)dp[i + 1][j] + (ll)dp[i][j + 1]) % MOD; } } } // for(int i=0;i<n;i++,cout<<endl) // for(int j=0;j<m;j++) // cout<<dp[i][j]<<" "; cout << dp[0][0] << endl; } int main() { int t = 1; // cin>>t; // cin.ignore(numeric_limits<streamsize>::max(),'\n'); while (t--) solve(); }
replace
39
40
39
40
0
p03167
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define M 1000000007 void fast_io() { ios_base::sync_with_stdio(false); cin.tie(NULL); } void test_here() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } ll no_of_paths_bu(vector<vector<char>> &grid, ll r, ll c) { vector<vector<ll>> dp(r + 1, vector<ll>(c + 1, 0)); dp[r][c] = 1; for (ll i = r; i >= 1; i--) { for (ll j = c; j >= 1; j--) { if (i == r && j == c) continue; if (grid[i - 1][j - 1] != '.') dp[i][j] = 0; else dp[i][j] = ((i + 1 <= r ? dp[i + 1][j] : 0) + (j + 1 <= c ? dp[i][j + 1] : 0)) % M; } } return dp[1][1]; } void qH() { ll h, w; cin >> h >> w; vector<vector<char>> grid(h + 1, vector<char>(w + 1)); for (ll i = 0; i < h; i++) for (ll j = 0; j < w; j++) cin >> grid[i][j]; cout << no_of_paths_bu(grid, h, w); /* vector< vector<ll> > dp(h+1, vector<ll>(w+1,-1)); cout<<no_of_paths(grid,h,w,dp,0,0);*/ } int main() { test_here(); qH(); }
#include <bits/stdc++.h> using namespace std; #define ll long long #define M 1000000007 void fast_io() { ios_base::sync_with_stdio(false); cin.tie(NULL); } void test_here() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); } ll no_of_paths_bu(vector<vector<char>> &grid, ll r, ll c) { vector<vector<ll>> dp(r + 1, vector<ll>(c + 1, 0)); dp[r][c] = 1; for (ll i = r; i >= 1; i--) { for (ll j = c; j >= 1; j--) { if (i == r && j == c) continue; if (grid[i - 1][j - 1] != '.') dp[i][j] = 0; else dp[i][j] = ((i + 1 <= r ? dp[i + 1][j] : 0) + (j + 1 <= c ? dp[i][j + 1] : 0)) % M; } } return dp[1][1]; } void qH() { ll h, w; cin >> h >> w; vector<vector<char>> grid(h + 1, vector<char>(w + 1)); for (ll i = 0; i < h; i++) for (ll j = 0; j < w; j++) cin >> grid[i][j]; cout << no_of_paths_bu(grid, h, w); /* vector< vector<ll> > dp(h+1, vector<ll>(w+1,-1)); cout<<no_of_paths(grid,h,w,dp,0,0);*/ } int main() { // test_here(); qH(); }
replace
51
52
51
52
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p03168
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define fi first #define se second #define pb push_back using namespace std; typedef long long LL; typedef pair<int, int> pii; double memo[3005][3005]; double datas[3005]; int n; double solve(int x, int y) { if (x + y == n) { if (x > y) return 1.00; else return 0.00; } if (memo[x][y] > 0.00) return memo[x][y]; return memo[x][y] = datas[x + y] * solve(x + 1, y) + (1 - datas[x + y]) * solve(x, y + 1); } int main() { scanf("%d", &n); for (int a = 0; a < n; a++) { scanf("%lf", &datas[a]); } for (int a = 0; a <= 3000; a++) { for (int b = 0; b <= 3000; b++) { memo[a][b] = -1.00; } } printf("%.10lf\n", solve(0, 0)); return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define pb push_back using namespace std; typedef long long LL; typedef pair<int, int> pii; double memo[3005][3005]; double datas[3005]; int n; double solve(int x, int y) { if (x + y == n) { if (x > y) return 1.00; else return 0.00; } if (memo[x][y] > -1.00) return memo[x][y]; return memo[x][y] = datas[x + y] * solve(x + 1, y) + (1 - datas[x + y]) * solve(x, y + 1); } int main() { scanf("%d", &n); for (int a = 0; a < n; a++) { scanf("%lf", &datas[a]); } for (int a = 0; a <= 3000; a++) { for (int b = 0; b <= 3000; b++) { memo[a][b] = -1.00; } } printf("%.10lf\n", solve(0, 0)); return 0; }
replace
18
19
18
19
TLE
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 int dx[2] = {1, 0}; int dy[2] = {0, 1}; double p[3000]; double dp[1000][1000] = {}; int main() { int N; cin >> N; for (int i = 0; i < N; ++i) { cin >> p[i]; } dp[0][0] = 1; for (int i = 0; i < N; ++i) { for (int j = 0; i + j < N; ++j) { dp[i][j + 1] += dp[i][j] * p[i + j]; dp[i + 1][j] += dp[i][j] * (1 - p[i + j]); } } double res = 0; for (int i = N; i > N / 2; --i) res += dp[N - i][i]; printf("%.10f\n", res); return 0; }
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 int dx[2] = {1, 0}; int dy[2] = {0, 1}; double p[3000]; double dp[3000][3000] = {}; int main() { int N; cin >> N; for (int i = 0; i < N; ++i) { cin >> p[i]; } dp[0][0] = 1; for (int i = 0; i < N; ++i) { for (int j = 0; i + j < N; ++j) { dp[i][j + 1] += dp[i][j] * p[i + j]; dp[i + 1][j] += dp[i][j] * (1 - p[i + j]); } } double res = 0; for (int i = N; i > N / 2; --i) res += dp[N - i][i]; printf("%.10f\n", res); return 0; }
replace
6
7
6
7
0
p03168
C++
Time Limit Exceeded
/* Pain. Anger. Hatred. Ego. Survive. Live. Win. Conquer. */ /*#Quota_Reform . #We_Want_Safe_Roads . #We_Want_Justice . #Support_Us . #Bangladesh . */ #include <bits/stdc++.h> using namespace std; typedef long long LL; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> #define ook order_of_key #define fbk find_by_order #define bug printf("Massacre.\n"); #define pf printf #define sf scanf #define pb push_back #define r0 return 0 #define ff first #define ss second #define mp make_pair #define set0(a) memset((a), 0, sizeof(a)) #define set1(a) memset((a), -1, sizeof(a)) #define si(a) scanf("%d", &a) #define sl(a) scanf("%lld", &a) #define sii(a, b) scanf("%d %d", &a, &b) #define siii(a, b, c) scanf("%d %d %d", &a, &b, &c) #define sll(a, b) scanf("%lld %lld", &a, &b) #define slll(a, b, c) scanf("%lld %lld %lld", &a, &b, &c) #define pll pair<LL, LL> #define pii pair<int, int> #define vi vector<int> #define vl vector<LL> #define all(x) (x).begin(), (x).end() #define vii vector<pair<int, int>> #define vll vector<pair<LL, LL>> #define mod 1000000007 // using namespace __gnu_pbds; // typedef tree < int, null_type // ,less<int>,rb_tree_tag,tree_order_statistics_node_update > ordered_set; void func(void) { freopen("input.c", "r", stdin); freopen("output.c", "w", stdout); } void print(vector<LL> &v) { cout << v.size() << endl; for (int i = 0; i < v.size(); i++) { pf("%lld ", v[i]); } pf("\n"); } void print(vector<pll> &v) { cout << v.size() << endl; for (int i = 0; i < v.size(); i++) { pf("%lld %lld\n", v[i].ff, v[i].ss); } } void print(double d) { cout << fixed << setprecision(10) << d << endl; } void print(string s, double d) { cout << s << " "; cout << fixed << setprecision(10) << d << endl; } const int N = 3000; double dp[N][N]; bool vis[N][N]; LL n; double a[N]; double calc(LL i, LL j) { if (i == n) { if (j * 2 >= n) return 1.0; return 0.0; } if (vis[i][j]) return dp[i][j]; return dp[i][j] = a[i] * calc(i + 1, j + 1) + (1.0 - a[i]) * calc(i + 1, j); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); LL q, i, j = 0, temp, t, k, ans = 0, sum = 0, x, y, z, cnt = 0, m, fg = 0, mx = 0, mx1 = 0, mn = 8000000000000000000, mn1 = 8000000000000000000; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } cout << fixed << setprecision(10) << calc(0, 0) << endl; }
/* Pain. Anger. Hatred. Ego. Survive. Live. Win. Conquer. */ /*#Quota_Reform . #We_Want_Safe_Roads . #We_Want_Justice . #Support_Us . #Bangladesh . */ #include <bits/stdc++.h> using namespace std; typedef long long LL; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> #define ook order_of_key #define fbk find_by_order #define bug printf("Massacre.\n"); #define pf printf #define sf scanf #define pb push_back #define r0 return 0 #define ff first #define ss second #define mp make_pair #define set0(a) memset((a), 0, sizeof(a)) #define set1(a) memset((a), -1, sizeof(a)) #define si(a) scanf("%d", &a) #define sl(a) scanf("%lld", &a) #define sii(a, b) scanf("%d %d", &a, &b) #define siii(a, b, c) scanf("%d %d %d", &a, &b, &c) #define sll(a, b) scanf("%lld %lld", &a, &b) #define slll(a, b, c) scanf("%lld %lld %lld", &a, &b, &c) #define pll pair<LL, LL> #define pii pair<int, int> #define vi vector<int> #define vl vector<LL> #define all(x) (x).begin(), (x).end() #define vii vector<pair<int, int>> #define vll vector<pair<LL, LL>> #define mod 1000000007 // using namespace __gnu_pbds; // typedef tree < int, null_type // ,less<int>,rb_tree_tag,tree_order_statistics_node_update > ordered_set; void func(void) { freopen("input.c", "r", stdin); freopen("output.c", "w", stdout); } void print(vector<LL> &v) { cout << v.size() << endl; for (int i = 0; i < v.size(); i++) { pf("%lld ", v[i]); } pf("\n"); } void print(vector<pll> &v) { cout << v.size() << endl; for (int i = 0; i < v.size(); i++) { pf("%lld %lld\n", v[i].ff, v[i].ss); } } void print(double d) { cout << fixed << setprecision(10) << d << endl; } void print(string s, double d) { cout << s << " "; cout << fixed << setprecision(10) << d << endl; } const int N = 3000; double dp[N][N]; bool vis[N][N]; LL n; double a[N]; double calc(LL i, LL j) { if (i == n) { if (j * 2 >= n) return 1.0; return 0.0; } if (vis[i][j]) return dp[i][j]; vis[i][j] = 1; return dp[i][j] = a[i] * calc(i + 1, j + 1) + (1.0 - a[i]) * calc(i + 1, j); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); LL q, i, j = 0, temp, t, k, ans = 0, sum = 0, x, y, z, cnt = 0, m, fg = 0, mx = 0, mx1 = 0, mn = 8000000000000000000, mn1 = 8000000000000000000; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } cout << fixed << setprecision(10) << calc(0, 0) << endl; }
insert
88
88
88
89
TLE
p03168
C++
Runtime Error
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdlib> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <ostream> #include <queue> #include <random> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> using namespace std; #define for0(i, n) for (int i = 0; i < n; i++) #define for1(i, n) for (int i = 1; i <= n; i++) #define pb push_back #define mp make_pair #define all(v) v.begin(), v.end() #define V vector<int> #define VP vector<pair<int, int>> #define FASTIO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define index INDEX #ifndef ONLINE_JUDGE #define print(x) PRINT(x, #x) template <typename T> void PRINT(T VARIABLE, const string &NAME) { cerr << NAME << " = " << fixed << VARIABLE << "\n"; } #else #define print(x) 0 #endif int generate_random() { const int MAX_RANDOM = (int)1e6; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); return uniform_int_distribution<int>(0, MAX_RANDOM)(rng); } typedef long long ll; typedef unsigned long long ull; typedef long double ld; const ll INFLL = 2 * (ll)1e18 + 100; #define int ll #ifdef int const int INFINT = INFLL; #else const int INFINT = 2 * (int)1e9 + 100; #endif const double PI = atan(1) * 4; const double EPS = 1e-6; const int SEED = (int)1e3 + 7; const int MOD = (int)1e9 + 7; const int NMAX = (int)1e3 + 5; double p[NMAX]; double dp[NMAX][NMAX]; int32_t main() { #ifndef ONLINE_JUDGE double START_PROGRAM = clock(); #endif srand(time(NULL)); cout << setprecision(20) << fixed; FASTIO; int n; cin >> n; for1(i, n) cin >> p[i]; dp[1][1] = p[1]; dp[1][0] = 1 - p[1]; for (int i = 2; i <= n; i++) { dp[i][0] = dp[i - 1][0] * (1 - p[i]); for1(j, i) dp[i][j] = dp[i - 1][j] * (1 - p[i]) + dp[i - 1][j - 1] * p[i]; } double sol = 0; for (int j = n / 2 + 1; j <= n; j++) sol += dp[n][j]; cout << sol; #ifndef ONLINE_JUDGE double END_PROGRAM = clock(); double ELAPSED_TIME = (END_PROGRAM - START_PROGRAM) / CLOCKS_PER_SEC; cerr << "\n\nElapsed Time: " << ELAPSED_TIME * 1000 << "\n"; #endif return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cassert> #include <chrono> #include <cmath> #include <complex> #include <cstdlib> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <ostream> #include <queue> #include <random> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> using namespace std; #define for0(i, n) for (int i = 0; i < n; i++) #define for1(i, n) for (int i = 1; i <= n; i++) #define pb push_back #define mp make_pair #define all(v) v.begin(), v.end() #define V vector<int> #define VP vector<pair<int, int>> #define FASTIO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define index INDEX #ifndef ONLINE_JUDGE #define print(x) PRINT(x, #x) template <typename T> void PRINT(T VARIABLE, const string &NAME) { cerr << NAME << " = " << fixed << VARIABLE << "\n"; } #else #define print(x) 0 #endif int generate_random() { const int MAX_RANDOM = (int)1e6; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); return uniform_int_distribution<int>(0, MAX_RANDOM)(rng); } typedef long long ll; typedef unsigned long long ull; typedef long double ld; const ll INFLL = 2 * (ll)1e18 + 100; #define int ll #ifdef int const int INFINT = INFLL; #else const int INFINT = 2 * (int)1e9 + 100; #endif const double PI = atan(1) * 4; const double EPS = 1e-6; const int SEED = (int)1e3 + 7; const int MOD = (int)1e9 + 7; const int NMAX = (int)3 * 1e3 + 5; double p[NMAX]; double dp[NMAX][NMAX]; int32_t main() { #ifndef ONLINE_JUDGE double START_PROGRAM = clock(); #endif srand(time(NULL)); cout << setprecision(20) << fixed; FASTIO; int n; cin >> n; for1(i, n) cin >> p[i]; dp[1][1] = p[1]; dp[1][0] = 1 - p[1]; for (int i = 2; i <= n; i++) { dp[i][0] = dp[i - 1][0] * (1 - p[i]); for1(j, i) dp[i][j] = dp[i - 1][j] * (1 - p[i]) + dp[i - 1][j - 1] * p[i]; } double sol = 0; for (int j = n / 2 + 1; j <= n; j++) sol += dp[n][j]; cout << sol; #ifndef ONLINE_JUDGE double END_PROGRAM = clock(); double ELAPSED_TIME = (END_PROGRAM - START_PROGRAM) / CLOCKS_PER_SEC; cerr << "\n\nElapsed Time: " << ELAPSED_TIME * 1000 << "\n"; #endif return 0; }
replace
70
71
70
71
0
Elapsed Time: 0.195
p03168
C++
Runtime Error
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> // #include<bits/extc++.h> using namespace std; // using namespace __gnu_pbds; // typedef // tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> // set_t; #define mp(a, b) make_pair((a), (b)) #define pii pair<int, int> #define pll pair<LL, LL> #define pdd pair<double, double> #define pb push_back #define x first #define y second #define sqr(x) ((x) * (x)) #define EPS 1e-6 #define MEM(x) memset(x, 0, sizeof(x)) #define MEMS(x) memset(x, -1, sizeof(x)) #define pi acos(-1) #define index Index #define Line pll typedef long long LL; double dp[3005][3005]; int main() { int n; scanf("%d", &n); double p[1005]; for (int i = 1; i <= n; i++) { scanf("%lf", &p[i]); } dp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j <= i; j++) { if (j == 0) { dp[i][j] = dp[i - 1][j] * (1 - p[i]); } else dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]); } } double ans = 0; for (int i = n / 2 + 1; i <= n; i++) ans += dp[n][i]; printf("%.12f\n", ans); }
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> // #include<bits/extc++.h> using namespace std; // using namespace __gnu_pbds; // typedef // tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> // set_t; #define mp(a, b) make_pair((a), (b)) #define pii pair<int, int> #define pll pair<LL, LL> #define pdd pair<double, double> #define pb push_back #define x first #define y second #define sqr(x) ((x) * (x)) #define EPS 1e-6 #define MEM(x) memset(x, 0, sizeof(x)) #define MEMS(x) memset(x, -1, sizeof(x)) #define pi acos(-1) #define index Index #define Line pll typedef long long LL; double dp[3005][3005]; int main() { int n; scanf("%d", &n); double p[3005]; for (int i = 1; i <= n; i++) { scanf("%lf", &p[i]); } dp[0][0] = 1; for (int i = 1; i <= n; i++) { for (int j = 0; j <= i; j++) { if (j == 0) { dp[i][j] = dp[i - 1][j] * (1 - p[i]); } else dp[i][j] = dp[i - 1][j - 1] * p[i] + dp[i - 1][j] * (1 - p[i]); } } double ans = 0; for (int i = n / 2 + 1; i <= n; i++) ans += dp[n][i]; printf("%.12f\n", ans); }
replace
28
29
28
29
0
p03168
C++
Time Limit Exceeded
/* Washief Hossain Mugdho 17 September 2020 Educational DP Coins */ #ifndef DEBUG #pragma GCC optimize("O3") #endif #include <bits/stdc++.h> #define ull unsigned long long #define ll long long #define pb push_back #define mp make_pair #define fr first #define sc second #define fastio ios_base::sync_with_stdio(0) #define untie cin.tie(0) #define ms(a, b) memset(a, b, sizeof a) using namespace std; bool visited[3005][3005]; double memo[3005][3005]; double arr[3005]; int n; double dp(int a, int b) { if (a >= n && b != 0) return 0.0; if (visited[a][b]) return memo[a][b]; visited[a][b]; if (b == 0) { double res = 1.0; for (int i = a; i < n; i++) res *= (1 - arr[i]); return memo[a][b] = res; } return memo[a][b] = (1.0 - arr[a]) * dp(a + 1, b) + arr[a] * dp(a + 1, b - 1); } int main() { #ifdef LOCAL_OUTPUT freopen(LOCAL_OUTPUT, "w", stdout); #endif #ifdef LOCAL_INPUT freopen(LOCAL_INPUT, "r", stdin); #endif cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; int m = n / 2 + 1; double res = 0.0; for (int i = m; i <= n; i++) res += dp(0, i); cout << fixed << setprecision(12) << res << endl; }
/* Washief Hossain Mugdho 17 September 2020 Educational DP Coins */ #ifndef DEBUG #pragma GCC optimize("O3") #endif #include <bits/stdc++.h> #define ull unsigned long long #define ll long long #define pb push_back #define mp make_pair #define fr first #define sc second #define fastio ios_base::sync_with_stdio(0) #define untie cin.tie(0) #define ms(a, b) memset(a, b, sizeof a) using namespace std; bool visited[3005][3005]; double memo[3005][3005]; double arr[3005]; int n; double dp(int a, int b) { if (a >= n && b != 0) return 0.0; if (visited[a][b]) return memo[a][b]; visited[a][b] = 1; if (b == 0) { double res = 1.0; for (int i = a; i < n; i++) res *= (1 - arr[i]); return memo[a][b] = res; } return memo[a][b] = (1.0 - arr[a]) * dp(a + 1, b) + arr[a] * dp(a + 1, b - 1); } int main() { #ifdef LOCAL_OUTPUT freopen(LOCAL_OUTPUT, "w", stdout); #endif #ifdef LOCAL_INPUT freopen(LOCAL_INPUT, "r", stdin); #endif cin >> n; for (int i = 0; i < n; i++) cin >> arr[i]; int m = n / 2 + 1; double res = 0.0; for (int i = m; i <= n; i++) res += dp(0, i); cout << fixed << setprecision(12) << res << endl; }
replace
31
32
31
32
TLE
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef vector<int> VI; typedef pair<int, int> ii; typedef long long LL; #define pb push_back const int INF = 2147483647; const int MOD = 1000000007; const int N = 3006; double T[2][N], sum, p; int act, prevv, i, j, n; int main() { scanf("%d", &n); T[0][n] = 1.0; for (i = 1; i <= n; i++) { scanf("%lf", &p); act = i % 2; prevv = 1 - act; T[act][n - i] = T[prevv][n - i + 1] * p; for (j = n - i + 2; j <= n + i - 2; j++) T[act][j] = T[prevv][j + 1] * p + T[prevv][j - 1] * (1 - p); T[act][n + i] = T[prevv][n + i - 1] * (1 - p); } sum = 0.0; for (j = 0; j < n; j += 2) sum += T[act][j]; printf("%.11lf\n", sum); return 0; }
#include <bits/stdc++.h> using namespace std; typedef vector<int> VI; typedef pair<int, int> ii; typedef long long LL; #define pb push_back const int INF = 2147483647; const int MOD = 1000000007; const int N = 6006; double T[2][N], sum, p; int act, prevv, i, j, n; int main() { scanf("%d", &n); T[0][n] = 1.0; for (i = 1; i <= n; i++) { scanf("%lf", &p); act = i % 2; prevv = 1 - act; T[act][n - i] = T[prevv][n - i + 1] * p; for (j = n - i + 2; j <= n + i - 2; j++) T[act][j] = T[prevv][j + 1] * p + T[prevv][j - 1] * (1 - p); T[act][n + i] = T[prevv][n + i - 1] * (1 - p); } sum = 0.0; for (j = 0; j < n; j += 2) sum += T[act][j]; printf("%.11lf\n", sum); return 0; }
replace
8
9
8
9
0
p03168
C++
Time Limit Exceeded
/*###################################################### #########~~~~~####~~~~###~~##~~##~~##~~##~~##~~######### #########~~##~~##~~##~~##~~~#~~##~~~#~~##~~##~~######### #~~~~~~##~~~~~###~~~~~~##~~#~~~##~~#~~~##~~##~~##~~~~~~# #########~~######~~##~~##~~##~~##~~##~~##~~##~~######### #########~~######~~##~~##~~##~~##~~##~~###~~~~########## ######################################################*/ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #pragma comment(linker, "/stack:256000000") #pragma GCC optimize("O3") #define ll long long #define str string #define rtn return #define endl '\n' #define F first #define S second #define pb push_back #define db long double #define MOD 1000000007 #define INF 1e18 #define EPS 1e-15 #define pll pair<ll, ll> #define vi vector<ll> #define vpll vector<pll> #define value_at find_by_order #define index_of order_of_key #define fill(a, v) memset(a, v, sizeof(a)) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i, n) for (ll i = 0; i < n; ++i) #define per(i, n) for (ll i = n - 1; i >= 0; --i) #define loop1(i, n) for (int i = 1; i <= n; ++i) #define loop(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define FAST_IO \ std::ios_base::sync_with_stdio(false); \ std::cin.tie(NULL); \ std::cout.tie(NULL) #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " = " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " |"; __f(comma + 1, args...); } #else #define trace(...) #endif template <class T> void remin(T &a, T b) { a = min(a, b); } template <class T> void remax(T &a, T b) { a = max(a, b); } template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define N 100005 db dp[3005][3005], p[3000], rec[3000]; bool sol[3005][3005]; int n; db solve(int i, int head) { if (head < 0) rtn 0; if (i == n) { if (head == 0) rtn 1; else rtn 0; } if (sol[i][head]) rtn dp[i][head]; dp[i][head] = 0; dp[i][head] += p[i] * solve(i + 1, head - 1); dp[i][head] += (1 - p[i]) * solve(i + 1, head); rtn dp[i][head]; } int main() { FAST_IO; db ans = 0; cin >> n; rep(i, n) cin >> p[i]; loop1(i, n) { int tails = n - i; if (i > tails) { ans += solve(0, i); } } cout << fixed << setprecision(12) << ans; rtn 0; }
/*###################################################### #########~~~~~####~~~~###~~##~~##~~##~~##~~##~~######### #########~~##~~##~~##~~##~~~#~~##~~~#~~##~~##~~######### #~~~~~~##~~~~~###~~~~~~##~~#~~~##~~#~~~##~~##~~##~~~~~~# #########~~######~~##~~##~~##~~##~~##~~##~~##~~######### #########~~######~~##~~##~~##~~##~~##~~###~~~~########## ######################################################*/ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #pragma comment(linker, "/stack:256000000") #pragma GCC optimize("O3") #define ll long long #define str string #define rtn return #define endl '\n' #define F first #define S second #define pb push_back #define db long double #define MOD 1000000007 #define INF 1e18 #define EPS 1e-15 #define pll pair<ll, ll> #define vi vector<ll> #define vpll vector<pll> #define value_at find_by_order #define index_of order_of_key #define fill(a, v) memset(a, v, sizeof(a)) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep(i, n) for (ll i = 0; i < n; ++i) #define per(i, n) for (ll i = n - 1; i >= 0; --i) #define loop1(i, n) for (int i = 1; i <= n; ++i) #define loop(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define FAST_IO \ std::ios_base::sync_with_stdio(false); \ std::cin.tie(NULL); \ std::cout.tie(NULL) #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " = " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " = " << arg1 << " |"; __f(comma + 1, args...); } #else #define trace(...) #endif template <class T> void remin(T &a, T b) { a = min(a, b); } template <class T> void remax(T &a, T b) { a = max(a, b); } template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define N 100005 db dp[3005][3005], p[3000], rec[3000]; bool sol[3005][3005]; int n; db solve(int i, int head) { if (head < 0) rtn 0; if (i == n) { if (head == 0) rtn 1; else rtn 0; } if (sol[i][head]) rtn dp[i][head]; sol[i][head] = 1; dp[i][head] = 0; dp[i][head] += p[i] * solve(i + 1, head - 1); dp[i][head] += (1 - p[i]) * solve(i + 1, head); rtn dp[i][head]; } int main() { FAST_IO; db ans = 0; cin >> n; rep(i, n) cin >> p[i]; loop1(i, n) { int tails = n - i; if (i > tails) { ans += solve(0, i); } } cout << fixed << setprecision(12) << ans; rtn 0; }
insert
83
83
83
84
TLE
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define maxx 10 int n; double p[maxx]; double dp[maxx][maxx]; double f(int n, int x) { if (x == 0) return 1.0; if (n == 1) { return p[n]; } if (dp[n][x] != -1) return dp[n][x]; if (n == x) { dp[n][x] = p[n] * f(n - 1, x - 1); return dp[n][x]; } dp[n][x] = p[n] * f(n - 1, x - 1) + (1 - p[n]) * f(n - 1, x); return dp[n][x]; } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> p[i]; for (int i = 0; i < maxx; i++) for (int j = 0; j < maxx; j++) dp[i][j] = -1; cout << fixed << setprecision(10) << f(n, (n + 1) / 2); }
#include <bits/stdc++.h> using namespace std; #define maxx 3000 int n; double p[maxx]; double dp[maxx][maxx]; double f(int n, int x) { if (x == 0) return 1.0; if (n == 1) { return p[n]; } if (dp[n][x] != -1) return dp[n][x]; if (n == x) { dp[n][x] = p[n] * f(n - 1, x - 1); return dp[n][x]; } dp[n][x] = p[n] * f(n - 1, x - 1) + (1 - p[n]) * f(n - 1, x); return dp[n][x]; } int main() { cin >> n; for (int i = 1; i <= n; i++) cin >> p[i]; for (int i = 0; i < maxx; i++) for (int j = 0; j < maxx; j++) dp[i][j] = -1; cout << fixed << setprecision(10) << f(n, (n + 1) / 2); }
replace
2
3
2
3
0
p03168
C++
Time Limit Exceeded
#include <iomanip> #include <iostream> #include <vector> using namespace std; double dp[3001][3001]; double helper(int numheads, int i, vector<double> &prob, int n) { if (dp[i][numheads] > -1) { return dp[i][numheads]; } if (i >= n) { if (numheads <= n / 2) { return 0; } else return 1; } else { return prob[i] * helper(numheads + 1, i + 1, prob, n) + helper(numheads, i + 1, prob, n) * (1 - prob[i]); } } int main() { int n; cin >> n; vector<double> prob(n); for (int i = 0; i < n; i++) { cin >> prob[i]; } double ans = 0; for (int i = 0; i < 3001; i++) { for (int j = 0; j < 3001; j++) { dp[i][j] = -1; } } cout << setprecision(15); cout << helper(0, 0, prob, n); }
#include <iomanip> #include <iostream> #include <vector> using namespace std; double dp[3001][3001]; double helper(int numheads, int i, vector<double> &prob, int n) { if (dp[i][numheads] > -1) { return dp[i][numheads]; } if (i >= n) { if (numheads <= n / 2) { return 0; } else return 1; } else { dp[i][numheads] = prob[i] * helper(numheads + 1, i + 1, prob, n) + helper(numheads, i + 1, prob, n) * (1 - prob[i]); return dp[i][numheads]; } } int main() { int n; cin >> n; vector<double> prob(n); for (int i = 0; i < n; i++) { cin >> prob[i]; } double ans = 0; for (int i = 0; i < 3001; i++) { for (int j = 0; j < 3001; j++) { dp[i][j] = -1; } } cout << setprecision(15); cout << helper(0, 0, prob, n); }
replace
15
17
15
18
TLE
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define mp make_pair #define nt _int128 #define mod 1000000007 double arr[3005], dp[3005][3005]; ll n; double func(ll i, ll k) { if (i == n + 1) { if (k == 0) return 1.0; else return 0.0; } else if (dp[i][k] != -1.0) { return dp[i][k]; } double x = 0; if (k > 0) x += arr[i] * func(i + 1, k - 1); x += (1 - arr[i]) * func(i + 1, k); return dp[i][k] = x; } int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(false); cin.tie(NULL); ll t; // cin >> t; t = 1; while (t--) { cin >> n; for (ll i = 1; i <= n; i++) cin >> arr[i]; double x = 0; for (ll i = 1; i <= 3000; i++) { for (ll j = 0; j <= 3000; j++) dp[i][j] = -1.0; } for (ll i = n / 2 + 1; i <= n; i++) { x += func(1, i); } // for(ll i=1;i<=n;i++) // { // for(ll j=0;j<=2;j++) // cout<<dp[i][j]<<" "; // cout<<endl; // } cout << fixed << setprecision(10) << x; } return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define pb push_back #define mp make_pair #define nt _int128 #define mod 1000000007 double arr[3005], dp[3005][3005]; ll n; double func(ll i, ll k) { if (i == n + 1) { if (k == 0) return 1.0; else return 0.0; } else if (dp[i][k] != -1.0) { return dp[i][k]; } double x = 0; if (k > 0) x += arr[i] * func(i + 1, k - 1); x += (1 - arr[i]) * func(i + 1, k); return dp[i][k] = x; } int main() { // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif ios_base::sync_with_stdio(false); cin.tie(NULL); ll t; // cin >> t; t = 1; while (t--) { cin >> n; for (ll i = 1; i <= n; i++) cin >> arr[i]; double x = 0; for (ll i = 1; i <= 3000; i++) { for (ll j = 0; j <= 3000; j++) dp[i][j] = -1.0; } for (ll i = n / 2 + 1; i <= n; i++) { x += func(1, i); } // for(ll i=1;i<=n;i++) // { // for(ll j=0;j<=2;j++) // cout<<dp[i][j]<<" "; // cout<<endl; // } cout << fixed << setprecision(10) << x; } return 0; }
replace
26
30
26
30
0
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); cout.precision(10); int n; cin >> n; vector<vector<double>> dp(n + 1, vector<double>(n + 1)); vector<double> v(n + 1); for (int i = 1; i <= n; i++) cin >> v[i]; dp[0][0] = 1.0; for (int i = 1; i <= n; i++) { dp[i][0] = dp[i - 1][0] * (1 - v[i]); for (int j = 1; j <= i; j++) { dp[i][j] = dp[i - 1][j - 1] * v[i] + dp[i - 1][j] * (1 - v[i]); } } double ans = 0.0; for (int i = (n + 1) / 2; i <= n; i++) ans = ans + dp[n][i]; cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); cout.precision(10); int n; cin >> n; vector<vector<double>> dp(n + 1, vector<double>(n + 1)); vector<double> v(n + 1); for (int i = 1; i <= n; i++) cin >> v[i]; dp[0][0] = 1.0; for (int i = 1; i <= n; i++) { dp[i][0] = dp[i - 1][0] * (1 - v[i]); for (int j = 1; j <= i; j++) { dp[i][j] = dp[i - 1][j - 1] * v[i] + dp[i - 1][j] * (1 - v[i]); } } double ans = 0.0; for (int i = (n + 1) / 2; i <= n; i++) ans = ans + dp[n][i]; cout << ans << '\n'; return 0; }
replace
5
7
5
7
0
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define fr(i, a, b) for (int i = (a); i < (b); i++) #define frr(i, a, b) for (int i = (a - 1); i >= (b); i--) #define vi vector<int> #define de deque<int> #define del deque<ll> #define vl vector<ll> #define pb push_back #define ppb pop_back() #define pf push_front #define ppf pop_front() #define mp map<ll, ll> #define rev(a) reverse(a.begin(), a.end()) #define srt(a) sort(a.begin(), a.end()) #define rsrt(a) sort(a.begin(), a.end(), greater<int>()) #define ln(a) a.length() #define sz(a) a.size() ll M = 1e9 + 7; int n; double a[3001]; double dp[3001][3001]; int ready[3001][3001]; double solve(int ind, int num) { if (ready[ind][num]) return dp[ind][num]; if (ind == 0) { return 0.0; } if (num == 0) return (1 - a[ind]) * solve(ind - 1, num); ready[ind][num] = 1; return dp[ind][num] = a[ind] * solve(ind - 1, num - 1) + (1.0 - a[ind]) * solve(ind - 1, num); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif cin >> n; fr(i, 1, n + 1) cin >> a[i]; memset(ready, 0, sizeof ready); fr(i, 0, 3001) fr(j, 0, 3001) dp[i][j] = 0.0; ready[0][0] = 1; dp[0][0] = 1.0; double ans = 0; fr(i, 0, n + 1) { if (i > n / 2) ans += solve(n, i); } cout << setprecision(12) << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define fr(i, a, b) for (int i = (a); i < (b); i++) #define frr(i, a, b) for (int i = (a - 1); i >= (b); i--) #define vi vector<int> #define de deque<int> #define del deque<ll> #define vl vector<ll> #define pb push_back #define ppb pop_back() #define pf push_front #define ppf pop_front() #define mp map<ll, ll> #define rev(a) reverse(a.begin(), a.end()) #define srt(a) sort(a.begin(), a.end()) #define rsrt(a) sort(a.begin(), a.end(), greater<int>()) #define ln(a) a.length() #define sz(a) a.size() ll M = 1e9 + 7; int n; double a[3001]; double dp[3001][3001]; int ready[3001][3001]; double solve(int ind, int num) { if (ready[ind][num]) return dp[ind][num]; if (ind == 0) { return 0.0; } if (num == 0) return (1 - a[ind]) * solve(ind - 1, num); ready[ind][num] = 1; return dp[ind][num] = a[ind] * solve(ind - 1, num - 1) + (1.0 - a[ind]) * solve(ind - 1, num); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif cin >> n; fr(i, 1, n + 1) cin >> a[i]; memset(ready, 0, sizeof ready); fr(i, 0, 3001) fr(j, 0, 3001) dp[i][j] = 0.0; ready[0][0] = 1; dp[0][0] = 1.0; double ans = 0; fr(i, 0, n + 1) { if (i > n / 2) ans += solve(n, i); } cout << setprecision(12) << ans << endl; }
replace
43
47
43
47
-11
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define D(x) cerr << #x << " = " << (x) << ", " template <typename T> ostream &operator<<(ostream &_o_, const vector<T> &_v_) { if (!_v_.empty()) { _o_ << '['; copy(_v_.begin(), _v_.end(), ostream_iterator<T>(_o_, ", ")); _o_ << "\b\b]"; } return _o_; } #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) typedef unsigned int uint; typedef unsigned long ul; typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef unsigned char uchar; struct secure_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; template <typename T> using V = vector<T>; template <typename T, typename U> using umap = unordered_map<T, U, secure_hash>; template <typename T> using uset = unordered_set<T, secure_hash>; template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>; template <typename T> using max_heap = priority_queue<T>; int n; V<ld> p; V<V<ld>> dp; V<V<bool>> computed; ld f(int i, int k) { if (k < 0) return 0; if (i == n) { if (k == 0) return 1; return 0; } if (computed[i][k]) return dp[i][k]; ld a = f(i + 1, k - 1) * p[i]; ld b = f(i + 1, k) * (1 - p[i]); computed[i][k] = true; return dp[i][k] = a + b; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; p.resize(n); rep(i, 0, n) cin >> p[i]; computed.assign(n, V<bool>(n, false)); dp.resize(n, V<ld>(n)); ld ans = 0; rep(i, n / 2 + 1, n + 1) ans += f(0, i); cout << fixed << setprecision(14) << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define endl '\n' #define D(x) cerr << #x << " = " << (x) << ", " template <typename T> ostream &operator<<(ostream &_o_, const vector<T> &_v_) { if (!_v_.empty()) { _o_ << '['; copy(_v_.begin(), _v_.end(), ostream_iterator<T>(_o_, ", ")); _o_ << "\b\b]"; } return _o_; } #define rep(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) typedef unsigned int uint; typedef unsigned long ul; typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef unsigned char uchar; struct secure_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; template <typename T> using V = vector<T>; template <typename T, typename U> using umap = unordered_map<T, U, secure_hash>; template <typename T> using uset = unordered_set<T, secure_hash>; template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>; template <typename T> using max_heap = priority_queue<T>; int n; V<ld> p; V<V<ld>> dp; V<V<bool>> computed; ld f(int i, int k) { if (k < 0) return 0; if (i == n) { if (k == 0) return 1; return 0; } if (computed[i][k]) return dp[i][k]; ld a = f(i + 1, k - 1) * p[i]; ld b = f(i + 1, k) * (1 - p[i]); computed[i][k] = true; return dp[i][k] = a + b; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; p.resize(n); rep(i, 0, n) cin >> p[i]; computed.assign(n + 1, V<bool>(n + 1, false)); dp.resize(n + 1, V<ld>(n + 1)); ld ans = 0; rep(i, n / 2 + 1, n + 1) ans += f(0, i); cout << fixed << setprecision(14) << ans << endl; }
replace
67
69
67
69
-11
p03168
C++
Runtime Error
#include <algorithm> #include <climits> #include <cstring> #include <inttypes.h> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <utility> #include <vector> using namespace std; const int cap = 3000; int N; double p; double dp[cap]; int main() { scanf("%d", &N); fill(dp, dp + N + 1, 0); dp[0] = 1; for (int i = 1; i <= N; ++i) { scanf(" %lf", &p); for (int j = i; j > 0; --j) { dp[j] = dp[j] * (1 - p) + dp[j - 1] * p; } dp[0] *= 1 - p; } double ans = accumulate(dp + N / 2 + 1, dp + N * N + 1, (double)0); printf("%.10lf\n", ans); }
#include <algorithm> #include <climits> #include <cstring> #include <inttypes.h> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <utility> #include <vector> using namespace std; const int cap = 3000; int N; double p; double dp[cap]; int main() { scanf("%d", &N); fill(dp, dp + N + 1, 0); dp[0] = 1; for (int i = 1; i <= N; ++i) { scanf(" %lf", &p); for (int j = i; j > 0; --j) { dp[j] = dp[j] * (1 - p) + dp[j - 1] * p; } dp[0] *= 1 - p; } double ans = accumulate(dp + N / 2 + 1, dp + N + 1, (double)0); printf("%.10lf\n", ans); }
replace
29
30
29
30
0
p03168
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); i++) #define NFOR(i, a, b) for (ll i = (ll)(a); i >= (ll)(b); --i) #define rep(i, a) for (ll i = 0; i < a; i++) #define endl "\n" #define fi first #define se second #define MOD 1000000007 #define inf 1e12 #define pb push_back #define Case cout << "Case #" << ++cas << ": "; #define fastio \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define all(v) v.begin(), v.end() typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vl; typedef vector<vl> vvl; #define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__) template <class T> void dbs(string str, T t) { cerr << str << " : " << t << "\n"; } template <class T, class... S> void dbs(string str, T t, S... s) { int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...); } template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <class T> ostream &operator<<(ostream &os, const vector<T> &p) { os << "[ "; for (auto &it : p) os << it << " "; return os << "]"; } template <class T> ostream &operator<<(ostream &os, const multiset<T> &p) { os << "[ "; for (auto &it : p) os << it << " "; return os << "]"; } template <class S, class T> ostream &operator<<(ostream &os, const map<S, T> &p) { os << "[ "; for (auto &it : p) os << it << " "; return os << "]"; } template <class T> void prc(T a, T b) { cerr << "["; for (T i = a; i != b; ++i) { if (i != a) cerr << ", "; cerr << *i; } cerr << "]\n"; } void solve() { ll mod = 1000000007; ll n; cin >> n; vector<double> p(n); rep(i, n) cin >> p[i]; vector<vector<double>> dp(2, vector<double>(n + 1, 0)); dp[0][0] = 1.0; FOR(i, 1, n) FOR(j, 0, i) { dp[i % 2][j] = dp[(i + 1) % 2][j] * (1.0 - p[i - 1]) + ((j >= 1) ? dp[(i + 1) % 2][j - 1] * p[i - 1] : 0); pr(i, j, dp[i % 2][j]); } double ans = 0; FOR(i, n / 2 + 1, n) ans += dp[n % 2][i]; cout << setprecision(10) << fixed << ans << endl; } int main() { fastio; ll t = 1; // cin >> t; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); i++) #define NFOR(i, a, b) for (ll i = (ll)(a); i >= (ll)(b); --i) #define rep(i, a) for (ll i = 0; i < a; i++) #define endl "\n" #define fi first #define se second #define MOD 1000000007 #define inf 1e12 #define pb push_back #define Case cout << "Case #" << ++cas << ": "; #define fastio \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define all(v) v.begin(), v.end() typedef long long ll; typedef pair<ll, ll> pll; typedef vector<ll> vl; typedef vector<vl> vvl; #define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__) template <class T> void dbs(string str, T t) { cerr << str << " : " << t << "\n"; } template <class T, class... S> void dbs(string str, T t, S... s) { int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...); } template <class S, class T> ostream &operator<<(ostream &os, const pair<S, T> &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <class T> ostream &operator<<(ostream &os, const vector<T> &p) { os << "[ "; for (auto &it : p) os << it << " "; return os << "]"; } template <class T> ostream &operator<<(ostream &os, const multiset<T> &p) { os << "[ "; for (auto &it : p) os << it << " "; return os << "]"; } template <class S, class T> ostream &operator<<(ostream &os, const map<S, T> &p) { os << "[ "; for (auto &it : p) os << it << " "; return os << "]"; } template <class T> void prc(T a, T b) { cerr << "["; for (T i = a; i != b; ++i) { if (i != a) cerr << ", "; cerr << *i; } cerr << "]\n"; } void solve() { ll mod = 1000000007; ll n; cin >> n; vector<double> p(n); rep(i, n) cin >> p[i]; vector<vector<double>> dp(2, vector<double>(n + 1, 0)); dp[0][0] = 1.0; FOR(i, 1, n) FOR(j, 0, i) dp[i % 2][j] = dp[(i + 1) % 2][j] * (1.0 - p[i - 1]) + ((j >= 1) ? dp[(i + 1) % 2][j - 1] * p[i - 1] : 0); double ans = 0; FOR(i, n / 2 + 1, n) ans += dp[n % 2][i]; cout << setprecision(10) << fixed << ans << endl; } int main() { fastio; ll t = 1; // cin >> t; while (t--) { solve(); } }
replace
76
81
76
79
TLE
p03168
C++
Runtime Error
#include <iomanip> #include <iostream> #include <vector> #define prDouble(x) cout << fixed << setprecision(10) << x using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; vector<double> prob(n + 1); for (int i = 1; i <= n; ++i) cin >> prob[i]; int x = ((n + 1) / 2) + 1; double dp[n][x]; for (int i = 0; i <= n; ++i) { for (int j = 0; j < x; ++j) { if (i == 0 && j == 0) dp[i][j] = 1; else if (i == 0) dp[i][j] = 0; else if (j == 0) dp[i][j] = 1; else dp[i][j] = prob[i] * dp[i - 1][j - 1] + (1 - prob[i]) * dp[i - 1][j]; } } prDouble(dp[n][x - 1]); cout << "\n"; return 0; }
#include <iomanip> #include <iostream> #include <vector> #define prDouble(x) cout << fixed << setprecision(10) << x using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; vector<double> prob(n + 1); for (int i = 1; i <= n; ++i) cin >> prob[i]; int x = ((n + 1) / 2) + 1; double dp[n + 1][x]; for (int i = 0; i <= n; ++i) { for (int j = 0; j < x; ++j) { if (i == 0 && j == 0) dp[i][j] = 1; else if (i == 0) dp[i][j] = 0; else if (j == 0) dp[i][j] = 1; else dp[i][j] = prob[i] * dp[i - 1][j - 1] + (1 - prob[i]) * dp[i - 1][j]; } } prDouble(dp[n][x - 1]); cout << "\n"; return 0; }
replace
13
14
13
14
0
p03168
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; #define cool \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define int long long int #define pb push_back #define fe first #define lb lower_bound #define ub upper_bound #define pii pair<pair<int, int>, pair<int, int>> #define se second #define endl "\n" #define pi pair<int, int> #define vi vector<int> #define vvi vector<vi> #define bs binary_search #define rep(i, a, b) for (int i = a; i < b; i++) #define rep1(i, a, b) for (int i = a; i <= b; i++) #define all(c) (c).begin(), (c).end() #define sz(x) (int)x.size() #define PI 3.14159265358979323846 const int N = 1e3 + 5; int mod = 1e9 + 7; int dx[4] = {0, 0, +1, -1}; int dy[4] = {+1, -1, 0, 0}; long double a[N][N], p[N], sum; void solve() { int n; cin >> n; rep(i, 0, n) cin >> p[i]; a[0][0] = 1; rep(i, 0, n) { rep(j, 0, i + 1) { a[i + 1][j + 1] += a[i][j] * p[i]; a[i + 1][j] += a[i][j] * (1 - p[i]); } } int bg = (n + 1) / 2; rep(i, bg, n + 1) sum += a[n][i]; cout << fixed << setprecision(10) << sum << endl; // cout<<sum<<endl; } int32_t main() { cool; int t = 1; // cin>>t; while (t--) solve(); return 0; }
#include "bits/stdc++.h" using namespace std; #define cool \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define int long long int #define pb push_back #define fe first #define lb lower_bound #define ub upper_bound #define pii pair<pair<int, int>, pair<int, int>> #define se second #define endl "\n" #define pi pair<int, int> #define vi vector<int> #define vvi vector<vi> #define bs binary_search #define rep(i, a, b) for (int i = a; i < b; i++) #define rep1(i, a, b) for (int i = a; i <= b; i++) #define all(c) (c).begin(), (c).end() #define sz(x) (int)x.size() #define PI 3.14159265358979323846 const int N = 3e3 + 5; int mod = 1e9 + 7; int dx[4] = {0, 0, +1, -1}; int dy[4] = {+1, -1, 0, 0}; long double a[N][N], p[N], sum; void solve() { int n; cin >> n; rep(i, 0, n) cin >> p[i]; a[0][0] = 1; rep(i, 0, n) { rep(j, 0, i + 1) { a[i + 1][j + 1] += a[i][j] * p[i]; a[i + 1][j] += a[i][j] * (1 - p[i]); } } int bg = (n + 1) / 2; rep(i, bg, n + 1) sum += a[n][i]; cout << fixed << setprecision(10) << sum << endl; // cout<<sum<<endl; } int32_t main() { cool; int t = 1; // cin>>t; while (t--) solve(); return 0; }
replace
27
28
27
28
0
p03168
C++
Time Limit Exceeded
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pair<int, int>> vpi; typedef vector<pair<ll, ll>> vpll; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define F0R(i, a) FOR(i, 0, a) #define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i) #define R0F(i, a) ROF(i, 0, a) #define trav(a, x) for (auto &a : x) #define pb push_back #define mp make_pair #define rsz resize #define sz(x) int(x.size()) #define all(x) x.begin(), x.end() #define f first #define s second #define cont continue #define inf 1000000007 #define endl '\n' #define ednl '\n' #define test \ int t; \ cin >> t; \ while (t--) #define vin(v, n) \ vi(v); \ (v).rsz((n)); \ F0R(i, (n)) cin >> (v)[i]; #define vlln(v, n) \ vector<ll>(v); \ (v).rsz((n)); \ F0R(i, (n)) cin >> (v)[i]; #define vvin(v, n, m) \ vector<vi>(v); \ (v).rsz((n)); \ F0R(i, (n))(v)[i].rsz((m)); \ F0R(i, (n)) F0R(j, (m)) cin >> (v)[i][j]; #define pi 3.1415926535 #define vvlln(v, n, m) \ vector<vector<ll>>(v); \ (v).rsz((n)); \ F0R(i, (n))(v)[i].rsz((m)); \ F0R(i, (n)) F0R(j, (m)) cin >> (v)[i][j]; #define pq priority_queue #define linf 1000000000000000000LL ll maximum(ll x, ll y) { if (x > y) return x; return y; } ll minimum(ll x, ll y) { if (x < y) return x; return y; } void print_vector(vector<int> amount) { for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " "; cout << endl; } void print_vector(vector<ll> amount) { for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " "; cout << endl; } void print_vector(vector<double> amount) { for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " "; cout << endl; } void print_vector(vector<string> amount) { for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " "; cout << endl; } void print_vector(vector<bool> amount) { for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " "; cout << endl; } void print_vector(vector<pii> amount) { for (auto i = amount.begin(); i != amount.end(); i++) cout << (*i).f << " "; cout << endl; for (auto i = amount.begin(); i != amount.end(); i++) cout << (*i).s << " "; cout << endl; } void print_vector(vector<pair<ll, ll>> amount) { for (auto i = amount.begin(); i != amount.end(); i++) cout << (*i).f << " "; cout << endl; for (auto i = amount.begin(); i != amount.end(); i++) cout << (*i).s << " "; cout << endl; } void print_vector(vector<pair<pii, int>> amount) { for (auto i = amount.begin(); i != amount.end(); i++) cout << (*i).f.f << " " << (*i).f.s << " " << (*i).s << endl; cout << endl; } void print_vector(vector<pair<int, pii>> amount) { for (auto i = amount.begin(); i != amount.end(); i++) cout << (*i).f << " " << (*i).s.f << " " << (*i).s.s << endl; cout << endl; } void print_vector(vector<vector<string>> amount) { for (auto i = amount.begin(); i != amount.end(); i++) { print_vector(*i); cout << endl; } cout << endl; } void print_vector(vector<vector<int>> amount) { for (auto i = amount.begin(); i != amount.end(); i++) { cout << i - amount.begin() << endl; print_vector(*i); cout << endl; } cout << endl; } void print_vector(vector<vector<ll>> amount) { for (auto i = amount.begin(); i != amount.end(); i++) { cout << i - amount.begin() << endl; print_vector(*i); cout << endl; } cout << endl; } void print_vector(vector<vector<pair<ll, ll>>> amount) { for (auto i = amount.begin(); i != amount.end(); i++) { cout << i - amount.begin() << endl; print_vector(*i); } cout << endl; } void print_vector(vector<vector<vi>> amount) { for (auto i = amount.begin(); i != amount.end(); i++) { cout << i - amount.begin() << endl; print_vector(*i); cout << endl; } cout << endl; } void print_vector(vector<vector<vector<ll>>> amount) { for (auto i = amount.begin(); i != amount.end(); i++) { cout << i - amount.begin() << endl; print_vector(*i); cout << endl; } cout << endl; } void print_vector(vector<vector<bool>> amount) { for (auto i = amount.begin(); i != amount.end(); i++) { print_vector(*i); cout << endl; } cout << endl; } void print_set(set<int> amount) { for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " "; cout << endl; } void print_set(set<pii> amount) { for (auto i = amount.begin(); i != amount.end(); i++) cout << i->f << " " << i->s << endl; cout << endl; } void print_vector(vector<set<int>> amount) { for (auto i = amount.begin(); i != amount.end(); i++) { cout << i - amount.begin() << endl; print_set(*i); cout << endl; } cout << endl; } void print_vector(vector<vector<pii>> amount) { for (auto i = amount.begin(); i != amount.end(); i++) { cout << i - amount.begin() << endl; print_vector(*i); } } void print_set(set<string> amount) { for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " "; cout << endl; } void print_map(map<int, vector<int>> m) { for (map<int, vector<int>>::iterator i = m.begin(); i != m.end(); i++) { cout << i->first << " "; print_vector(i->second); } } void print_map(map<string, vector<string>> m) { for (map<string, vector<string>>::iterator i = m.begin(); i != m.end(); i++) { cout << i->first << " "; print_vector(i->second); } } void print_map(map<string, int> m) { for (auto i = m.begin(); i != m.end(); i++) { cout << i->first << " " << i->s << endl; } } void print_map(map<string, vector<bool>> m) { for (map<string, vector<bool>>::iterator i = m.begin(); i != m.end(); i++) { cout << i->first << " "; print_vector(i->second); } } void print_map(map<string, set<string>> m) { for (auto i = m.begin(); i != m.end(); i++) { cout << i->first << " "; print_set(i->second); } } void print_map(map<int, int> m) { for (map<int, int>::iterator i = m.begin(); i != m.end(); i++) { cout << i->first << " " << i->second << endl; } } void print_map(map<char, vector<string>> m) { for (auto i = m.begin(); i != m.end(); i++) { cout << i->first << endl; cout << '\t'; print_vector(i->second); } } void print_map(map<char, int> m) { for (auto i = m.begin(); i != m.end(); i++) { cout << i->first << endl; cout << '\t' << i->second << endl; } } void print_map(map<pii, int> m) { for (auto i = m.begin(); i != m.end(); i++) { cout << i->first.f << " " << i->first.s << " " << i->second << endl; } } bool comp(pii x, pii y) { if (x.s == y.s) return x.f < y.f; return x.s < y.s; } struct Graph { int V, E; vector<pair<int, pii>> edges; // node a, b, weight // constructor Graph(int a, int b) { V = a; E = b; } void addEdge(int a, int b, int w) { edges.push_back({w, {a, b}}); } // add function generate adj based on vertices and edges. vector<int> links, sizes; int find(int a) // return the root for node a { if (a == links[a]) return a; return links[a] = find(links[a]); } bool same(int a, int b) // check if node a and b has the same root { return find(a) == find(b); } void unite(int a, int b) { a = find(a); b = find(b); if (sizes[a] < sizes[b]) swap(a, b); sizes[a] += sizes[b]; // a always bigger than b, move subtree b under a links[b] = a; } void sort_edges() { sort(edges.begin(), edges.end()); } ll kruskalMST() { sort_edges(); // initialize for MST links.resize(V); sizes.resize(V); for (int i = 0; i < V; i++) { links[i] = i; sizes[i] = 1; } ll sum = 0; int count = 0; F0R(i, E) { int start = edges[i].s.f; int end = edges[i].s.s; if (!same(start, end)) { unite(start, end); sum += edges[i].f; count++; } } if (count != V - 1) return -inf; return sum; } }; /* void dijkstra(int i) {//Preconditions for this to work: 1. no negative edges. 2. dist and parents are both initialized with size N and full of INT_MAX and 0 respectively while dist[i]=0 and parent[i]=-1 priority_queue<pii>todo; vi finalized; finalized.rsz(N + 1, 0);//make sure that the size of adjacency is N+1 todo.push(mp(0, i)); while (!todo.empty()) {//.s is index while .f is weight pii temp = todo.top(); int index = temp.second; todo.pop(); if (finalized[index])continue; finalized[index] = 1; trav(x, adjacency[index]) { if (finalized[x.first]) continue; if (dist[x.f] > x.s + dist[index]) { dist[x.first] = x.second + dist[index]; parents[x.f] = index; todo.push(mp(-dist[x.first], x.f)); } } } } void make_adjacency() { F0R(i, NN) { a = i / N; b = i % N; if (a > 0) { if (pastures[a][b] == pastures[a - 1][b]) { adjacency[i].pb(mp(i - N, A)); } else { adjacency[i].pb(mp(i - N, B)); } } if (a < N - 1) { if (pastures[a][b] == pastures[a + 1][b]) { adjacency[i].pb(mp(i + N, A)); } else { adjacency[i].pb(mp(i + N, B)); } } if (b > 0) { if (pastures[a][b] == pastures[a][b - 1]) { adjacency[i].pb(mp(i - 1, A)); } else { adjacency[i].pb(mp(i - 1, B)); } } if (b < N - 1) { if (pastures[a][b] == pastures[a][b + 1]) { adjacency[i].pb(mp(i + 1, A)); } else { adjacency[i].pb(mp(i + 1, B)); } } } } void build_primes() { primes.reserve(50000); vi visited; visited.rsz(200000, 0); FOR(i, 2, 200000) { if (visited[i] == 0) { primes.pb(i); a = i; while (a < 200000) { visited[a] = 1; a += i; } } } } //Prim's Algorithm // need vector<vpi>adjacency ll prim() { ll a = 0; vi visited; visited.rsz(n, 0); visited[0] = 1; pq<pii>todo; trav(x, adjacency[0]) todo.push({ -x.s,x.f }); F0R(i, n - 1) { pii temp = todo.top(); todo.pop(); int index = temp.s; if (visited[index])cont; a -= temp.f; visited[index] = 1; trav(x, adjacency[index]) if (visited[x.f] == 0) { todo.push({ -x.s,x.f }); } } return a; } bool is_ancestor(int anc,int node) { return tin[anc]<=tin[node]&&tout[anc]>=tout[node]; } int LCA(int node1, int node2)//using SQRT decomposition { if (depth[node1] > depth[node2])swap(node1, node2); if (is_ancestor(node1, node2))return node1; int next = jump_parents[node1]; while (next != -1 && !is_ancestor(next, node2)) { node1 = next; next = jump_parents[node1]; } next = parents[node1]; while (next != -1 && !is_ancestor(next, node2)) { node1 = next; next = parents[node1]; } node1 = parents[node1]; return node1; } //building the sparse table for LCA int h = *max_element(all(depth)); logh = log2(h - 1) + 1; jump.rsz(n); F0R(i, n)jump[i].rsz(logh + 1); F0R(i, n)jump[i][0] = parents[i]; FOR(i, 1, logh + 1)F0R(j, n) { a=jump[j][i - 1]; if (a != -1)jump[j][i] = jump[a][i - 1]; else jump[j][i] = -1; } int LCA(int x, int y)//LCA with Sparse Table { if (depth[x] > depth[y])swap(x, y); if (is_ancestor(x, y))return x; int j = logh - 1; int next; while (!is_ancestor(parents[x], y)) { next = jump[x][j]; if (next == -1 || is_ancestor(next, y)) { j--; } else { x = next; } } return parents[x]; } */ int modInverse(int a, int m) { int m0 = m; int y = 0, x = 1; if (m == 1) return 0; while (a > 1) { // q is quotient int q = a / m; int t = m; // m is remainder now, process same as // Euclid's algo m = a % m, a = t; t = y; // Update y and x y = x - q * y; x = t; } // Make x positive if (x < 0) x += m0; return x; } ll power(ll x, ll y) { ll k = 1 << 30; ll z = 1; while (k != 0) { z *= z; z %= inf; if (y >= k) { z *= x; z %= inf; y -= k; } k >>= 1; } return z; } // remember that you need to take abs long double area(pii x, pii y, pii z) { return ((ll)x.s * y.f + (ll)y.s * z.f + (ll)z.s * x.f - (ll)x.f * y.s - (ll)y.f * z.s - (ll)z.f * x.s) / 2.0; } bool clockwise(pii x, pii y, pii z) { return area(x, y, z) > 0; } int gcd(int a, int b) { if (a > b) swap(a, b); if (a == 0) return b; return gcd(a, b % a); } // end of preprogrammed methods ll a, b, c; void setIO(string s) { ios_base::sync_with_stdio(0); cin.tie(0); // freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), // "w", stdout); } int n; vector<long double> p; void init() { setIO(""); cin >> n; p.rsz(n); F0R(i, n) cin >> p[i]; } int main() { init(); vector<vector<long double>> dp; dp.rsz(n + 1); F0R(i, n + 1) dp[i].rsz(2 * n + 1); dp[0][n] = 1; list<pii> todo; todo.pb({0, n}); while (!todo.empty()) { pii temp = todo.front(); todo.pop_front(); if (temp.f >= n || dp[temp.f + 1][temp.s + 1] > 0) cont; dp[temp.f + 1][temp.s - 1] += dp[temp.f][temp.s] * (1 - p[temp.f]); dp[temp.f + 1][temp.s + 1] += dp[temp.f][temp.s] * p[temp.f]; todo.pb({temp.f + 1, temp.s - 1}); todo.pb({temp.f + 1, temp.s + 1}); } long double sum = 0; FOR(i, n, 2 * n + 1) sum += (dp[n][i]); cout << setprecision(20) << sum << endl; }
#define _CRT_SECURE_NO_WARNINGS #include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pair<int, int>> vpi; typedef vector<pair<ll, ll>> vpll; #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define F0R(i, a) FOR(i, 0, a) #define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i) #define R0F(i, a) ROF(i, 0, a) #define trav(a, x) for (auto &a : x) #define pb push_back #define mp make_pair #define rsz resize #define sz(x) int(x.size()) #define all(x) x.begin(), x.end() #define f first #define s second #define cont continue #define inf 1000000007 #define endl '\n' #define ednl '\n' #define test \ int t; \ cin >> t; \ while (t--) #define vin(v, n) \ vi(v); \ (v).rsz((n)); \ F0R(i, (n)) cin >> (v)[i]; #define vlln(v, n) \ vector<ll>(v); \ (v).rsz((n)); \ F0R(i, (n)) cin >> (v)[i]; #define vvin(v, n, m) \ vector<vi>(v); \ (v).rsz((n)); \ F0R(i, (n))(v)[i].rsz((m)); \ F0R(i, (n)) F0R(j, (m)) cin >> (v)[i][j]; #define pi 3.1415926535 #define vvlln(v, n, m) \ vector<vector<ll>>(v); \ (v).rsz((n)); \ F0R(i, (n))(v)[i].rsz((m)); \ F0R(i, (n)) F0R(j, (m)) cin >> (v)[i][j]; #define pq priority_queue #define linf 1000000000000000000LL ll maximum(ll x, ll y) { if (x > y) return x; return y; } ll minimum(ll x, ll y) { if (x < y) return x; return y; } void print_vector(vector<int> amount) { for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " "; cout << endl; } void print_vector(vector<ll> amount) { for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " "; cout << endl; } void print_vector(vector<double> amount) { for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " "; cout << endl; } void print_vector(vector<string> amount) { for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " "; cout << endl; } void print_vector(vector<bool> amount) { for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " "; cout << endl; } void print_vector(vector<pii> amount) { for (auto i = amount.begin(); i != amount.end(); i++) cout << (*i).f << " "; cout << endl; for (auto i = amount.begin(); i != amount.end(); i++) cout << (*i).s << " "; cout << endl; } void print_vector(vector<pair<ll, ll>> amount) { for (auto i = amount.begin(); i != amount.end(); i++) cout << (*i).f << " "; cout << endl; for (auto i = amount.begin(); i != amount.end(); i++) cout << (*i).s << " "; cout << endl; } void print_vector(vector<pair<pii, int>> amount) { for (auto i = amount.begin(); i != amount.end(); i++) cout << (*i).f.f << " " << (*i).f.s << " " << (*i).s << endl; cout << endl; } void print_vector(vector<pair<int, pii>> amount) { for (auto i = amount.begin(); i != amount.end(); i++) cout << (*i).f << " " << (*i).s.f << " " << (*i).s.s << endl; cout << endl; } void print_vector(vector<vector<string>> amount) { for (auto i = amount.begin(); i != amount.end(); i++) { print_vector(*i); cout << endl; } cout << endl; } void print_vector(vector<vector<int>> amount) { for (auto i = amount.begin(); i != amount.end(); i++) { cout << i - amount.begin() << endl; print_vector(*i); cout << endl; } cout << endl; } void print_vector(vector<vector<ll>> amount) { for (auto i = amount.begin(); i != amount.end(); i++) { cout << i - amount.begin() << endl; print_vector(*i); cout << endl; } cout << endl; } void print_vector(vector<vector<pair<ll, ll>>> amount) { for (auto i = amount.begin(); i != amount.end(); i++) { cout << i - amount.begin() << endl; print_vector(*i); } cout << endl; } void print_vector(vector<vector<vi>> amount) { for (auto i = amount.begin(); i != amount.end(); i++) { cout << i - amount.begin() << endl; print_vector(*i); cout << endl; } cout << endl; } void print_vector(vector<vector<vector<ll>>> amount) { for (auto i = amount.begin(); i != amount.end(); i++) { cout << i - amount.begin() << endl; print_vector(*i); cout << endl; } cout << endl; } void print_vector(vector<vector<bool>> amount) { for (auto i = amount.begin(); i != amount.end(); i++) { print_vector(*i); cout << endl; } cout << endl; } void print_set(set<int> amount) { for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " "; cout << endl; } void print_set(set<pii> amount) { for (auto i = amount.begin(); i != amount.end(); i++) cout << i->f << " " << i->s << endl; cout << endl; } void print_vector(vector<set<int>> amount) { for (auto i = amount.begin(); i != amount.end(); i++) { cout << i - amount.begin() << endl; print_set(*i); cout << endl; } cout << endl; } void print_vector(vector<vector<pii>> amount) { for (auto i = amount.begin(); i != amount.end(); i++) { cout << i - amount.begin() << endl; print_vector(*i); } } void print_set(set<string> amount) { for (auto i = amount.begin(); i != amount.end(); i++) cout << *i << " "; cout << endl; } void print_map(map<int, vector<int>> m) { for (map<int, vector<int>>::iterator i = m.begin(); i != m.end(); i++) { cout << i->first << " "; print_vector(i->second); } } void print_map(map<string, vector<string>> m) { for (map<string, vector<string>>::iterator i = m.begin(); i != m.end(); i++) { cout << i->first << " "; print_vector(i->second); } } void print_map(map<string, int> m) { for (auto i = m.begin(); i != m.end(); i++) { cout << i->first << " " << i->s << endl; } } void print_map(map<string, vector<bool>> m) { for (map<string, vector<bool>>::iterator i = m.begin(); i != m.end(); i++) { cout << i->first << " "; print_vector(i->second); } } void print_map(map<string, set<string>> m) { for (auto i = m.begin(); i != m.end(); i++) { cout << i->first << " "; print_set(i->second); } } void print_map(map<int, int> m) { for (map<int, int>::iterator i = m.begin(); i != m.end(); i++) { cout << i->first << " " << i->second << endl; } } void print_map(map<char, vector<string>> m) { for (auto i = m.begin(); i != m.end(); i++) { cout << i->first << endl; cout << '\t'; print_vector(i->second); } } void print_map(map<char, int> m) { for (auto i = m.begin(); i != m.end(); i++) { cout << i->first << endl; cout << '\t' << i->second << endl; } } void print_map(map<pii, int> m) { for (auto i = m.begin(); i != m.end(); i++) { cout << i->first.f << " " << i->first.s << " " << i->second << endl; } } bool comp(pii x, pii y) { if (x.s == y.s) return x.f < y.f; return x.s < y.s; } struct Graph { int V, E; vector<pair<int, pii>> edges; // node a, b, weight // constructor Graph(int a, int b) { V = a; E = b; } void addEdge(int a, int b, int w) { edges.push_back({w, {a, b}}); } // add function generate adj based on vertices and edges. vector<int> links, sizes; int find(int a) // return the root for node a { if (a == links[a]) return a; return links[a] = find(links[a]); } bool same(int a, int b) // check if node a and b has the same root { return find(a) == find(b); } void unite(int a, int b) { a = find(a); b = find(b); if (sizes[a] < sizes[b]) swap(a, b); sizes[a] += sizes[b]; // a always bigger than b, move subtree b under a links[b] = a; } void sort_edges() { sort(edges.begin(), edges.end()); } ll kruskalMST() { sort_edges(); // initialize for MST links.resize(V); sizes.resize(V); for (int i = 0; i < V; i++) { links[i] = i; sizes[i] = 1; } ll sum = 0; int count = 0; F0R(i, E) { int start = edges[i].s.f; int end = edges[i].s.s; if (!same(start, end)) { unite(start, end); sum += edges[i].f; count++; } } if (count != V - 1) return -inf; return sum; } }; /* void dijkstra(int i) {//Preconditions for this to work: 1. no negative edges. 2. dist and parents are both initialized with size N and full of INT_MAX and 0 respectively while dist[i]=0 and parent[i]=-1 priority_queue<pii>todo; vi finalized; finalized.rsz(N + 1, 0);//make sure that the size of adjacency is N+1 todo.push(mp(0, i)); while (!todo.empty()) {//.s is index while .f is weight pii temp = todo.top(); int index = temp.second; todo.pop(); if (finalized[index])continue; finalized[index] = 1; trav(x, adjacency[index]) { if (finalized[x.first]) continue; if (dist[x.f] > x.s + dist[index]) { dist[x.first] = x.second + dist[index]; parents[x.f] = index; todo.push(mp(-dist[x.first], x.f)); } } } } void make_adjacency() { F0R(i, NN) { a = i / N; b = i % N; if (a > 0) { if (pastures[a][b] == pastures[a - 1][b]) { adjacency[i].pb(mp(i - N, A)); } else { adjacency[i].pb(mp(i - N, B)); } } if (a < N - 1) { if (pastures[a][b] == pastures[a + 1][b]) { adjacency[i].pb(mp(i + N, A)); } else { adjacency[i].pb(mp(i + N, B)); } } if (b > 0) { if (pastures[a][b] == pastures[a][b - 1]) { adjacency[i].pb(mp(i - 1, A)); } else { adjacency[i].pb(mp(i - 1, B)); } } if (b < N - 1) { if (pastures[a][b] == pastures[a][b + 1]) { adjacency[i].pb(mp(i + 1, A)); } else { adjacency[i].pb(mp(i + 1, B)); } } } } void build_primes() { primes.reserve(50000); vi visited; visited.rsz(200000, 0); FOR(i, 2, 200000) { if (visited[i] == 0) { primes.pb(i); a = i; while (a < 200000) { visited[a] = 1; a += i; } } } } //Prim's Algorithm // need vector<vpi>adjacency ll prim() { ll a = 0; vi visited; visited.rsz(n, 0); visited[0] = 1; pq<pii>todo; trav(x, adjacency[0]) todo.push({ -x.s,x.f }); F0R(i, n - 1) { pii temp = todo.top(); todo.pop(); int index = temp.s; if (visited[index])cont; a -= temp.f; visited[index] = 1; trav(x, adjacency[index]) if (visited[x.f] == 0) { todo.push({ -x.s,x.f }); } } return a; } bool is_ancestor(int anc,int node) { return tin[anc]<=tin[node]&&tout[anc]>=tout[node]; } int LCA(int node1, int node2)//using SQRT decomposition { if (depth[node1] > depth[node2])swap(node1, node2); if (is_ancestor(node1, node2))return node1; int next = jump_parents[node1]; while (next != -1 && !is_ancestor(next, node2)) { node1 = next; next = jump_parents[node1]; } next = parents[node1]; while (next != -1 && !is_ancestor(next, node2)) { node1 = next; next = parents[node1]; } node1 = parents[node1]; return node1; } //building the sparse table for LCA int h = *max_element(all(depth)); logh = log2(h - 1) + 1; jump.rsz(n); F0R(i, n)jump[i].rsz(logh + 1); F0R(i, n)jump[i][0] = parents[i]; FOR(i, 1, logh + 1)F0R(j, n) { a=jump[j][i - 1]; if (a != -1)jump[j][i] = jump[a][i - 1]; else jump[j][i] = -1; } int LCA(int x, int y)//LCA with Sparse Table { if (depth[x] > depth[y])swap(x, y); if (is_ancestor(x, y))return x; int j = logh - 1; int next; while (!is_ancestor(parents[x], y)) { next = jump[x][j]; if (next == -1 || is_ancestor(next, y)) { j--; } else { x = next; } } return parents[x]; } */ int modInverse(int a, int m) { int m0 = m; int y = 0, x = 1; if (m == 1) return 0; while (a > 1) { // q is quotient int q = a / m; int t = m; // m is remainder now, process same as // Euclid's algo m = a % m, a = t; t = y; // Update y and x y = x - q * y; x = t; } // Make x positive if (x < 0) x += m0; return x; } ll power(ll x, ll y) { ll k = 1 << 30; ll z = 1; while (k != 0) { z *= z; z %= inf; if (y >= k) { z *= x; z %= inf; y -= k; } k >>= 1; } return z; } // remember that you need to take abs long double area(pii x, pii y, pii z) { return ((ll)x.s * y.f + (ll)y.s * z.f + (ll)z.s * x.f - (ll)x.f * y.s - (ll)y.f * z.s - (ll)z.f * x.s) / 2.0; } bool clockwise(pii x, pii y, pii z) { return area(x, y, z) > 0; } int gcd(int a, int b) { if (a > b) swap(a, b); if (a == 0) return b; return gcd(a, b % a); } // end of preprogrammed methods ll a, b, c; void setIO(string s) { ios_base::sync_with_stdio(0); cin.tie(0); // freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), // "w", stdout); } int n; vector<long double> p; void init() { setIO(""); cin >> n; p.rsz(n); F0R(i, n) cin >> p[i]; } int main() { init(); vector<vector<long double>> dp; dp.rsz(n + 1); F0R(i, n + 1) dp[i].rsz(2 * n + 1); dp[0][n] = 1; F0R(i, n) { F0R(j, 2 * n + 1) { if (dp[i][j] > 0) { dp[i + 1][j - 1] += dp[i][j] * (1 - p[i]); dp[i + 1][j + 1] += dp[i][j] * (p[i]); } } } /* list<pii>todo; todo.pb({ 0,n }); while (!todo.empty()) { pii temp = todo.front(); todo.pop_front(); if (temp.f >= n || dp[temp.f + 1][temp.s + 1] > 0)cont; dp[temp.f + 1][temp.s - 1] += dp[temp.f][temp.s] * (1 - p[temp.f]); dp[temp.f + 1][temp.s + 1] += dp[temp.f][temp.s] * p[temp.f]; todo.pb({ temp.f + 1,temp.s - 1 }); todo.pb({ temp.f + 1,temp.s + 1 }); } trav(x, dp) { trav(y, x) cout << y << " "; cout << endl; }*/ long double sum = 0; FOR(i, n, 2 * n + 1) sum += (dp[n][i]); cout << setprecision(20) << sum << endl; }
replace
584
596
584
611
TLE
p03168
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; vector<vector<double>> dp; double solve(double a[], int i, int x) { if (x == 0) return 1; if (i == 0) return 0; if (dp[i][x] >= -0.9) return dp[i][x]; return dp[i][x] = (a[i] * solve(a, i - 1, x - 1)) + ((1 - a[i]) * solve(a, i - 1, x)); } int main() { int n; cin >> n; double a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; dp.resize(n, vector<double>(n, -1)); cout << fixed << setprecision(10) << solve(a, n, (n + 1) / 2); return 0; }
#include <bits/stdc++.h> using namespace std; vector<vector<double>> dp; double solve(double a[], int i, int x) { if (x == 0) return 1; if (i == 0) return 0; if (dp[i][x] >= -0.9) return dp[i][x]; return dp[i][x] = (a[i] * solve(a, i - 1, x - 1)) + ((1 - a[i]) * solve(a, i - 1, x)); } int main() { int n; cin >> n; double a[n + 1]; for (int i = 1; i <= n; i++) cin >> a[i]; dp.resize(n + 1, vector<double>(n + 1, -1)); cout << fixed << setprecision(10) << solve(a, n, (n + 1) / 2); return 0; }
replace
19
20
19
20
-11