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
p03221
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> P; typedef pair<ll, ll> Pll; using Graph = vector<vector<int>>; using Graphl = vector<vector<ll>>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define Rep(i, k, n) for (int i = k; i < (int)(n); i++) #define RRep(i, k, n) for (int i = k; i > (int)(n); i--) #define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl #define ALL(a) (a).begin(), (a).end() #define rALL(a) (a).rbegin(), (a).rend() template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> void PrintVector(const vector<T> &vec) { for (auto val : vec) cout << val << " "; cout << endl; } const long long INF = 1LL << 60; const long long minusINF = -(1LL << 40); const int MOD = 1000000007; const double PI = acos(-1); // 3.14~ const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; int main() { int n, m; cin >> n >> m; Graphl a(n); vector<int> p(m), y(m); rep(i, m) { cin >> p[i] >> y[i]; --p[i]; a[p[i]].push_back(y[i]); } for (auto &v : a) { sort(ALL(v)); } rep(i, m) { auto b = find(ALL(a[p[i]]), y[i]); int index = distance(a[p[i]].begin(), b); printf("%06d%06d\n", p[i] + 1, index + 1); } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> P; typedef pair<ll, ll> Pll; using Graph = vector<vector<int>>; using Graphl = vector<vector<ll>>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define Rep(i, k, n) for (int i = k; i < (int)(n); i++) #define RRep(i, k, n) for (int i = k; i > (int)(n); i--) #define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl #define ALL(a) (a).begin(), (a).end() #define rALL(a) (a).rbegin(), (a).rend() template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> void PrintVector(const vector<T> &vec) { for (auto val : vec) cout << val << " "; cout << endl; } const long long INF = 1LL << 60; const long long minusINF = -(1LL << 40); const int MOD = 1000000007; const double PI = acos(-1); // 3.14~ const int dx[4] = {1, 0, -1, 0}; const int dy[4] = {0, 1, 0, -1}; int main() { int n, m; cin >> n >> m; Graphl a(n); vector<int> p(m), y(m); rep(i, m) { cin >> p[i] >> y[i]; --p[i]; a[p[i]].push_back(y[i]); } for (auto &v : a) { sort(ALL(v)); } rep(i, m) { // auto b = find(ALL(a[p[i]]), y[i]); // int index = distance(a[p[i]].begin(), b); int index = lower_bound(a[p[i]].begin(), a[p[i]].end(), y[i]) - a[p[i]].begin(); printf("%06d%06d\n", p[i] + 1, index + 1); } }
replace
56
58
56
60
TLE
p03222
C++
Runtime Error
#include <cmath> #include <iostream> #include <vector> // https://qiita.com/ofutonfuton/items/92b1a6f4a7775f00b6ae using namespace std; typedef long long ll; const ll M = pow(10, 9) + 7; vector<ll> fac(300001); // n!(mod M) vector<ll> ifac(300001); // k!^{M-2} (mod M) // k^{M-2} == k^{-1} // a,bの範囲的にこれだけ配列を用意していけば十分 ll mpow(ll x, ll n) { // x^n(mod M) ←普通にpow(x,n)では溢れてしまうため,随時mod計算 ll ans = 1; while (n != 0) { if (n & 1) ans = ans * x % M; x = x * x % M; n = n >> 1; } return ans; } ll comb(ll a, ll b) { // aCbをmod計算 if (a == 0 && b == 0) return 1; if (a < b || a < 0) return 0; ll tmp = ifac[a - b] * ifac[b] % M; return tmp * fac[a] % M; } ll comb2(ll a, ll b) { // aCbをmod計算 if (a == 0 && b == 0) return 1; if (a < b || a < 0) return 0; ll tmp = ifac[a - b] * ifac[b] % M; return tmp * fac[a] % M; } long long gcd(long long a, long long b) { long long c; if (a < b) { a += b; b = a - b; a -= b; } while (b != 0) { c = a % b; a = b; b = c; } return a; } ll lcm(ll m, ll n) { // 引数に0がある場合は0を返す if ((0 == m) || (0 == n)) return 0; return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n) } // lcm pair<ll, ll> add_bunsuu(pair<ll, ll> a, pair<ll, ll> b) { ll bunbo = lcm(a.second, b.second); cout << a.first << "/" << a.second << endl; cout << b.first << "/" << b.second << endl; cout << a.first * bunbo / a.second + b.first * bunbo / b.second << "/" << bunbo << endl; return make_pair(a.first * bunbo / a.second + b.first * bunbo / b.second, bunbo); } ll valid_amida_pattern(ll w) { if (w <= 0) { return 1; } return valid_amida_pattern(w - 1) % 1000000007 + valid_amida_pattern(w - 2) % 1000000007; } int main() { ll H, W, K; cin >> H >> W >> K; ll **int_probs = new ll *[H + 1]; for (ll i = 0; i < H + 1; i++) { int_probs[i] = new ll[W]; } if (W == 1) { return 1; } for (ll i = 0; i < W; i++) { if (i == 0) { int_probs[0][i] = 1; } else { int_probs[0][i] = 0; } } for (ll i = 1; i < H + 1; i++) { for (ll n = 0; n < W; n++) { if (n == 0) { int_probs[i][n] = int_probs[i - 1][n] * valid_amida_pattern(W - 2) % 1000000007 + int_probs[i - 1][n + 1] * valid_amida_pattern(W - 3) % 1000000007; } else if (n == W - 1) { int_probs[i][n] = int_probs[i - 1][n] * valid_amida_pattern(W - 2) % 1000000007 + int_probs[i - 1][n - 1] * valid_amida_pattern(W - 3) % 1000000007; } else { int_probs[i][n] = int_probs[i - 1][n] * valid_amida_pattern(n - 1) * valid_amida_pattern(W - n - 2) % 1000000007 + int_probs[i - 1][n + 1] * valid_amida_pattern(n - 1) * valid_amida_pattern(W - n - 3) % 1000000007 + int_probs[i - 1][n - 1] * valid_amida_pattern(n - 2) * valid_amida_pattern(W - n - 2) % 1000000007; } int_probs[i][n] = int_probs[i][n] % 1000000007; } } cout << int_probs[H][K - 1]; return 0; }
#include <cmath> #include <iostream> #include <vector> // https://qiita.com/ofutonfuton/items/92b1a6f4a7775f00b6ae using namespace std; typedef long long ll; const ll M = pow(10, 9) + 7; vector<ll> fac(300001); // n!(mod M) vector<ll> ifac(300001); // k!^{M-2} (mod M) // k^{M-2} == k^{-1} // a,bの範囲的にこれだけ配列を用意していけば十分 ll mpow(ll x, ll n) { // x^n(mod M) ←普通にpow(x,n)では溢れてしまうため,随時mod計算 ll ans = 1; while (n != 0) { if (n & 1) ans = ans * x % M; x = x * x % M; n = n >> 1; } return ans; } ll comb(ll a, ll b) { // aCbをmod計算 if (a == 0 && b == 0) return 1; if (a < b || a < 0) return 0; ll tmp = ifac[a - b] * ifac[b] % M; return tmp * fac[a] % M; } ll comb2(ll a, ll b) { // aCbをmod計算 if (a == 0 && b == 0) return 1; if (a < b || a < 0) return 0; ll tmp = ifac[a - b] * ifac[b] % M; return tmp * fac[a] % M; } long long gcd(long long a, long long b) { long long c; if (a < b) { a += b; b = a - b; a -= b; } while (b != 0) { c = a % b; a = b; b = c; } return a; } ll lcm(ll m, ll n) { // 引数に0がある場合は0を返す if ((0 == m) || (0 == n)) return 0; return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n) } // lcm pair<ll, ll> add_bunsuu(pair<ll, ll> a, pair<ll, ll> b) { ll bunbo = lcm(a.second, b.second); cout << a.first << "/" << a.second << endl; cout << b.first << "/" << b.second << endl; cout << a.first * bunbo / a.second + b.first * bunbo / b.second << "/" << bunbo << endl; return make_pair(a.first * bunbo / a.second + b.first * bunbo / b.second, bunbo); } ll valid_amida_pattern(ll w) { if (w <= 0) { return 1; } return valid_amida_pattern(w - 1) % 1000000007 + valid_amida_pattern(w - 2) % 1000000007; } int main() { ll H, W, K; cin >> H >> W >> K; ll **int_probs = new ll *[H + 1]; for (ll i = 0; i < H + 1; i++) { int_probs[i] = new ll[W]; } for (ll i = 0; i < W; i++) { if (i == 0) { int_probs[0][i] = 1; } else { int_probs[0][i] = 0; } } for (ll i = 1; i < H + 1; i++) { for (ll n = 0; n < W; n++) { if (n == 0) { int_probs[i][n] = int_probs[i - 1][n] * valid_amida_pattern(W - 2) % 1000000007 + int_probs[i - 1][n + 1] * valid_amida_pattern(W - 3) % 1000000007; } else if (n == W - 1) { int_probs[i][n] = int_probs[i - 1][n] * valid_amida_pattern(W - 2) % 1000000007 + int_probs[i - 1][n - 1] * valid_amida_pattern(W - 3) % 1000000007; } else { int_probs[i][n] = int_probs[i - 1][n] * valid_amida_pattern(n - 1) * valid_amida_pattern(W - n - 2) % 1000000007 + int_probs[i - 1][n + 1] * valid_amida_pattern(n - 1) * valid_amida_pattern(W - n - 3) % 1000000007 + int_probs[i - 1][n - 1] * valid_amida_pattern(n - 2) * valid_amida_pattern(W - n - 2) % 1000000007; } int_probs[i][n] = int_probs[i][n] % 1000000007; } } cout << int_probs[H][K - 1]; return 0; }
delete
99
103
99
99
0
p03222
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vs = vector<string>; using pll = pair<ll, ll>; using vp = vector<pll>; #define rep(i, n) for (ll i = 0; i < (n); i++) #define repr(i, a, b) for (ll i = (a); i < (b); i++) #define ALL(a) (a).begin(), (a).end() #define SZ(x) ((ll)(x).size()) const ll MOD = 1000000007; const ll INF = 100000000000000000LL; inline ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; } inline ll LCM(ll a, ll b) { return a / GCD(a, b) * b; } inline ll powint(ll x, ll y) { ll r = 1; while (y) { if (y & 1) r *= x; x *= x; y >>= 1; } return r; } inline ll powmod(ll x, ll y, ll m = MOD) { ll r = 1; while (y) { if (y & 1) r *= x; x *= x; r %= m; x %= m; y >>= 1; } return r; } 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; } #ifdef OJ_LOCAL #include "dump.hpp" #else #define dump(...) ((void)0) #endif // xがyに行く vvvll dp(100, vvll(8, vll(8, 0))); vvll dpb(8, vll(8, 0)); int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); ll h, w, k; cin >> h >> w >> k; ll r = powint(2, w - 1); rep(i, r) { rep(j, w - 1) { if ((i >> j) & 1 && (i >> (j + 1)) & 1) goto invalid; } rep(j, w) { if ((i >> j) & 1) dpb[j][j + 1]++; else if (j > 0 && (i >> (j - 1)) & 1) dpb[j][j - 1]++; else dpb[j][j]++; } invalid:; } rep(i, 8) rep(j, 8) { dp[1][i][j] = dpb[i][j]; } repr(i, 2, h + 1) { rep(j, 8) rep(k, 8) rep(l, 8) { dp[i][j][k] += (dp[i - 1][j][l] * dpb[l][k]) % MOD; dp[i][j][k] %= MOD; } } cout << dp[h][0][k - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>; using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vs = vector<string>; using pll = pair<ll, ll>; using vp = vector<pll>; #define rep(i, n) for (ll i = 0; i < (n); i++) #define repr(i, a, b) for (ll i = (a); i < (b); i++) #define ALL(a) (a).begin(), (a).end() #define SZ(x) ((ll)(x).size()) const ll MOD = 1000000007; const ll INF = 100000000000000000LL; inline ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; } inline ll LCM(ll a, ll b) { return a / GCD(a, b) * b; } inline ll powint(ll x, ll y) { ll r = 1; while (y) { if (y & 1) r *= x; x *= x; y >>= 1; } return r; } inline ll powmod(ll x, ll y, ll m = MOD) { ll r = 1; while (y) { if (y & 1) r *= x; x *= x; r %= m; x %= m; y >>= 1; } return r; } 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; } #ifdef OJ_LOCAL #include "dump.hpp" #else #define dump(...) ((void)0) #endif // xがyに行く vvvll dp(101, vvll(8, vll(8, 0))); vvll dpb(8, vll(8, 0)); int main() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); ll h, w, k; cin >> h >> w >> k; ll r = powint(2, w - 1); rep(i, r) { rep(j, w - 1) { if ((i >> j) & 1 && (i >> (j + 1)) & 1) goto invalid; } rep(j, w) { if ((i >> j) & 1) dpb[j][j + 1]++; else if (j > 0 && (i >> (j - 1)) & 1) dpb[j][j - 1]++; else dpb[j][j]++; } invalid:; } rep(i, 8) rep(j, 8) { dp[1][i][j] = dpb[i][j]; } repr(i, 2, h + 1) { rep(j, 8) rep(k, 8) rep(l, 8) { dp[i][j][k] += (dp[i - 1][j][l] * dpb[l][k]) % MOD; dp[i][j][k] %= MOD; } } cout << dp[h][0][k - 1] << endl; return 0; }
replace
63
64
63
64
0
p03222
C++
Runtime Error
#include <iostream> using namespace std; typedef long long ll; ll mod = 1e9 + 7; ll dp[10][10]; ll fib[20]; int main() { ll h, w, k; cin >> h >> w >> k; fib[0] = 0, fib[1] = 1; for (int i = 2; i < 20; i++) { fib[i] = fib[i - 1] + fib[i - 2]; } dp[0][1] = 1; for (int i = 2; i <= w; i++) dp[0][i] = 0; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { dp[i][j] = (dp[i - 1][j - 1] * fib[w - j + 1] % mod * fib[j - 1] % mod + dp[i - 1][j + 1] * fib[w - j] % mod * fib[j] % mod + dp[i - 1][j] * fib[j] % mod * fib[w - j + 1] % mod) % mod; } } cout << dp[h][k] << endl; }
#include <iostream> using namespace std; typedef long long ll; ll mod = 1e9 + 7; ll dp[110][10]; ll fib[20]; int main() { ll h, w, k; cin >> h >> w >> k; fib[0] = 0, fib[1] = 1; for (int i = 2; i < 20; i++) { fib[i] = fib[i - 1] + fib[i - 2]; } dp[0][1] = 1; for (int i = 2; i <= w; i++) dp[0][i] = 0; for (int i = 1; i <= h; i++) { for (int j = 1; j <= w; j++) { dp[i][j] = (dp[i - 1][j - 1] * fib[w - j + 1] % mod * fib[j - 1] % mod + dp[i - 1][j + 1] * fib[w - j] % mod * fib[j] % mod + dp[i - 1][j] * fib[j] % mod * fib[w - j + 1] % mod) % mod; } } cout << dp[h][k] << endl; }
replace
6
7
6
7
0
p03222
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; ll dp[16][9]; // dp[i][j]:上からiの高さまでの1から出発した時の数 ll h, w, k; bool invalid(ll bit) { for (ll i = 0; i < w - 1; ++i) { if ((bit) & (1 << i) && (bit) & (1 << (i + 1))) { // cout<<bit<<endl; return true; } } return false; } int main() { cin >> h >> w >> k; dp[0][0] = 1; for (ll i = 0; i < h; ++i) { for (ll bit = 0; bit < (1 << (w - 1)); ++bit) { if (invalid(bit)) continue; for (ll j = 0; j < w - 1; j++) { if (bit & (1 << j)) { (dp[i + 1][j] += dp[i][j + 1]) %= MOD; (dp[i + 1][j + 1] += dp[i][j]) %= MOD; j++; } else { (dp[i + 1][j] += dp[i][j]) %= MOD; } } if (!(bit & (1 << (w - 2)))) { // cout<<bit<<endl; (dp[i + 1][w - 1] += dp[i][w - 1]) %= MOD; } } } // for(ll i = 0;i<=h;i++){for(ll j = 0;j<w;j++){cout<<dp[i][j]<<' // ';}cout<<endl;} cout << dp[h][k - 1] << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; ll dp[101][9]; // dp[i][j]:上からiの高さまでの1から出発した時の数 ll h, w, k; bool invalid(ll bit) { for (ll i = 0; i < w - 1; ++i) { if ((bit) & (1 << i) && (bit) & (1 << (i + 1))) { // cout<<bit<<endl; return true; } } return false; } int main() { cin >> h >> w >> k; dp[0][0] = 1; for (ll i = 0; i < h; ++i) { for (ll bit = 0; bit < (1 << (w - 1)); ++bit) { if (invalid(bit)) continue; for (ll j = 0; j < w - 1; j++) { if (bit & (1 << j)) { (dp[i + 1][j] += dp[i][j + 1]) %= MOD; (dp[i + 1][j + 1] += dp[i][j]) %= MOD; j++; } else { (dp[i + 1][j] += dp[i][j]) %= MOD; } } if (!(bit & (1 << (w - 2)))) { // cout<<bit<<endl; (dp[i + 1][w - 1] += dp[i][w - 1]) %= MOD; } } } // for(ll i = 0;i<=h;i++){for(ll j = 0;j<w;j++){cout<<dp[i][j]<<' // ';}cout<<endl;} cout << dp[h][k - 1] << endl; return 0; }
replace
5
6
5
6
0
p03222
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <cstdlib> #include <iostream> #include <list> #include <string> #include <vector> using namespace std; int main(void) { int h, w, k; cin >> h; cin >> w; cin >> k; const int mod = 1000000007; vector<vector<uint64_t>> num(w, vector<uint64_t>(101, 0)); num[0][0] = 1; for (int i = 0; i <= h; i++) { for (int j = 0; j < w; j++) { // num[j][i+1] = num[j][i]; for (int k = 0; k < (1 << (w - 1)); k++) { bool check = true; for (int l = 0; l < w - 2; l++) { if ((k >> l) & 1 && (k >> l + 1) & 1) check = false; } if (!check) continue; if (j >= 1 && (k >> (j - 1)) & 1) { num[j - 1][i + 1] += num[j][i]; num[j - 1][i + 1] %= mod; } else if (j <= w - 2 && (k >> j) & 1) { num[j + 1][i + 1] += num[j][i]; num[j + 1][i + 1] %= mod; } else { num[j][i + 1] += num[j][i]; num[j][i + 1] %= mod; } } // cout << endl; // cout << num[j][i] << " "; // cout << log10(num[j][i]) << " "; // cout << endl; // num[j][i]%=(uint64_t)1000000007; } // cout << num[0][i] << endl; // cout << endl; } // cout << (uint64_t)(num[k-1][h]%(uint64_t)1000000007) << endl; cout << num[k - 1][h] << endl; // uint64_t ans=num[k-1][h]%mod; // cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <cstdlib> #include <iostream> #include <list> #include <string> #include <vector> using namespace std; int main(void) { int h, w, k; cin >> h; cin >> w; cin >> k; const int mod = 1000000007; vector<vector<uint64_t>> num(w, vector<uint64_t>(102, 0)); num[0][0] = 1; for (int i = 0; i <= h; i++) { for (int j = 0; j < w; j++) { // num[j][i+1] = num[j][i]; for (int k = 0; k < (1 << (w - 1)); k++) { bool check = true; for (int l = 0; l < w - 2; l++) { if ((k >> l) & 1 && (k >> l + 1) & 1) check = false; } if (!check) continue; if (j >= 1 && (k >> (j - 1)) & 1) { num[j - 1][i + 1] += num[j][i]; num[j - 1][i + 1] %= mod; } else if (j <= w - 2 && (k >> j) & 1) { num[j + 1][i + 1] += num[j][i]; num[j + 1][i + 1] %= mod; } else { num[j][i + 1] += num[j][i]; num[j][i + 1] %= mod; } } // cout << endl; // cout << num[j][i] << " "; // cout << log10(num[j][i]) << " "; // cout << endl; // num[j][i]%=(uint64_t)1000000007; } // cout << num[0][i] << endl; // cout << endl; } // cout << (uint64_t)(num[k-1][h]%(uint64_t)1000000007) << endl; cout << num[k - 1][h] << endl; // uint64_t ans=num[k-1][h]%mod; // cout << ans << endl; return 0; }
replace
19
20
19
20
0
p03222
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; #define endl '\n' #define fo(i, a, b) for (int i = a; i <= b; i++) #define rf(i, a, b) for (int i = a; i >= b; i--) #define fast_io ios_base::sync_with_stdio(0); #define show(x) cout << x << endl; #define pret(x) \ cout << x << endl; \ return 0; #define disp(x) cout << x << " "; #define let(x, y) cout << x << " " << y << endl; ll MOD = 1e9 + 7; ll MAX = 9223372036854775807; ll dp[101][9], fib[20]; int main() { fast_io; int h, w, k; cin >> h >> w >> k; fib[2] = 2, fib[3] = 3; fib[0] = 1, fib[1] = 1; fo(i, 4, 19) fib[i] = (fib[i - 1] + fib[i - 2]) % MOD; dp[h + 1][1] = 1; rf(i, h, 1) { // { // int j=2; fo(j, 1, w) { // show(dp[1][k]); dp[i][j] = (dp[i + 1][j] * ((fib[j - 1] * fib[w - j]) % MOD)) % MOD; // show(dp[1][k]); if (j + 1 <= w) dp[i][j] = (dp[i][j] + dp[i + 1][j + 1] * ((fib[j - 1] * fib[w - j - 1]) % MOD)) % MOD; // show(dp[1][k]); if (j - 1 > 0) dp[i][j] = (dp[i][j] + dp[i + 1][j - 1] * ((fib[j - 2] * fib[w - j]) % MOD)) % MOD; // show(dp[1][k]); } } show(dp[1][k]); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<int> vi; #define endl '\n' #define fo(i, a, b) for (int i = a; i <= b; i++) #define rf(i, a, b) for (int i = a; i >= b; i--) #define fast_io ios_base::sync_with_stdio(0); #define show(x) cout << x << endl; #define pret(x) \ cout << x << endl; \ return 0; #define disp(x) cout << x << " "; #define let(x, y) cout << x << " " << y << endl; ll MOD = 1e9 + 7; ll MAX = 9223372036854775807; ll dp[112][15], fib[20]; int main() { fast_io; int h, w, k; cin >> h >> w >> k; fib[2] = 2, fib[3] = 3; fib[0] = 1, fib[1] = 1; fo(i, 4, 19) fib[i] = (fib[i - 1] + fib[i - 2]) % MOD; dp[h + 1][1] = 1; rf(i, h, 1) { // { // int j=2; fo(j, 1, w) { // show(dp[1][k]); dp[i][j] = (dp[i + 1][j] * ((fib[j - 1] * fib[w - j]) % MOD)) % MOD; // show(dp[1][k]); if (j + 1 <= w) dp[i][j] = (dp[i][j] + dp[i + 1][j + 1] * ((fib[j - 1] * fib[w - j - 1]) % MOD)) % MOD; // show(dp[1][k]); if (j - 1 > 0) dp[i][j] = (dp[i][j] + dp[i + 1][j - 1] * ((fib[j - 2] * fib[w - j]) % MOD)) % MOD; // show(dp[1][k]); } } show(dp[1][k]); return 0; }
replace
17
18
17
18
0
p03222
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> Pii; typedef pair<ll, ll> Pll; #define rep(i, n) for (ll i = 0; i < n; ++i) #define rep2(i, a, b) for (ll i = a; i < b; ++i) const ll MOD = 1000000007; string alp = "abcdefghijklmnopqrstuvwxyz"; int main() { int H, W, K; cin >> H >> W >> K; vector<vector<vector<ll>>> pos1(W, vector<vector<ll>>(W, vector<ll>(W, 0))); vector<vector<vector<ll>>> pos2(W, vector<vector<ll>>(W, vector<ll>(W, 0))); rep(i, W) { rep(j, W) { pos2[i][j][0] = 1; if (i == 0 && j == 0) { pos1[i][j][0] = 1; pos2[i][j][0] = 0; } rep(k, W - 1) { if (k + 1 == i || k + 1 == j) { if (i == j) { pos1[i][j][k + 1] = 0; pos2[i][j][k + 1] = (pos1[i][j][k] + pos2[i][j][k]) % MOD; if (k + 2 <= W - 1) { pos1[i][j][k + 2] = 0; pos2[i][j][k + 2] = pos2[i][j][k + 1]; k++; } } else if ((i == 0 && j == 1) || (i == 1 && j == 0)) { pos1[i][j][k + 1] = 1; pos2[i][j][k + 1] = 0; } else { pos1[i][j][k + 1] = 0; pos2[i][j][k + 1] = (pos1[i][j][k] + pos2[i][j][k]) % MOD; pos1[i][j][k + 2] = pos2[i][j][k + 1]; pos2[i][j][k + 2] = 0; k++; } } else { pos1[i][j][k + 1] = pos2[i][j][k]; pos2[i][j][k + 1] = (pos1[i][j][k] + pos2[i][j][k]) % MOD; } } } } vector<vector<ll>> dp(H + 1, vector<ll>(8, 0)); dp[0][0] = 1; rep(i, H) { rep(j, W) { dp[i + 1][j] += dp[i][j] * (pos1[j][j][W - 1] + pos2[j][j][W - 1]); if (j > 0) { dp[i + 1][j] += dp[i][j - 1] * (pos1[j - 1][j][W - 1] + pos2[j - 1][j][W - 1]); } if (j < W - 1) { dp[i + 1][j] += dp[i][j + 1] * (pos1[j + 1][j][W - 1] + pos2[j + 1][j][W - 1]); } dp[i + 1][j] %= MOD; } } cout << dp[H][K - 1] << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> Pii; typedef pair<ll, ll> Pll; #define rep(i, n) for (ll i = 0; i < n; ++i) #define rep2(i, a, b) for (ll i = a; i < b; ++i) const ll MOD = 1000000007; string alp = "abcdefghijklmnopqrstuvwxyz"; int main() { int H, W, K; cin >> H >> W >> K; vector<vector<vector<ll>>> pos1(W, vector<vector<ll>>(W, vector<ll>(W, 0))); vector<vector<vector<ll>>> pos2(W, vector<vector<ll>>(W, vector<ll>(W, 0))); rep(i, W) { rep(j, W) { pos2[i][j][0] = 1; if (i == 0 && j == 0) { pos1[i][j][0] = 1; pos2[i][j][0] = 0; } rep(k, W - 1) { if (k + 1 == i || k + 1 == j) { if (i == j) { pos1[i][j][k + 1] = 0; pos2[i][j][k + 1] = (pos1[i][j][k] + pos2[i][j][k]) % MOD; if (k + 2 <= W - 1) { pos1[i][j][k + 2] = 0; pos2[i][j][k + 2] = pos2[i][j][k + 1]; k++; } } else if ((i == 0 && j == 1) || (i == 1 && j == 0)) { pos1[i][j][k + 1] = 1; pos2[i][j][k + 1] = 0; } else { pos1[i][j][k + 1] = 0; pos2[i][j][k + 1] = (pos1[i][j][k] + pos2[i][j][k]) % MOD; if (k + 2 <= W - 1) { pos1[i][j][k + 2] = pos2[i][j][k + 1]; pos2[i][j][k + 2] = 0; k++; } } } else { pos1[i][j][k + 1] = pos2[i][j][k]; pos2[i][j][k + 1] = (pos1[i][j][k] + pos2[i][j][k]) % MOD; } } } } vector<vector<ll>> dp(H + 1, vector<ll>(8, 0)); dp[0][0] = 1; rep(i, H) { rep(j, W) { dp[i + 1][j] += dp[i][j] * (pos1[j][j][W - 1] + pos2[j][j][W - 1]); if (j > 0) { dp[i + 1][j] += dp[i][j - 1] * (pos1[j - 1][j][W - 1] + pos2[j - 1][j][W - 1]); } if (j < W - 1) { dp[i + 1][j] += dp[i][j + 1] * (pos1[j + 1][j][W - 1] + pos2[j + 1][j][W - 1]); } dp[i + 1][j] %= MOD; } } cout << dp[H][K - 1] << endl; }
replace
38
41
38
43
-6
free(): invalid pointer
p03222
C++
Runtime Error
#include <bits/stdc++.h> using ll = long long; using Int = int; #define int ll #define rep(i, n) for (int i = 0; i < n; i++) #define loop(i, s, n) for (int i = s; i < n; i++) #define erep(e, v) for (auto &&e : v) #define all(in) in.begin(), in.end() #define MP make_pair #define INF (sizeof(int) == 4 ? (int)1e9 : (int)1e18) #define EPS 0.0000000001 using namespace std; template <class T, class S> void cmin(T &a, const S &b) { if (a > b) a = b; } template <class T, class S> void cmax(T &a, const S &b) { if (a < b) a = b; } template <typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); } template <typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); } template <class T> void join(T a) { for (auto itr : a) { if (itr != *a.begin()) cout << " "; cout << itr; } } using ld = long double; using pii = pair<int, int>; using piii = pair<int, pii>; int W, H; int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0}; bool valid(int x, int y) { return (0 <= x && x < W) && (0 <= y && y < H); } int MOD = 1000000007; class dynamic_bitset { public: long long bit; string sbit = ""; unsigned long long bitsize = 0; dynamic_bitset(int _bit) : bit{_bit} { for (int t = 1, num = 1; bitsize == 0; t++, num *= 2) { if (num - 1 >= bit) bitsize = t; } for (int i = 0; i < bitsize; i++) { sbit = ((bit >> i & 1) == 1 ? "1" : "0") + sbit; } } dynamic_bitset(int _bit, int bitrange) : bit{_bit} { for (int t = 1, num = 1; bitsize == 0; t++, num *= 2) { if (num - 1 >= bit) bitsize = t; } for (int i = 0; i < bitrange; i++) { sbit = (i < bitsize and ((bit >> i & 1) == 1) ? "1" : "0") + sbit; } } auto test(int _idx) { assert(_idx < sbit.size() && "excution will be out of range"); return sbit[_idx] == '1'; } void set(int _idx) { assert(_idx < sbit.size() && "excution will be out of range"); sbit[_idx] = '1'; } auto size() { return sbit.size(); } }; int ans = 0; signed main() { int h, w, k; cin >> h >> w >> k; auto dp = vectors(100, 100, 0LL); dp[1][1] = 1; for (int j = 1; j <= h; j++) { for (int i = 1; i <= w; i++) { for (int bit = 0; bit < (1 << (w - 1)); bit++) { auto db = dynamic_bitset(bit, w - 1); bool isValid = true; rep(i, (int)db.size() - 1) { if (db.test(i) and db.test(i + 1)) isValid = false; } if (!isValid) continue; if (i + 1 <= w and db.test(i - 1)) { dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % MOD; } else if (i - 1 >= 1 and db.test(i - 2)) { dp[i - 1][j + 1] = (dp[i - 1][j + 1] + dp[i][j]) % MOD; } else { dp[i][j + 1] = (dp[i][j + 1] + dp[i][j]) % MOD; } } } } cout << dp[k][h + 1] << endl; }
#include <bits/stdc++.h> using ll = long long; using Int = int; #define int ll #define rep(i, n) for (int i = 0; i < n; i++) #define loop(i, s, n) for (int i = s; i < n; i++) #define erep(e, v) for (auto &&e : v) #define all(in) in.begin(), in.end() #define MP make_pair #define INF (sizeof(int) == 4 ? (int)1e9 : (int)1e18) #define EPS 0.0000000001 using namespace std; template <class T, class S> void cmin(T &a, const S &b) { if (a > b) a = b; } template <class T, class S> void cmax(T &a, const S &b) { if (a < b) a = b; } template <typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); } template <typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); } template <class T> void join(T a) { for (auto itr : a) { if (itr != *a.begin()) cout << " "; cout << itr; } } using ld = long double; using pii = pair<int, int>; using piii = pair<int, pii>; int W, H; int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0}; bool valid(int x, int y) { return (0 <= x && x < W) && (0 <= y && y < H); } int MOD = 1000000007; class dynamic_bitset { public: long long bit; string sbit = ""; unsigned long long bitsize = 0; dynamic_bitset(int _bit) : bit{_bit} { for (int t = 1, num = 1; bitsize == 0; t++, num *= 2) { if (num - 1 >= bit) bitsize = t; } for (int i = 0; i < bitsize; i++) { sbit = ((bit >> i & 1) == 1 ? "1" : "0") + sbit; } } dynamic_bitset(int _bit, int bitrange) : bit{_bit} { for (int t = 1, num = 1; bitsize == 0; t++, num *= 2) { if (num - 1 >= bit) bitsize = t; } for (int i = 0; i < bitrange; i++) { sbit = (i < bitsize and ((bit >> i & 1) == 1) ? "1" : "0") + sbit; } } auto test(int _idx) { assert(_idx < sbit.size() && "excution will be out of range"); return sbit[_idx] == '1'; } void set(int _idx) { assert(_idx < sbit.size() && "excution will be out of range"); sbit[_idx] = '1'; } auto size() { return sbit.size(); } }; int ans = 0; signed main() { int h, w, k; cin >> h >> w >> k; auto dp = vectors(300, 300, 0LL); dp[1][1] = 1; for (int j = 1; j <= h; j++) { for (int i = 1; i <= w; i++) { for (int bit = 0; bit < (1 << (w - 1)); bit++) { auto db = dynamic_bitset(bit, w - 1); bool isValid = true; rep(i, (int)db.size() - 1) { if (db.test(i) and db.test(i + 1)) isValid = false; } if (!isValid) continue; if (i + 1 <= w and db.test(i - 1)) { dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % MOD; } else if (i - 1 >= 1 and db.test(i - 2)) { dp[i - 1][j + 1] = (dp[i - 1][j + 1] + dp[i][j]) % MOD; } else { dp[i][j + 1] = (dp[i][j + 1] + dp[i][j]) % MOD; } } } } cout << dp[k][h + 1] << endl; }
replace
81
82
81
82
0
p03222
C++
Runtime Error
#include <algorithm> #include <array> #include <cstdio> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <sstream> #include <string.h> #include <string> #include <unistd.h> #include <vector> #define ALL(a) (a).begin(), (a).end() const long long INF = 1LL << 58; const long long MOD = 1e9 + 7; using namespace std; typedef long long ll; struct point { int x; int y; }; int gcd(int a, int b) { if (a > b) { return gcd(b, a); } return a == 0 ? b : gcd(b % a, a); } int lcm(int m, int n) { // 引数に0がある場合は0を返す if ((0 == m) || (0 == n)) return 0; return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n) } // lcm int input() { int x; cin >> x; return x; } int moji(char in) { int ans = (int)in - (int)'a'; if ((ans < 0) || (ans > 25)) { ans = 26; } return ans; } const int VV = 10; // 場合に応じてVVの値のみ変更する必要あり // dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能 int cost[VV][VV]; int d[VV]; bool used[VV]; void dijkstra(int s) { fill(d, d + VV, 100000); fill(used, used + VV, false); d[s] = 0; while (true) { int v = -1; for (int u = 0; u < VV; u++) { if (!used[u] && (v == -1 || d[u] < d[v])) v = u; } if (v == -1) break; used[v] = true; for (int u = 0; u < VV; u++) { d[u] = min(d[u], d[v] + cost[v][u]); } } } int compare_int(const void *a, const void *b) // qsort(quick sort利用時に使用) { return *(int *)a - *(int *)b; } int binary_searchh(long long x, long long k[], int n) { int l = 0; int r = n; while (r - l >= 1) { int i = (l + r) / 2; if (k[i] == x) return i; else if (k[i] < x) l = i + 1; else r = i; } return -1; } struct File { int aa; int bb; File(const int &aa, const int &bb) : aa(aa), bb(bb) {} }; bool operator<(const File &a, const File &b) { // ファイル種別、ファイル名の順番で優先順位を付けて比較 return std::tie(a.aa, a.bb) < std::tie(b.aa, b.bb); } long long kaijo(long long x) { long long l = 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 + 7; long long sum = 1; for (int i = x; i > 0; i--) { sum *= i; if (sum > l) { sum %= l; } } return sum; } template <class T> void chmin(T &a, T b) { if (a > b) { a = b; } } // formerは前方のindex(自分自身を含んで良い) template <class T> int former(const vector<T> &v, T x) { return upper_bound(v.begin(), v.end(), x) - v.begin() - 1; } // latterは後方のindex(自分自身を含んで良い) template <class T> int latter(const vector<T> &v, T x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); } int main() { int H, W, K; cin >> H >> W >> K; K--; long long dp[H + 1][W]; for (int i = 0; i < H + 1; i++) { for (int j = 0; j < W; j++) { dp[i][j] = 0; } } dp[0][0] = 1; for (int h = 0; h < H + 1; h++) { for (int b = 0; b < (1 << (W - 1)); b++) { bool ok = true; for (int x = 0; x < W - 2; x++) { if ((b >> x) % 4 == 3) { ok = false; break; } } if (!ok) { continue; } int hh[W]; for (int i = 0; i < W; i++) { hh[i] = i; } for (int i = 0; i < W - 1; i++) { if (b & (1 << i)) { swap(hh[i], hh[i + 1]); } } for (int i = 0; i < W; ++i) { dp[h + 1][hh[i]] += dp[h][i]; dp[h + 1][hh[i]] %= MOD; } } } cout << dp[H][K] << endl; }
#include <algorithm> #include <array> #include <cstdio> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <sstream> #include <string.h> #include <string> #include <unistd.h> #include <vector> #define ALL(a) (a).begin(), (a).end() const long long INF = 1LL << 58; const long long MOD = 1e9 + 7; using namespace std; typedef long long ll; struct point { int x; int y; }; int gcd(int a, int b) { if (a > b) { return gcd(b, a); } return a == 0 ? b : gcd(b % a, a); } int lcm(int m, int n) { // 引数に0がある場合は0を返す if ((0 == m) || (0 == n)) return 0; return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n) } // lcm int input() { int x; cin >> x; return x; } int moji(char in) { int ans = (int)in - (int)'a'; if ((ans < 0) || (ans > 25)) { ans = 26; } return ans; } const int VV = 10; // 場合に応じてVVの値のみ変更する必要あり // dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能 int cost[VV][VV]; int d[VV]; bool used[VV]; void dijkstra(int s) { fill(d, d + VV, 100000); fill(used, used + VV, false); d[s] = 0; while (true) { int v = -1; for (int u = 0; u < VV; u++) { if (!used[u] && (v == -1 || d[u] < d[v])) v = u; } if (v == -1) break; used[v] = true; for (int u = 0; u < VV; u++) { d[u] = min(d[u], d[v] + cost[v][u]); } } } int compare_int(const void *a, const void *b) // qsort(quick sort利用時に使用) { return *(int *)a - *(int *)b; } int binary_searchh(long long x, long long k[], int n) { int l = 0; int r = n; while (r - l >= 1) { int i = (l + r) / 2; if (k[i] == x) return i; else if (k[i] < x) l = i + 1; else r = i; } return -1; } struct File { int aa; int bb; File(const int &aa, const int &bb) : aa(aa), bb(bb) {} }; bool operator<(const File &a, const File &b) { // ファイル種別、ファイル名の順番で優先順位を付けて比較 return std::tie(a.aa, a.bb) < std::tie(b.aa, b.bb); } long long kaijo(long long x) { long long l = 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 + 7; long long sum = 1; for (int i = x; i > 0; i--) { sum *= i; if (sum > l) { sum %= l; } } return sum; } template <class T> void chmin(T &a, T b) { if (a > b) { a = b; } } // formerは前方のindex(自分自身を含んで良い) template <class T> int former(const vector<T> &v, T x) { return upper_bound(v.begin(), v.end(), x) - v.begin() - 1; } // latterは後方のindex(自分自身を含んで良い) template <class T> int latter(const vector<T> &v, T x) { return lower_bound(v.begin(), v.end(), x) - v.begin(); } int main() { int H, W, K; cin >> H >> W >> K; K--; long long dp[H + 1][W]; for (int i = 0; i < H + 1; i++) { for (int j = 0; j < W; j++) { dp[i][j] = 0; } } dp[0][0] = 1; for (int h = 0; h < H; h++) { for (int b = 0; b < (1 << (W - 1)); b++) { bool ok = true; for (int x = 0; x < W - 2; x++) { if ((b >> x) % 4 == 3) { ok = false; break; } } if (!ok) { continue; } int hh[W]; for (int i = 0; i < W; i++) { hh[i] = i; } for (int i = 0; i < W - 1; i++) { if (b & (1 << i)) { swap(hh[i], hh[i + 1]); } } for (int i = 0; i < W; ++i) { dp[h + 1][hh[i]] += dp[h][i]; dp[h + 1][hh[i]] %= MOD; } } } cout << dp[H][K] << endl; }
replace
142
143
142
143
0
p03222
C++
Runtime Error
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline") // #pragma GCC option("arch=native", "tune=native", "no-zero-upper") // #pragma GCC // target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") // #pragma GCC optimize("Ofast") // #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning") // #pragma GCC option("D_GLIBCXX_PARALLEL","openmp") #pragma GCC optimize("O3") #pragma GCC target("avx2") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef vector<int> vi; typedef vector<ll> vll; // #define int long long #define pb push_back #define mp make_pair #define eps 1e-9 #define INF 2000000000 // 2e9 #define LLINF 2000000000000000000ll // 2e18 (llmax:9e18) #define fi first #define sec second #define all(x) (x).begin(), (x).end() #define sq(x) ((x) * (x)) #define dmp(x) cerr << #x << ": " << x << endl; template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } template <class T> using MaxHeap = priority_queue<T>; template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>; template <class T> vector<T> vect(int len, T elem) { return vector<T>(len, elem); } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.fi << ',' << p.sec; return os; } template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.fi >> p.sec; return is; } template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (int i = 0; i < vec.size(); i++) { os << vec[i]; if (i + 1 < vec.size()) os << ' '; } return os; } template <class T> istream &operator>>(istream &is, vector<T> &vec) { for (int i = 0; i < vec.size(); i++) is >> vec[i]; return is; } void fastio() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); } template <int MOD> struct ModInt { ll val; ModInt() : val(0ll) {} ModInt(const ll &v) : val(((v % MOD) + MOD) % MOD) {} bool operator==(const ModInt &x) const { return val == x.val; } bool operator!=(const ModInt &x) const { return !(*this == x); } bool operator<(const ModInt &x) const { return val < x.val; } bool operator>(const ModInt &x) const { return val > x.val; } bool operator>=(const ModInt &x) const { return !(*this < x); } bool operator<=(const ModInt &x) const { return !(*this > x); } ModInt operator-() const { return ModInt(MOD - val); } ModInt inv() const { return this->pow(MOD - 2); } ModInt &operator+=(const ModInt &x) { if ((val += x.val) >= MOD) val -= MOD; return *this; } ModInt &operator-=(const ModInt &x) { if ((val += MOD - x.val) >= MOD) val -= MOD; return *this; } ModInt &operator*=(const ModInt &x) { (val *= x.val) %= MOD; return *this; } ModInt &operator/=(const ModInt &x) { return *this *= x.inv(); }; ModInt operator+(const ModInt &x) const { return ModInt(*this) += x; } ModInt operator-(const ModInt &x) const { return ModInt(*this) -= x; } ModInt operator*(const ModInt &x) const { return ModInt(*this) *= x; } ModInt operator/(const ModInt &x) const { return ModInt(*this) /= x; } friend istream &operator>>(istream &i, ModInt &x) { ll v; i >> v; x = v; return i; } friend ostream &operator<<(ostream &o, const ModInt &x) { o << x.val; return o; } ModInt pow(ll x) const { auto res = ModInt(1ll); auto b = *this; while (x) { if (x & 1) res *= b; x >>= 1; b *= b; } return res; } }; template <int MOD> ModInt<MOD> pow(ModInt<MOD> a, ll x) { ModInt<MOD> res = ModInt<MOD>(1ll); while (x) { if (x & 1) res *= a; x >>= 1; a *= a; } return res; } constexpr int MOD = 1e9 + 7; // constexpr int MOD = 998244353; using mint = ModInt<MOD>; vector<mint> inv, fac, facinv; // notice: 0C0 = 1 mint nCr(int n, int r) { assert(!(n < r)); assert(!(n < 0 || r < 0)); return fac[n] * facinv[r] * facinv[n - r]; } void init(int SIZE) { fac.resize(SIZE + 1); inv.resize(SIZE + 1); facinv.resize(SIZE + 1); fac[0] = inv[1] = facinv[0] = mint(1ll); for (int i = 1; i <= SIZE; i++) fac[i] = fac[i - 1] * mint(i); for (int i = 2; i <= SIZE; i++) inv[i] = mint(0ll) - mint(MOD / i) * inv[MOD % i]; for (int i = 1; i <= SIZE; i++) facinv[i] = facinv[i - 1] * inv[i]; return; } #define endl "\n" void solve() { int H, W, K; cin >> H >> W >> K; K--; if (W == 1) { cout << 1 << endl; return; } auto dp = vect(H + 1, vect(W, mint(0))); dp[0][0] = mint(1); for (int i = 0; i < H; i++) { for (int j = 0; j < (1 << (W - 1)); j++) { bool judge = true; for (int k = 0; k < W; k++) { if (((j >> k) & 1) && ((j >> (k + 1)) & 1)) judge = false; } if (!judge) continue; for (int k = 0; k < W; k++) { if ((j >> k) & 1) dp[i + 1][k + 1] += dp[i][k]; else if (k > 0 && ((j >> (k - 1)) & 1)) dp[i + 1][k - 1] += dp[i][k]; else dp[i + 1][k] += dp[i][k]; } } } // for (auto &col : dp) cout << col << endl; cout << dp[H][K] << endl; return; } signed main() { fastio(); solve(); // int t; // cin >> t; // while (t--) solve(); // int t; cin >> t; // for(int i=1;i<=t;i++){ // cout << "Case #" << i << ": "; // solve(); // } return 0; }
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline") // #pragma GCC option("arch=native", "tune=native", "no-zero-upper") // #pragma GCC // target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") // #pragma GCC optimize("Ofast") // #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning") // #pragma GCC option("D_GLIBCXX_PARALLEL","openmp") // #pragma GCC optimize("O3") // #pragma GCC target("avx2") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef vector<int> vi; typedef vector<ll> vll; // #define int long long #define pb push_back #define mp make_pair #define eps 1e-9 #define INF 2000000000 // 2e9 #define LLINF 2000000000000000000ll // 2e18 (llmax:9e18) #define fi first #define sec second #define all(x) (x).begin(), (x).end() #define sq(x) ((x) * (x)) #define dmp(x) cerr << #x << ": " << x << endl; template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } template <class T> using MaxHeap = priority_queue<T>; template <class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>; template <class T> vector<T> vect(int len, T elem) { return vector<T>(len, elem); } template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.fi << ',' << p.sec; return os; } template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.fi >> p.sec; return is; } template <class T> ostream &operator<<(ostream &os, const vector<T> &vec) { for (int i = 0; i < vec.size(); i++) { os << vec[i]; if (i + 1 < vec.size()) os << ' '; } return os; } template <class T> istream &operator>>(istream &is, vector<T> &vec) { for (int i = 0; i < vec.size(); i++) is >> vec[i]; return is; } void fastio() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); } template <int MOD> struct ModInt { ll val; ModInt() : val(0ll) {} ModInt(const ll &v) : val(((v % MOD) + MOD) % MOD) {} bool operator==(const ModInt &x) const { return val == x.val; } bool operator!=(const ModInt &x) const { return !(*this == x); } bool operator<(const ModInt &x) const { return val < x.val; } bool operator>(const ModInt &x) const { return val > x.val; } bool operator>=(const ModInt &x) const { return !(*this < x); } bool operator<=(const ModInt &x) const { return !(*this > x); } ModInt operator-() const { return ModInt(MOD - val); } ModInt inv() const { return this->pow(MOD - 2); } ModInt &operator+=(const ModInt &x) { if ((val += x.val) >= MOD) val -= MOD; return *this; } ModInt &operator-=(const ModInt &x) { if ((val += MOD - x.val) >= MOD) val -= MOD; return *this; } ModInt &operator*=(const ModInt &x) { (val *= x.val) %= MOD; return *this; } ModInt &operator/=(const ModInt &x) { return *this *= x.inv(); }; ModInt operator+(const ModInt &x) const { return ModInt(*this) += x; } ModInt operator-(const ModInt &x) const { return ModInt(*this) -= x; } ModInt operator*(const ModInt &x) const { return ModInt(*this) *= x; } ModInt operator/(const ModInt &x) const { return ModInt(*this) /= x; } friend istream &operator>>(istream &i, ModInt &x) { ll v; i >> v; x = v; return i; } friend ostream &operator<<(ostream &o, const ModInt &x) { o << x.val; return o; } ModInt pow(ll x) const { auto res = ModInt(1ll); auto b = *this; while (x) { if (x & 1) res *= b; x >>= 1; b *= b; } return res; } }; template <int MOD> ModInt<MOD> pow(ModInt<MOD> a, ll x) { ModInt<MOD> res = ModInt<MOD>(1ll); while (x) { if (x & 1) res *= a; x >>= 1; a *= a; } return res; } constexpr int MOD = 1e9 + 7; // constexpr int MOD = 998244353; using mint = ModInt<MOD>; vector<mint> inv, fac, facinv; // notice: 0C0 = 1 mint nCr(int n, int r) { assert(!(n < r)); assert(!(n < 0 || r < 0)); return fac[n] * facinv[r] * facinv[n - r]; } void init(int SIZE) { fac.resize(SIZE + 1); inv.resize(SIZE + 1); facinv.resize(SIZE + 1); fac[0] = inv[1] = facinv[0] = mint(1ll); for (int i = 1; i <= SIZE; i++) fac[i] = fac[i - 1] * mint(i); for (int i = 2; i <= SIZE; i++) inv[i] = mint(0ll) - mint(MOD / i) * inv[MOD % i]; for (int i = 1; i <= SIZE; i++) facinv[i] = facinv[i - 1] * inv[i]; return; } #define endl "\n" void solve() { int H, W, K; cin >> H >> W >> K; K--; if (W == 1) { cout << 1 << endl; return; } auto dp = vect(H + 1, vect(W, mint(0))); dp[0][0] = mint(1); for (int i = 0; i < H; i++) { for (int j = 0; j < (1 << (W - 1)); j++) { bool judge = true; for (int k = 0; k < W; k++) { if (((j >> k) & 1) && ((j >> (k + 1)) & 1)) judge = false; } if (!judge) continue; for (int k = 0; k < W; k++) { if ((j >> k) & 1) dp[i + 1][k + 1] += dp[i][k]; else if (k > 0 && ((j >> (k - 1)) & 1)) dp[i + 1][k - 1] += dp[i][k]; else dp[i + 1][k] += dp[i][k]; } } } // for (auto &col : dp) cout << col << endl; cout << dp[H][K] << endl; return; } signed main() { fastio(); solve(); // int t; // cin >> t; // while (t--) solve(); // int t; cin >> t; // for(int i=1;i<=t;i++){ // cout << "Case #" << i << ": "; // solve(); // } return 0; }
replace
8
10
8
10
0
p03222
C++
Runtime Error
#include <algorithm> #include <bits/stdc++.h> #include <string> using namespace std; int main() { int H, W, K; cin >> H >> W >> K; long long int dp[100][10] = {}; long long int P = 1e9 + 7; int Fib[8] = {1, 1, 2, 3, 5, 8, 13, 21}; if (W == 1) { cout << 1 << endl; } else { dp[0][1] = 1; for (int i = 1; i < 105; i++) { dp[i][1] = ((dp[i - 1][1] * Fib[W - 1]) % P + (dp[i - 1][2] * Fib[W - 2]) % P) % P; dp[i][W] = ((dp[i - 1][W] * Fib[W - 1]) % P + (dp[i - 1][W - 1] * Fib[W - 2]) % P) % P; for (int j = 2; j < W; j++) { dp[i][j] = ((dp[i - 1][j - 1] * Fib[j - 2] * Fib[W - j]) % P + (dp[i - 1][j] * Fib[j - 1] * Fib[W - j]) % P + (dp[i - 1][j + 1] * Fib[j - 1] * Fib[W - j - 1]) % P) % P; } } cout << dp[H][K] << endl; } }
#include <algorithm> #include <bits/stdc++.h> #include <string> using namespace std; int main() { int H, W, K; cin >> H >> W >> K; long long int dp[110][10] = {}; long long int P = 1e9 + 7; int Fib[8] = {1, 1, 2, 3, 5, 8, 13, 21}; if (W == 1) { cout << 1 << endl; } else { dp[0][1] = 1; for (int i = 1; i < 105; i++) { dp[i][1] = ((dp[i - 1][1] * Fib[W - 1]) % P + (dp[i - 1][2] * Fib[W - 2]) % P) % P; dp[i][W] = ((dp[i - 1][W] * Fib[W - 1]) % P + (dp[i - 1][W - 1] * Fib[W - 2]) % P) % P; for (int j = 2; j < W; j++) { dp[i][j] = ((dp[i - 1][j - 1] * Fib[j - 2] * Fib[W - j]) % P + (dp[i - 1][j] * Fib[j - 1] * Fib[W - j]) % P + (dp[i - 1][j + 1] * Fib[j - 1] * Fib[W - j - 1]) % P) % P; } } cout << dp[H][K] << endl; } }
replace
7
8
7
8
-6
*** stack smashing detected ***: terminated
p03222
C++
Runtime Error
#include <iostream> using namespace std; #define ll long long const ll mod = 1000000007; int H, W, K; ll dp[100][10]; ll sub(int n) { if (n <= 0) { return 1; } else if (n == 1) { return 2; } else { return sub(n - 1) + sub(n - 2); } } int solve() { if (W == 1) { cout << 1 << endl; return 0; } // 初期値 dp[0][0] = 1; for (int i = 1; i < W; i++) { dp[0][i] = 0; } for (int i = 1; i <= H; i++) { for (int j = 0; j < W; j++) { if (j == 0) { dp[i][j] = sub(W - 2) * dp[i - 1][j] + sub(W - 3) * dp[i - 1][j + 1]; } else if (j == W - 1) { dp[i][j] = sub(W - 3) * dp[i - 1][j - 1] + sub(W - 2) * dp[i - 1][j]; } else { dp[i][j] = sub(j - 2) * sub(W - 2 - j) * dp[i - 1][j - 1] + sub(j - 1) * sub(W - 2 - j) * dp[i - 1][j] + sub(j - 1) * sub(W - 3 - j) * dp[i - 1][j + 1]; } dp[i][j] %= mod; } } cout << dp[H][K - 1] << endl; return 0; } int main() { cin >> H >> W >> K; solve(); return 0; }
#include <iostream> using namespace std; #define ll long long const ll mod = 1000000007; int H, W, K; ll dp[110][15]; ll sub(int n) { if (n <= 0) { return 1; } else if (n == 1) { return 2; } else { return sub(n - 1) + sub(n - 2); } } int solve() { if (W == 1) { cout << 1 << endl; return 0; } // 初期値 dp[0][0] = 1; for (int i = 1; i < W; i++) { dp[0][i] = 0; } for (int i = 1; i <= H; i++) { for (int j = 0; j < W; j++) { if (j == 0) { dp[i][j] = sub(W - 2) * dp[i - 1][j] + sub(W - 3) * dp[i - 1][j + 1]; } else if (j == W - 1) { dp[i][j] = sub(W - 3) * dp[i - 1][j - 1] + sub(W - 2) * dp[i - 1][j]; } else { dp[i][j] = sub(j - 2) * sub(W - 2 - j) * dp[i - 1][j - 1] + sub(j - 1) * sub(W - 2 - j) * dp[i - 1][j] + sub(j - 1) * sub(W - 3 - j) * dp[i - 1][j + 1]; } dp[i][j] %= mod; } } cout << dp[H][K - 1] << endl; return 0; } int main() { cin >> H >> W >> K; solve(); return 0; }
replace
7
8
7
8
0
p03222
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; long mod = 1000000007; long dp[101][8] = {}; int H, W; vector<vector<int>> v; // 横棒のパターン int bit[8] = {}; void addBit() { int l = W - 1; for (int i = 1; i < l; i++) { if (bit[i - 1] == 1 && bit[i] == 1) return; } vector<int> tmp(l); for (int i = 0; i < l; i++) { tmp[i] = bit[i]; } v.push_back(tmp); } void makeBit(int k) { if (k == W - 1) { addBit(); return; } makeBit(k + 1); bit[k] = 1; makeBit(k + 1); bit[k] = 0; } void swap(long a[], vector<int> b, long c[]) { for (int i = 0; i < W - 1; i++) { if (b[i] == 1) { c[i] = a[i + 1]; c[i + 1] = a[i]; } } } void disp(long a[]) { for (int i = 0; i < W; i++) { cout << a[i] << " "; } cout << "\n"; } int main() { // cin.tie(0); // ios::sync_with_stdio(false); int K; cin >> H >> W >> K; if (W == 1) { if (K == 1) cout << "1\n"; else cout << "0\n"; return 0; } dp[0][0] = 1; makeBit(0); // for (int i = 0; i < v.size(); i++) { // for(int j = 0; j < W - 1; j++) { // cout << v[i][j] << " "; // } // cout << "\n"; // } int l = v.size(); for (int i = 1; i <= H; i++) { for (int j = 0; j < l; j++) { long *c = new long[W](); memcpy(c, dp[i - 1], sizeof(dp[i - 1])); // disp(c); // disp(dp[i - 1]); swap(dp[i - 1], v[j], c); // disp(c); for (int k = 0; k < W; k++) { dp[i][k] += c[k]; dp[i][k] %= mod; } } } cout << dp[H][K - 1] << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; long mod = 1000000007; long dp[101][8] = {}; int H, W; vector<vector<int>> v; // 横棒のパターン int bit[8] = {}; void addBit() { int l = W - 1; for (int i = 1; i < l; i++) { if (bit[i - 1] == 1 && bit[i] == 1) return; } vector<int> tmp(l); for (int i = 0; i < l; i++) { tmp[i] = bit[i]; } v.push_back(tmp); } void makeBit(int k) { if (k == W - 1) { addBit(); return; } makeBit(k + 1); bit[k] = 1; makeBit(k + 1); bit[k] = 0; } void swap(long a[], vector<int> b, long c[]) { for (int i = 0; i < W - 1; i++) { if (b[i] == 1) { c[i] = a[i + 1]; c[i + 1] = a[i]; } } } void disp(long a[]) { for (int i = 0; i < W; i++) { cout << a[i] << " "; } cout << "\n"; } int main() { // cin.tie(0); // ios::sync_with_stdio(false); int K; cin >> H >> W >> K; if (W == 1) { if (K == 1) cout << "1\n"; else cout << "0\n"; return 0; } dp[0][0] = 1; makeBit(0); // for (int i = 0; i < v.size(); i++) { // for(int j = 0; j < W - 1; j++) { // cout << v[i][j] << " "; // } // cout << "\n"; // } int l = v.size(); for (int i = 1; i <= H; i++) { for (int j = 0; j < l; j++) { long *c = new long[W](); for (int k = 0; k < W; k++) { c[k] = dp[i - 1][k]; } // memcpy(c, dp[i - 1], sizeof(dp[i - 1])); // disp(c); // disp(dp[i - 1]); swap(dp[i - 1], v[j], c); // disp(c); for (int k = 0; k < W; k++) { dp[i][k] += c[k]; dp[i][k] %= mod; } } } cout << dp[H][K - 1] << "\n"; return 0; }
replace
74
75
74
78
-6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
p03222
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> #define MOD 1000000007 #define INF 1000000001 using namespace std; typedef unsigned long long ull; typedef long long ll; template <class T> ostream &operator<<(ostream &o, const vector<T> &obj) { o << "["; for (int i = 0; i < (int)obj.size(); ++i) o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o; } template <class T, class U> ostream &operator<<(ostream &o, const pair<T, U> &obj) { o << "(" << obj.first << ", " << obj.second << ")"; return o; } template <class T, class U> ostream &operator<<(ostream &o, const map<T, U> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; } template <class T> ostream &operator<<(ostream &o, const set<T> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; } template <class T> ostream &operator<<(ostream &o, const queue<T> &obj) { queue<T> obj_cp = obj; bool first = true; o << "{"; while (!obj_cp.empty()) { o << (!first ? ", " : "") << obj_cp.front(); obj_cp.pop(); first = false; } o << "}"; return o; } void print() { cout << "\n"; } template <class Head, class... Body> void print(Head head, Body... body) { cout << head << " "; print(body...); } int H, W, K; vector<int> pattern_nums; void init_pnums() { pattern_nums.resize(W); pattern_nums[0] = 1; pattern_nums[1] = 2; for (int i = 0; i < W; ++i) { pattern_nums[i + 2] = pattern_nums[i] + pattern_nums[i + 1]; } } int get_pnum(int h) { if (h < 0) return 1; return pattern_nums[h]; } int main(int argc, char const *argv[]) { cin >> H >> W >> K; init_pnums(); // print(pattern_nums); vector<vector<ull>> dp(H + 1, vector<ull>(W, 0)); dp[0][0] = 1; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { dp[i + 1][j] = (dp[i][j] * get_pnum(j - 1) * get_pnum(W - j - 2)) % MOD; // print(i, j, "center", dp[i][j] * get_pnum(j-1) * get_pnum(W-j-2)); if (j > 0) { dp[i + 1][j] = (dp[i + 1][j] + dp[i][j - 1] * get_pnum(j - 2) * get_pnum(W - j - 2)) % MOD; // print(i, j, "left", dp[i][j-1] * get_pnum(j-2) * get_pnum(W-j-2)); } if (j < W - 1) { dp[i + 1][j] = (dp[i + 1][j] + dp[i][j + 1] * get_pnum(j - 1) * get_pnum(W - j - 3)) % MOD; // print(i, j, "right", dp[i][j+1] * get_pnum(j-1) * get_pnum(W-j-3)); } } // print(i+1, dp[i+1]); } cout << dp[H][K - 1] << endl; return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <iterator> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> #define MOD 1000000007 #define INF 1000000001 using namespace std; typedef unsigned long long ull; typedef long long ll; template <class T> ostream &operator<<(ostream &o, const vector<T> &obj) { o << "["; for (int i = 0; i < (int)obj.size(); ++i) o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o; } template <class T, class U> ostream &operator<<(ostream &o, const pair<T, U> &obj) { o << "(" << obj.first << ", " << obj.second << ")"; return o; } template <class T, class U> ostream &operator<<(ostream &o, const map<T, U> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; } template <class T> ostream &operator<<(ostream &o, const set<T> &obj) { o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o; } template <class T> ostream &operator<<(ostream &o, const queue<T> &obj) { queue<T> obj_cp = obj; bool first = true; o << "{"; while (!obj_cp.empty()) { o << (!first ? ", " : "") << obj_cp.front(); obj_cp.pop(); first = false; } o << "}"; return o; } void print() { cout << "\n"; } template <class Head, class... Body> void print(Head head, Body... body) { cout << head << " "; print(body...); } int H, W, K; vector<int> pattern_nums; void init_pnums() { pattern_nums.resize(W); pattern_nums[0] = 1; pattern_nums[1] = 2; for (int i = 0; i <= W - 2; ++i) { pattern_nums[i + 2] = pattern_nums[i] + pattern_nums[i + 1]; } } int get_pnum(int h) { if (h < 0) return 1; return pattern_nums[h]; } int main(int argc, char const *argv[]) { cin >> H >> W >> K; init_pnums(); // print(pattern_nums); vector<vector<ull>> dp(H + 1, vector<ull>(W, 0)); dp[0][0] = 1; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { dp[i + 1][j] = (dp[i][j] * get_pnum(j - 1) * get_pnum(W - j - 2)) % MOD; // print(i, j, "center", dp[i][j] * get_pnum(j-1) * get_pnum(W-j-2)); if (j > 0) { dp[i + 1][j] = (dp[i + 1][j] + dp[i][j - 1] * get_pnum(j - 2) * get_pnum(W - j - 2)) % MOD; // print(i, j, "left", dp[i][j-1] * get_pnum(j-2) * get_pnum(W-j-2)); } if (j < W - 1) { dp[i + 1][j] = (dp[i + 1][j] + dp[i][j + 1] * get_pnum(j - 1) * get_pnum(W - j - 3)) % MOD; // print(i, j, "right", dp[i][j+1] * get_pnum(j-1) * get_pnum(W-j-3)); } } // print(i+1, dp[i+1]); } cout << dp[H][K - 1] << endl; return 0; }
replace
72
73
72
73
0
p03222
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; const int MOD = 1e9 + 7; int H, W, K; vector<int> fib; ll ans; void input() { cin >> H >> W >> K; } int solve(int n) { if (n < 0) return 1; return fib[n]; } int main() { input(); fib = vector<int>(W); fib[0] = 1; fib[1] = 2; for (int i = 2; i < W; i++) fib[i] = fib[i - 1] + fib[i - 2]; vector<ll> w1, w2; w1 = vector<ll>(W, 0); w1[0] = 1; rep(i, H) { w2 = vector<ll>(W, 0); for (int j = 0; j < W; j++) { if (j > 0) w2[j - 1] = (w2[j - 1] + w1[j] * solve(j - 2) * solve(W - j - 2)) % MOD; w2[j] = (w2[j] + w1[j] * solve(j - 1) * solve(W - j - 2)) % MOD; if (j <= W) w2[j + 1] = (w2[j + 1] + w1[j] * solve(j - 1) * solve(W - j - 3)) % MOD; } w1 = w2; } cout << w1[K - 1] << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; const int MOD = 1e9 + 7; int H, W, K; vector<int> fib; ll ans; void input() { cin >> H >> W >> K; } int solve(int n) { if (n < 0) return 1; return fib[n]; } int main() { input(); fib = vector<int>(W); fib[0] = 1; fib[1] = 2; for (int i = 2; i < W; i++) fib[i] = fib[i - 1] + fib[i - 2]; vector<ll> w1, w2; w1 = vector<ll>(W, 0); w1[0] = 1; rep(i, H) { w2 = vector<ll>(W, 0); for (int j = 0; j < W; j++) { if (j > 0) w2[j - 1] = (w2[j - 1] + w1[j] * solve(j - 2) * solve(W - j - 2)) % MOD; w2[j] = (w2[j] + w1[j] * solve(j - 1) * solve(W - j - 2)) % MOD; if (j < W - 1) w2[j + 1] = (w2[j + 1] + w1[j] * solve(j - 1) * solve(W - j - 3)) % MOD; } w1 = w2; } cout << w1[K - 1] << endl; }
replace
34
35
34
35
0
p03222
C++
Runtime Error
#include <iostream> using namespace std; const int MOD = 1000 * 1000 * 1000 + 7; int subcount(int n) { if (n <= 0) { return 1; } int c = 0; for (int i = 0; i < (1 << n); ++i) { bool ok = true; for (int k = 0; k + 1 < n; ++k) { if ((i & (1 << k)) && (i & (1 << (k + 1)))) { ok = false; break; } } if (ok) { ++c; } } return c; } int main() { int H, W, K; cin >> H >> W >> K; long long dp[100][8 + 1] = {}; dp[1][1] = subcount(W - 2); dp[1][2] = subcount(W - 3); for (int j = 3; j <= W; ++j) { dp[1][j] = 0; } for (int i = 2; i <= H; ++i) { for (int j = 1; j <= W; ++j) { if (1 < j) { dp[i][j - 1] += 1LL * subcount(j - 3) * subcount(W - j - 1) * dp[i - 1][j]; dp[i][j - 1] %= MOD; } dp[i][j] += 1LL * subcount(j - 2) * subcount(W - j - 1) * dp[i - 1][j]; dp[i][j] %= MOD; if (j < W) { dp[i][j + 1] += 1LL * subcount(j - 2) * subcount(W - j - 2) * dp[i - 1][j]; dp[i][j + 1] %= MOD; } } } cout << dp[H][K] << endl; }
#include <iostream> using namespace std; const int MOD = 1000 * 1000 * 1000 + 7; int subcount(int n) { if (n <= 0) { return 1; } int c = 0; for (int i = 0; i < (1 << n); ++i) { bool ok = true; for (int k = 0; k + 1 < n; ++k) { if ((i & (1 << k)) && (i & (1 << (k + 1)))) { ok = false; break; } } if (ok) { ++c; } } return c; } int main() { int H, W, K; cin >> H >> W >> K; long long dp[101][8 + 1] = {}; dp[1][1] = subcount(W - 2); dp[1][2] = subcount(W - 3); for (int j = 3; j <= W; ++j) { dp[1][j] = 0; } for (int i = 2; i <= H; ++i) { for (int j = 1; j <= W; ++j) { if (1 < j) { dp[i][j - 1] += 1LL * subcount(j - 3) * subcount(W - j - 1) * dp[i - 1][j]; dp[i][j - 1] %= MOD; } dp[i][j] += 1LL * subcount(j - 2) * subcount(W - j - 1) * dp[i - 1][j]; dp[i][j] %= MOD; if (j < W) { dp[i][j + 1] += 1LL * subcount(j - 2) * subcount(W - j - 2) * dp[i - 1][j]; dp[i][j + 1] %= MOD; } } } cout << dp[H][K] << endl; }
replace
30
31
30
31
0
p03222
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; const long long MOD = 1e9 + 7; int main() { int H, W, K; cin >> H >> W >> K; // 1*N のところに好きに線を引く (1-index) vector<long long> fr = {1, 1, 2, 3, 5, 8, 13, 21, 34}; // N*W で K で終了する DP vector<vector<long long>> dp(H + 1, vector<long long>(W + 1)); dp[1][1] = fr[W - 1]; if (W >= 2) dp[1][2] = fr[W - 2]; for (int k = 3; k <= 8; k++) dp[1][k] = 0; for (int h = 2; h <= H; h++) { for (int k = 1; k <= W; k++) { dp[h][k] = (dp[h - 1][k] * fr[k - 1] % MOD) * fr[W - k] % MOD; // そのまま降りてくるやつ if (k >= 2) { // 左から dp[h][k] += (dp[h - 1][k - 1] * fr[k - 2] % MOD) * fr[W - k] % MOD; dp[h][k] %= MOD; } if (k <= W - 1) { // 右から dp[h][k] += (dp[h - 1][k + 1] * fr[k - 1] % MOD) * fr[W - k - 1] % MOD; dp[h][k] %= MOD; } } } cout << dp[H][K] << endl; return 0; }
#include <iostream> #include <vector> using namespace std; const long long MOD = 1e9 + 7; int main() { int H, W, K; cin >> H >> W >> K; // 1*N のところに好きに線を引く (1-index) vector<long long> fr = {1, 1, 2, 3, 5, 8, 13, 21, 34}; // N*W で K で終了する DP vector<vector<long long>> dp(H + 1, vector<long long>(W + 1)); dp[1][1] = fr[W - 1]; if (W >= 2) dp[1][2] = fr[W - 2]; for (int k = 3; k <= W; k++) dp[1][k] = 0; for (int h = 2; h <= H; h++) { for (int k = 1; k <= W; k++) { dp[h][k] = (dp[h - 1][k] * fr[k - 1] % MOD) * fr[W - k] % MOD; // そのまま降りてくるやつ if (k >= 2) { // 左から dp[h][k] += (dp[h - 1][k - 1] * fr[k - 2] % MOD) * fr[W - k] % MOD; dp[h][k] %= MOD; } if (k <= W - 1) { // 右から dp[h][k] += (dp[h - 1][k + 1] * fr[k - 1] % MOD) * fr[W - k - 1] % MOD; dp[h][k] %= MOD; } } } cout << dp[H][K] << endl; return 0; }
replace
19
20
19
20
-6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
p03222
C++
Runtime Error
#include <algorithm> #include <cstdlib> #include <iostream> #include <string> #include <utility> using namespace std; int bi(int n, int k) { if (k == 1 && n % 2 == 0) { return 0; } if (k == 1 && n % 2 == 1) { return 1; } if (k >= 2) { return bi(n / 2, k - 1); } } int power(int n) { if (n == 0) { return 1; } else { return 2 * power(n - 1); } } int main() { int H; int W; int K; cin >> H >> W >> K; long int val[10][200] = {}; // 高さn、棒mへ行く経路の数 int sen[10]; int nom; // 線の引き方が正しいか val[0][1] = 1; for (int h = 1; h <= H; h++) { for (int i = 0; i < power(W - 1); i++) { // 線を引く箇所の決定 for (int j = 1; j <= W; j++) { sen[j] = bi(i, j); } nom = 0; for (int j = 1; j <= W - 1; j++) { // 線の引き方が正しいか判定 if (sen[j] == 1 && sen[j + 1] == 1) { nom = 1; } } for (int j = 1; j <= W; j++) { if (nom == 1) { break; } if (j < W && sen[j] == 1) { val[h][j] = val[h][j] + val[h - 1][j + 1]; } else if (j > 1 && sen[j - 1] == 1) { val[h][j] = val[h][j] + val[h - 1][j - 1]; } else { val[h][j] = val[h][j] + val[h - 1][j]; } if (val[h][j] >= 1000000007) { val[h][j] = val[h][j] % 1000000007; } } } } cout << val[H][K]; }
#include <algorithm> #include <cstdlib> #include <iostream> #include <string> #include <utility> using namespace std; int bi(int n, int k) { if (k == 1 && n % 2 == 0) { return 0; } if (k == 1 && n % 2 == 1) { return 1; } if (k >= 2) { return bi(n / 2, k - 1); } } int power(int n) { if (n == 0) { return 1; } else { return 2 * power(n - 1); } } int main() { int H; int W; int K; cin >> H >> W >> K; long int val[200][10] = {}; // 高さn、棒mへ行く経路の数 int sen[10]; int nom; // 線の引き方が正しいか val[0][1] = 1; for (int h = 1; h <= H; h++) { for (int i = 0; i < power(W - 1); i++) { // 線を引く箇所の決定 for (int j = 1; j <= W; j++) { sen[j] = bi(i, j); } nom = 0; for (int j = 1; j <= W - 1; j++) { // 線の引き方が正しいか判定 if (sen[j] == 1 && sen[j + 1] == 1) { nom = 1; } } for (int j = 1; j <= W; j++) { if (nom == 1) { break; } if (j < W && sen[j] == 1) { val[h][j] = val[h][j] + val[h - 1][j + 1]; } else if (j > 1 && sen[j - 1] == 1) { val[h][j] = val[h][j] + val[h - 1][j - 1]; } else { val[h][j] = val[h][j] + val[h - 1][j]; } if (val[h][j] >= 1000000007) { val[h][j] = val[h][j] % 1000000007; } } } } cout << val[H][K]; }
replace
36
37
36
37
0
p03222
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() using ll = long long; const int H = 100, W = 8; const ll MOD = 1e9 + 7; int h, w, k; ll dp[H][W], fib[10]; void pre() { fib[0] = 0, fib[1] = 1; for (int i = 2; i < 10; ++i) fib[i] = fib[i - 1] + fib[i - 2]; int sum = 0; for (int i = 0; i < 10; ++i) { sum += fib[i]; fib[i] = sum; } } int main() { cin.sync_with_stdio(0); cin.tie(0); cin >> h >> w >> k; dp[0][0] = 1; pre(); for (int i = 1; i <= h; ++i) { for (int j = 0; j < w; ++j) { for (int l = -1; l <= 1; ++l) { int width = j + l; if (width >= 0 && width < w) { // Left slots avail, right slots avail ll la = j, ra = w - j - 1; --la, --ra; if (l == -1) --la; if (l == 1) --ra; la = max(0ll, la), ra = max(0ll, ra); la = fib[la] + 1, ra = fib[ra] + 1; ll toAdd = ((dp[i - 1][width] % MOD) * la) % MOD; toAdd *= ra, toAdd %= MOD; dp[i][j] = (dp[i][j] + toAdd) % MOD; } } } } cout << dp[h][k - 1] % MOD; }
#include <bits/stdc++.h> using namespace std; #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() using ll = long long; const int H = 105, W = 8; const ll MOD = 1e9 + 7; int h, w, k; ll dp[H][W], fib[10]; void pre() { fib[0] = 0, fib[1] = 1; for (int i = 2; i < 10; ++i) fib[i] = fib[i - 1] + fib[i - 2]; int sum = 0; for (int i = 0; i < 10; ++i) { sum += fib[i]; fib[i] = sum; } } int main() { cin.sync_with_stdio(0); cin.tie(0); cin >> h >> w >> k; dp[0][0] = 1; pre(); for (int i = 1; i <= h; ++i) { for (int j = 0; j < w; ++j) { for (int l = -1; l <= 1; ++l) { int width = j + l; if (width >= 0 && width < w) { // Left slots avail, right slots avail ll la = j, ra = w - j - 1; --la, --ra; if (l == -1) --la; if (l == 1) --ra; la = max(0ll, la), ra = max(0ll, ra); la = fib[la] + 1, ra = fib[ra] + 1; ll toAdd = ((dp[i - 1][width] % MOD) * la) % MOD; toAdd *= ra, toAdd %= MOD; dp[i][j] = (dp[i][j] + toAdd) % MOD; } } } } cout << dp[h][k - 1] % MOD; }
replace
6
7
6
7
0
p03222
C++
Runtime Error
#include <cmath> #include <iostream> #include <vector> // https://qiita.com/ofutonfuton/items/92b1a6f4a7775f00b6ae using namespace std; typedef long long ll; const ll M = pow(10, 9) + 7; vector<ll> fac(300001); // n!(mod M) vector<ll> ifac(300001); // k!^{M-2} (mod M) // k^{M-2} == k^{-1} // a,bの範囲的にこれだけ配列を用意していけば十分 ll mpow(ll x, ll n) { // x^n(mod M) ←普通にpow(x,n)では溢れてしまうため,随時mod計算 ll ans = 1; while (n != 0) { if (n & 1) ans = ans * x % M; x = x * x % M; n = n >> 1; } return ans; } ll comb(ll a, ll b) { // aCbをmod計算 if (a == 0 && b == 0) return 1; if (a < b || a < 0) return 0; ll tmp = ifac[a - b] * ifac[b] % M; return tmp * fac[a] % M; } ll comb2(ll a, ll b) { // aCbをmod計算 if (a == 0 && b == 0) return 1; if (a < b || a < 0) return 0; ll tmp = ifac[a - b] * ifac[b] % M; return tmp * fac[a] % M; } long long gcd(long long a, long long b) { long long c; if (a < b) { a += b; b = a - b; a -= b; } while (b != 0) { c = a % b; a = b; b = c; } return a; } ll lcm(ll m, ll n) { // 引数に0がある場合は0を返す if ((0 == m) || (0 == n)) return 0; return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n) } // lcm pair<ll, ll> add_bunsuu(pair<ll, ll> a, pair<ll, ll> b) { ll bunbo = lcm(a.second, b.second); cout << a.first << "/" << a.second << endl; cout << b.first << "/" << b.second << endl; cout << a.first * bunbo / a.second + b.first * bunbo / b.second << "/" << bunbo << endl; return make_pair(a.first * bunbo / a.second + b.first * bunbo / b.second, bunbo); } ll valid_amida_pattern(ll w) { if (w <= 0) { return 1; } return valid_amida_pattern(w - 1) % 1000000007 + valid_amida_pattern(w - 2) % 1000000007; } ll int_probs[105][10]; int main() { ll H, W, K; cin >> H >> W >> K; /*ll** int_probs = new ll*[H + 1]; for(ll i = 0; i < H + 1; i ++){ int_probs[i] = new ll[W]; }*/ if (W == 1) { return 1; } for (ll i = 0; i < W; i++) { if (i == 0) { int_probs[0][i] = 1; } else { int_probs[0][i] = 0; } } for (ll i = 1; i < H + 1; i++) { for (ll n = 0; n < W; n++) { if (n == 0) { int_probs[i][n] = int_probs[i - 1][n] * valid_amida_pattern(W - 2) % 1000000007 + int_probs[i - 1][n + 1] * valid_amida_pattern(W - 3) % 1000000007; } else if (n == W - 1) { int_probs[i][n] = int_probs[i - 1][n] * valid_amida_pattern(W - 2) % 1000000007 + int_probs[i - 1][n - 1] * valid_amida_pattern(W - 3) % 1000000007; } else { int_probs[i][n] = int_probs[i - 1][n] * valid_amida_pattern(n - 1) * valid_amida_pattern(W - n - 2) % 1000000007 + int_probs[i - 1][n + 1] * valid_amida_pattern(n - 1) * valid_amida_pattern(W - n - 3) % 1000000007 + int_probs[i - 1][n - 1] * valid_amida_pattern(n - 2) * valid_amida_pattern(W - n - 2) % 1000000007; } int_probs[i][n] = int_probs[i][n] % 1000000007; } } cout << int_probs[H][K - 1] << endl; return 0; }
#include <cmath> #include <iostream> #include <vector> // https://qiita.com/ofutonfuton/items/92b1a6f4a7775f00b6ae using namespace std; typedef long long ll; const ll M = pow(10, 9) + 7; vector<ll> fac(300001); // n!(mod M) vector<ll> ifac(300001); // k!^{M-2} (mod M) // k^{M-2} == k^{-1} // a,bの範囲的にこれだけ配列を用意していけば十分 ll mpow(ll x, ll n) { // x^n(mod M) ←普通にpow(x,n)では溢れてしまうため,随時mod計算 ll ans = 1; while (n != 0) { if (n & 1) ans = ans * x % M; x = x * x % M; n = n >> 1; } return ans; } ll comb(ll a, ll b) { // aCbをmod計算 if (a == 0 && b == 0) return 1; if (a < b || a < 0) return 0; ll tmp = ifac[a - b] * ifac[b] % M; return tmp * fac[a] % M; } ll comb2(ll a, ll b) { // aCbをmod計算 if (a == 0 && b == 0) return 1; if (a < b || a < 0) return 0; ll tmp = ifac[a - b] * ifac[b] % M; return tmp * fac[a] % M; } long long gcd(long long a, long long b) { long long c; if (a < b) { a += b; b = a - b; a -= b; } while (b != 0) { c = a % b; a = b; b = c; } return a; } ll lcm(ll m, ll n) { // 引数に0がある場合は0を返す if ((0 == m) || (0 == n)) return 0; return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n) } // lcm pair<ll, ll> add_bunsuu(pair<ll, ll> a, pair<ll, ll> b) { ll bunbo = lcm(a.second, b.second); cout << a.first << "/" << a.second << endl; cout << b.first << "/" << b.second << endl; cout << a.first * bunbo / a.second + b.first * bunbo / b.second << "/" << bunbo << endl; return make_pair(a.first * bunbo / a.second + b.first * bunbo / b.second, bunbo); } ll valid_amida_pattern(ll w) { if (w <= 0) { return 1; } return valid_amida_pattern(w - 1) % 1000000007 + valid_amida_pattern(w - 2) % 1000000007; } ll int_probs[105][10]; int main() { ll H, W, K; cin >> H >> W >> K; /*ll** int_probs = new ll*[H + 1]; for(ll i = 0; i < H + 1; i ++){ int_probs[i] = new ll[W]; }*/ /*if(W == 1){ cout<< 1 <<endl; }*/ for (ll i = 0; i < W; i++) { if (i == 0) { int_probs[0][i] = 1; } else { int_probs[0][i] = 0; } } for (ll i = 1; i < H + 1; i++) { for (ll n = 0; n < W; n++) { if (n == 0) { int_probs[i][n] = int_probs[i - 1][n] * valid_amida_pattern(W - 2) % 1000000007 + int_probs[i - 1][n + 1] * valid_amida_pattern(W - 3) % 1000000007; } else if (n == W - 1) { int_probs[i][n] = int_probs[i - 1][n] * valid_amida_pattern(W - 2) % 1000000007 + int_probs[i - 1][n - 1] * valid_amida_pattern(W - 3) % 1000000007; } else { int_probs[i][n] = int_probs[i - 1][n] * valid_amida_pattern(n - 1) * valid_amida_pattern(W - n - 2) % 1000000007 + int_probs[i - 1][n + 1] * valid_amida_pattern(n - 1) * valid_amida_pattern(W - n - 3) % 1000000007 + int_probs[i - 1][n - 1] * valid_amida_pattern(n - 2) * valid_amida_pattern(W - n - 2) % 1000000007; } int_probs[i][n] = int_probs[i][n] % 1000000007; } } cout << int_probs[H][K - 1] << endl; return 0; }
replace
99
102
99
102
0
p03222
C++
Runtime Error
#include <bits/stdc++.h> #define int long long int #define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORE(i, a, b) for (int i = (a); i <= (b); ++i) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i) #define RFORE(i, a, b) for (int i = (b); i >= (a); --i) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, 0, n) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define SORT(c) sort(ALL(c)) #define RSORT(c) sort(RALL(c)) #define SZ(c) (int)((c).size()) #define EACH(i, v) for (auto i = v.begin(); i != v.end(); ++i) #define REACH(i, v) for (auto i = v.rbegin(); i != v.rend(); ++i) #define LB(c, x) distance((c).begin(), lower_bound(ALL(c), x)) #define UB(c, x) distance((c).begin(), upper_bound(ALL(c), x)) #define COUNT(c, x) (upper_bound(ALL(c), x) - lower_bound(ALL(c), x)) #define UNIQUE(c) \ SORT(c); \ (c).erase(unique(ALL(c)), (c).end()); #define COPY(c1, c2) copy(ALL(c1), (c2).begin()) #define EXIST(s, e) (bool)((s).find(e) != (s).end()) #define PB push_back #define MP make_pair #define DUMP(x) cerr << #x << " = " << (x) << endl; #define NL cerr << endl; using namespace std; template <typename T, typename U> using P = pair<T, U>; template <typename T> using V = vector<T>; template <typename T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <typename T> T sum(vector<T> &v) { return accumulate(ALL(v), T()); } template <typename T> T sum(vector<T> &v, int a, int b) { return accumulate(v.begin() + a, v.begin() + b, T()); } template <typename T> T max(vector<T> &v) { return *max_element(ALL(v)); } template <typename T> T min(vector<T> &v) { return *min_element(ALL(v)); } template <typename T> T max_index(vector<T> &v) { return distance((v).begin(), max_element(ALL(v))); } template <typename T> T min_index(vector<T> &v) { return distance((v).begin(), min_element(ALL(v))); } struct edge { int to, cost; }; template <typename T> auto &operator<<(ostream &s, const vector<T> &v) { s << "["; bool a = 1; for (auto e : v) { s << (a ? "" : " ") << e; a = 0; } s << "]"; return s; } template <typename T, typename U> auto &operator<<(ostream &s, const pair<T, U> &p) { s << "(" << p.first << "," << p.second << ")"; return s; } template <typename T> auto &operator<<(ostream &s, const set<T> &st) { s << "{"; bool a = 1; for (auto e : st) { s << (a ? "" : " ") << e; a = 0; } s << "}"; return s; } template <typename T, typename U> auto &operator<<(ostream &s, const map<T, U> &m) { s << "{"; bool a = 1; for (auto e : m) { s << (a ? "" : " ") << e.first << ":" << e.second; a = 0; } s << "}"; return s; } const int INF = 1e18; const int MOD_N = 1e9 + 7; int GF_MOD = MOD_N; struct GF { int mod, x; GF() : mod(GF_MOD), x(0) {} GF(int a) : mod(GF_MOD) { x = ((a % mod) + mod) % mod; } GF &operator=(const GF &a) { x = a.x; return *this; } GF &operator=(int a) { return *this = GF(a); } GF operator-() const { return GF((-x + mod) % mod); } GF power(int n) const { GF tmp = x, res = 1; while (n > 0) { if ((n & 1) == 1) res *= tmp; tmp *= tmp; n >>= 1; } return res; } GF inverse() const { return power(mod - 2); } GF &operator+=(const GF &a) { (x += a.x) %= mod; return *this; } GF &operator-=(const GF &a) { return *this += -a; } GF &operator*=(const GF &a) { (x *= a.x) %= mod; return *this; } GF &operator/=(const GF &a) { return *this *= a.inverse(); } const GF operator+(const GF &a) const { return GF(x) += a; } const GF operator-(const GF &a) const { return GF(x) -= a; } const GF operator*(const GF &a) const { return GF(x) *= a; } const GF operator/(const GF &a) const { return GF(x) /= a; } GF &operator+=(int a) { return *this += GF(a); } GF &operator-=(int a) { return *this -= GF(a); } GF &operator*=(int a) { return *this *= GF(a); } GF &operator/=(int a) { return *this /= GF(a); } const GF operator+(int a) const { return GF(x) += a; } const GF operator-(int a) const { return GF(x) -= a; } const GF operator*(int a) const { return GF(x) *= a; } const GF operator/(int a) const { return GF(x) /= a; } }; auto &operator<<(ostream &s, const GF &a) { s << a.x; return s; } signed main() { int H, W, K; cin >> H >> W >> K; V<GF> fibo(W); fibo[0] = 1; fibo[1] = 1; FOR(i, 2, W) { fibo[i] = fibo[i - 1] + fibo[i - 2]; } V<V<GF>> dp(H + 1, V<GF>(W)); dp[0][0] = 1; REP(h, H) { REP(w, W) { dp[h + 1][w] += dp[h][w] * fibo[w] * fibo[W - 1 - w]; if (w != 0) dp[h + 1][w - 1] += dp[h][w] * fibo[w - 1] * fibo[W - 1 - w]; if (w != W - 1) dp[h + 1][w + 1] += dp[h][w] * fibo[w] * fibo[W - 2 - w]; } } cout << dp[H][K - 1] << endl; return 0; }
#include <bits/stdc++.h> #define int long long int #define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define FORE(i, a, b) for (int i = (a); i <= (b); ++i) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i) #define RFORE(i, a, b) for (int i = (b); i >= (a); --i) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, 0, n) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define SORT(c) sort(ALL(c)) #define RSORT(c) sort(RALL(c)) #define SZ(c) (int)((c).size()) #define EACH(i, v) for (auto i = v.begin(); i != v.end(); ++i) #define REACH(i, v) for (auto i = v.rbegin(); i != v.rend(); ++i) #define LB(c, x) distance((c).begin(), lower_bound(ALL(c), x)) #define UB(c, x) distance((c).begin(), upper_bound(ALL(c), x)) #define COUNT(c, x) (upper_bound(ALL(c), x) - lower_bound(ALL(c), x)) #define UNIQUE(c) \ SORT(c); \ (c).erase(unique(ALL(c)), (c).end()); #define COPY(c1, c2) copy(ALL(c1), (c2).begin()) #define EXIST(s, e) (bool)((s).find(e) != (s).end()) #define PB push_back #define MP make_pair #define DUMP(x) cerr << #x << " = " << (x) << endl; #define NL cerr << endl; using namespace std; template <typename T, typename U> using P = pair<T, U>; template <typename T> using V = vector<T>; template <typename T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <typename T> T sum(vector<T> &v) { return accumulate(ALL(v), T()); } template <typename T> T sum(vector<T> &v, int a, int b) { return accumulate(v.begin() + a, v.begin() + b, T()); } template <typename T> T max(vector<T> &v) { return *max_element(ALL(v)); } template <typename T> T min(vector<T> &v) { return *min_element(ALL(v)); } template <typename T> T max_index(vector<T> &v) { return distance((v).begin(), max_element(ALL(v))); } template <typename T> T min_index(vector<T> &v) { return distance((v).begin(), min_element(ALL(v))); } struct edge { int to, cost; }; template <typename T> auto &operator<<(ostream &s, const vector<T> &v) { s << "["; bool a = 1; for (auto e : v) { s << (a ? "" : " ") << e; a = 0; } s << "]"; return s; } template <typename T, typename U> auto &operator<<(ostream &s, const pair<T, U> &p) { s << "(" << p.first << "," << p.second << ")"; return s; } template <typename T> auto &operator<<(ostream &s, const set<T> &st) { s << "{"; bool a = 1; for (auto e : st) { s << (a ? "" : " ") << e; a = 0; } s << "}"; return s; } template <typename T, typename U> auto &operator<<(ostream &s, const map<T, U> &m) { s << "{"; bool a = 1; for (auto e : m) { s << (a ? "" : " ") << e.first << ":" << e.second; a = 0; } s << "}"; return s; } const int INF = 1e18; const int MOD_N = 1e9 + 7; int GF_MOD = MOD_N; struct GF { int mod, x; GF() : mod(GF_MOD), x(0) {} GF(int a) : mod(GF_MOD) { x = ((a % mod) + mod) % mod; } GF &operator=(const GF &a) { x = a.x; return *this; } GF &operator=(int a) { return *this = GF(a); } GF operator-() const { return GF((-x + mod) % mod); } GF power(int n) const { GF tmp = x, res = 1; while (n > 0) { if ((n & 1) == 1) res *= tmp; tmp *= tmp; n >>= 1; } return res; } GF inverse() const { return power(mod - 2); } GF &operator+=(const GF &a) { (x += a.x) %= mod; return *this; } GF &operator-=(const GF &a) { return *this += -a; } GF &operator*=(const GF &a) { (x *= a.x) %= mod; return *this; } GF &operator/=(const GF &a) { return *this *= a.inverse(); } const GF operator+(const GF &a) const { return GF(x) += a; } const GF operator-(const GF &a) const { return GF(x) -= a; } const GF operator*(const GF &a) const { return GF(x) *= a; } const GF operator/(const GF &a) const { return GF(x) /= a; } GF &operator+=(int a) { return *this += GF(a); } GF &operator-=(int a) { return *this -= GF(a); } GF &operator*=(int a) { return *this *= GF(a); } GF &operator/=(int a) { return *this /= GF(a); } const GF operator+(int a) const { return GF(x) += a; } const GF operator-(int a) const { return GF(x) -= a; } const GF operator*(int a) const { return GF(x) *= a; } const GF operator/(int a) const { return GF(x) /= a; } }; auto &operator<<(ostream &s, const GF &a) { s << a.x; return s; } signed main() { int H, W, K; cin >> H >> W >> K; V<GF> fibo(W); FOR(i, 0, W) { if (i == 0 || i == 1) fibo[i] = 1; else fibo[i] = fibo[i - 1] + fibo[i - 2]; } V<V<GF>> dp(H + 1, V<GF>(W)); dp[0][0] = 1; REP(h, H) { REP(w, W) { dp[h + 1][w] += dp[h][w] * fibo[w] * fibo[W - 1 - w]; if (w != 0) dp[h + 1][w - 1] += dp[h][w] * fibo[w - 1] * fibo[W - 1 - w]; if (w != W - 1) dp[h + 1][w + 1] += dp[h][w] * fibo[w] * fibo[W - 2 - w]; } } cout << dp[H][K - 1] << endl; return 0; }
replace
157
160
157
163
0
p03222
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (int i = a; i < b; i++) #define ALL(v) v.begin(), v.end() #define pb push_back #define eb emplace_back #define mp make_pair typedef long long ll; typedef pair<int, int> pii; typedef pair<int, ll> pil; typedef pair<ll, int> pli; typedef pair<ll, ll> pll; const int INF = 1e9; const ll LLINF = 1e18; const ll MOD = 1e9 + 7; const double EPS = 1e-10; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <int MOD> struct modint { long long val; constexpr modint(long long v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr int getmod() { return MOD; } constexpr modint operator-() const noexcept { return val ? MOD - val : 0; } constexpr modint operator+(const modint &r) const noexcept { return modint(*this) += r; } constexpr modint operator-(const modint &r) const noexcept { return modint(*this) -= r; } constexpr modint operator*(const modint &r) const noexcept { return modint(*this) *= r; } constexpr modint operator/(const modint &r) const noexcept { return modint(*this) /= r; } constexpr modint &operator+=(const modint &r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr modint &operator-=(const modint &r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr modint &operator*=(const modint &r) noexcept { val = val * r.val % MOD; return *this; } constexpr modint &operator/=(const modint &r) noexcept { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator==(const modint &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const modint &r) const noexcept { return this->val != r.val; } friend constexpr ostream &operator<<(ostream &os, const modint<MOD> &x) noexcept { return os << x.val; } friend constexpr modint<MOD> modpow(const modint<MOD> &a, long long n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; using mint = modint<MOD>; mint dp[10][10]; int main() { int h, w, k; cin >> h >> w >> k; rep(i, 10) rep(j, 10) dp[i][j] = 0; dp[0][0] = 1; rep(i, h) rep(j, w) { rep(k, 1 << (w - 1)) { bool ok = true; rep(l, w - 2) { if ((k & (1 << l)) && (k & (1 << (l + 1)))) ok = false; } if (ok) { if (j > 0 && (k & 1 << (j - 1))) dp[i + 1][j] += dp[i][j - 1]; else if (j < w - 1 && (k & 1 << j)) dp[i + 1][j] += dp[i][j + 1]; else dp[i + 1][j] += dp[i][j]; } } } // rep(i, h+1) { // rep(j, w) printf("%9d ", dp[i][j]); // cout << endl; // } cout << dp[h][k - 1] << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) #define FOR(i, a, b) for (int i = a; i < b; i++) #define ALL(v) v.begin(), v.end() #define pb push_back #define eb emplace_back #define mp make_pair typedef long long ll; typedef pair<int, int> pii; typedef pair<int, ll> pil; typedef pair<ll, int> pli; typedef pair<ll, ll> pll; const int INF = 1e9; const ll LLINF = 1e18; const ll MOD = 1e9 + 7; const double EPS = 1e-10; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } template <int MOD> struct modint { long long val; constexpr modint(long long v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr int getmod() { return MOD; } constexpr modint operator-() const noexcept { return val ? MOD - val : 0; } constexpr modint operator+(const modint &r) const noexcept { return modint(*this) += r; } constexpr modint operator-(const modint &r) const noexcept { return modint(*this) -= r; } constexpr modint operator*(const modint &r) const noexcept { return modint(*this) *= r; } constexpr modint operator/(const modint &r) const noexcept { return modint(*this) /= r; } constexpr modint &operator+=(const modint &r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr modint &operator-=(const modint &r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr modint &operator*=(const modint &r) noexcept { val = val * r.val % MOD; return *this; } constexpr modint &operator/=(const modint &r) noexcept { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator==(const modint &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const modint &r) const noexcept { return this->val != r.val; } friend constexpr ostream &operator<<(ostream &os, const modint<MOD> &x) noexcept { return os << x.val; } friend constexpr modint<MOD> modpow(const modint<MOD> &a, long long n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; using mint = modint<MOD>; mint dp[110][10]; int main() { int h, w, k; cin >> h >> w >> k; rep(i, 10) rep(j, 10) dp[i][j] = 0; dp[0][0] = 1; rep(i, h) rep(j, w) { rep(k, 1 << (w - 1)) { bool ok = true; rep(l, w - 2) { if ((k & (1 << l)) && (k & (1 << (l + 1)))) ok = false; } if (ok) { if (j > 0 && (k & 1 << (j - 1))) dp[i + 1][j] += dp[i][j - 1]; else if (j < w - 1 && (k & 1 << j)) dp[i + 1][j] += dp[i][j + 1]; else dp[i + 1][j] += dp[i][j]; } } } // rep(i, h+1) { // rep(j, w) printf("%9d ", dp[i][j]); // cout << endl; // } cout << dp[h][k - 1] << endl; }
replace
106
107
106
107
0
p03222
C++
Runtime Error
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <algorithm> #include <array> #include <bitset> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> using namespace std; #define INF 0x3f3f3f3f #define INFLL 0x3f3f3f3f3f3f3f3fLL #define MOD 1000000007 #define mp make_pair #define mt make_tuple #define pb push_back #define eb emplace_back typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pint; typedef pair<ll, ll> pll; typedef tuple<int, int, int> tint; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<ull> vull; typedef vector<pint> vpint; int dx[8] = {0, 0, -1, 1, 1, 1, -1, -1}; int dy[8] = {-1, 1, 0, 0, 1, -1, 1, -1}; const int SIZE = 100; // ここまでテンプレ int main() { ll H, W, K; cin >> H >> W >> K; // DP[i][j]=i本目の縦棒時点でjにたどりつくあみだくじの数 ll DP[SIZE][SIZE] = {}; DP[0][0] = 1; int X = W - 1; for (int i = 1; i <= H; i++) { for (int state = 0; state < (1 << X); state++) { // stateがvalidかどうか判定する bool valid = true; for (int j = 0; j < X; j++) if ((state & (1 << j)) && (state & (1 << (j + 1)))) valid = false; if (!valid) continue; // cout<<bitset<10>(state)<<endl; // DPテーブルを更新する for (int j = 0; j < W; j++) { // 左に行く if (j != 0 && (state & (1 << (j - 1)))) { DP[i][j - 1] += DP[i - 1][j]; DP[i][j - 1] %= MOD; } // 右に行く else if (j != W - 1 && (state & (1 << j))) { DP[i][j + 1] += DP[i - 1][j]; DP[i][j + 1] %= MOD; } // そのまま else { DP[i][j] += DP[i - 1][j]; DP[i][j] %= MOD; } } } } cout << DP[H][K - 1] << endl; /* for(int i=0;i<=H;i++){ for(int j=0;j<W;j++){ cout<<DP[i][j]<<" "; } cout<<endl; } */ return 0; }
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <algorithm> #include <array> #include <bitset> #include <cctype> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <utility> #include <vector> using namespace std; #define INF 0x3f3f3f3f #define INFLL 0x3f3f3f3f3f3f3f3fLL #define MOD 1000000007 #define mp make_pair #define mt make_tuple #define pb push_back #define eb emplace_back typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> pint; typedef pair<ll, ll> pll; typedef tuple<int, int, int> tint; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<ull> vull; typedef vector<pint> vpint; int dx[8] = {0, 0, -1, 1, 1, 1, -1, -1}; int dy[8] = {-1, 1, 0, 0, 1, -1, 1, -1}; const int SIZE = 150; // ここまでテンプレ int main() { ll H, W, K; cin >> H >> W >> K; // DP[i][j]=i本目の縦棒時点でjにたどりつくあみだくじの数 ll DP[SIZE][SIZE] = {}; DP[0][0] = 1; int X = W - 1; for (int i = 1; i <= H; i++) { for (int state = 0; state < (1 << X); state++) { // stateがvalidかどうか判定する bool valid = true; for (int j = 0; j < X; j++) if ((state & (1 << j)) && (state & (1 << (j + 1)))) valid = false; if (!valid) continue; // cout<<bitset<10>(state)<<endl; // DPテーブルを更新する for (int j = 0; j < W; j++) { // 左に行く if (j != 0 && (state & (1 << (j - 1)))) { DP[i][j - 1] += DP[i - 1][j]; DP[i][j - 1] %= MOD; } // 右に行く else if (j != W - 1 && (state & (1 << j))) { DP[i][j + 1] += DP[i - 1][j]; DP[i][j + 1] %= MOD; } // そのまま else { DP[i][j] += DP[i - 1][j]; DP[i][j] %= MOD; } } } } cout << DP[H][K - 1] << endl; /* for(int i=0;i<=H;i++){ for(int j=0;j<W;j++){ cout<<DP[i][j]<<" "; } cout<<endl; } */ return 0; }
replace
43
44
43
44
0
p03222
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long int mod = 1e9 + 7; int h, w, k; vector<int> r; int dp[100][8]; int nextPos(int cur, int row) { int l, r; l = cur > 0 ? (row >> cur - 1) % 2 : 0; r = (row >> cur) % 2; if (cur > 0 && l) return cur - 1; else if (cur < w - 1 && r) return cur + 1; else return cur; } signed main() { cin >> h >> w >> k; // cout<<nextPos(0,2)<<endl; // cout<<nextPos(1,2)<<endl; if (w > 1) { for (int x = 0; x < (1 << w - 1) - 1; x++) if ((x & x >> 1 & (1 << w - 2) - 1) == 0) r.push_back(x); } else { r.push_back(0); } // for(auto&& x:r)cout<<x<<" "; // cout<<endl; // cout<<r.size()<<endl; // static int dp[h][w]; // fill(dp,dp+w,0); dp[0][0] = 1; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { for (auto &&x : r) { // int y; // y=nextPos(j,x); dp[i + 1][nextPos(j, x)] += (dp[i][j] % mod); } } } // for(int i=0;i<=h;i++){ // for(int j=0;j<w;j++){ // cout <<dp[i][j]<<" "; // } // cout <<endl; // } cout << dp[h][k - 1] % mod << endl; }
#include <bits/stdc++.h> using namespace std; #define int long long int mod = 1e9 + 7; int h, w, k; vector<int> r; int dp[101][8]; int nextPos(int cur, int row) { int l, r; l = cur > 0 ? (row >> cur - 1) % 2 : 0; r = (row >> cur) % 2; if (cur > 0 && l) return cur - 1; else if (cur < w - 1 && r) return cur + 1; else return cur; } signed main() { cin >> h >> w >> k; // cout<<nextPos(0,2)<<endl; // cout<<nextPos(1,2)<<endl; if (w > 1) { for (int x = 0; x < (1 << w - 1) - 1; x++) if ((x & x >> 1 & (1 << w - 2) - 1) == 0) r.push_back(x); } else { r.push_back(0); } // for(auto&& x:r)cout<<x<<" "; // cout<<endl; // cout<<r.size()<<endl; // static int dp[h][w]; // fill(dp,dp+w,0); dp[0][0] = 1; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { for (auto &&x : r) { // int y; // y=nextPos(j,x); dp[i + 1][nextPos(j, x)] += (dp[i][j] % mod); } } } // for(int i=0;i<=h;i++){ // for(int j=0;j<w;j++){ // cout <<dp[i][j]<<" "; // } // cout <<endl; // } cout << dp[h][k - 1] % mod << endl; }
replace
6
7
6
7
0
p03222
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <map> #include <queue> #include <random> #include <vector> using namespace std; int main() { long long MOD = 1000000007; long long H, W, K; long long num[100][10]; long long hor_f[10]; scanf("%lld %lld %lld", &H, &W, &K); hor_f[0] = 1; hor_f[1] = 1; for (int i = 2; i < 10; i++) { hor_f[i] = hor_f[i - 1] + hor_f[i - 2]; } num[0][1] = 1; for (int i = 2; i < W + 1; i++) { num[0][i] = 0; } for (int h = 1; h <= H; h++) { num[h][1] = (hor_f[W - 1] * num[h - 1][1] + hor_f[W - 2] * num[h - 1][2]) % MOD; num[h][W] = (hor_f[W - 2] * num[h - 1][W - 1] + hor_f[W - 1] * num[h - 1][W]) % MOD; for (int a = 2; a < W; a++) { num[h][a] = (hor_f[a - 2] * hor_f[W - a] * num[h - 1][a - 1] + hor_f[a - 1] * hor_f[W - a] * num[h - 1][a] + hor_f[a - 1] * hor_f[W - a - 1] * num[h - 1][a + 1]) % MOD; } } printf("%lld\n", num[H][K]); }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <functional> #include <map> #include <queue> #include <random> #include <vector> using namespace std; int main() { long long MOD = 1000000007; long long H, W, K; long long num[101][10]; long long hor_f[10]; scanf("%lld %lld %lld", &H, &W, &K); hor_f[0] = 1; hor_f[1] = 1; for (int i = 2; i < 10; i++) { hor_f[i] = hor_f[i - 1] + hor_f[i - 2]; } num[0][1] = 1; for (int i = 2; i < W + 1; i++) { num[0][i] = 0; } for (int h = 1; h <= H; h++) { num[h][1] = (hor_f[W - 1] * num[h - 1][1] + hor_f[W - 2] * num[h - 1][2]) % MOD; num[h][W] = (hor_f[W - 2] * num[h - 1][W - 1] + hor_f[W - 1] * num[h - 1][W]) % MOD; for (int a = 2; a < W; a++) { num[h][a] = (hor_f[a - 2] * hor_f[W - a] * num[h - 1][a - 1] + hor_f[a - 1] * hor_f[W - a] * num[h - 1][a] + hor_f[a - 1] * hor_f[W - a - 1] * num[h - 1][a + 1]) % MOD; } } printf("%lld\n", num[H][K]); }
replace
14
15
14
15
0
p03222
C++
Runtime Error
// #include "stdafx.h" #include <algorithm> #include <assert.h> #include <climits> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <vector> using namespace std; /*-----------------------------------------------------------------------------  定義 -------------------------------------------------------------------------------*/ #define REP(i, n) for (int(i) = 0; (i) < (int)(n); ++(i)) #define REPN(i, m, n) for (int(i) = m; (i) < (int)(n); ++(i)) #define INF 2e9 #define MOD (1000 * 1000 * 1000 + 7) #define Ceil(x, n) (((((x)) + ((n)-1)) / n)) /* Nの倍数に切り上げ割り算 */ #define CeilN(x, n) (((((x)) + ((n)-1)) / n) * n) /* Nの倍数に切り上げ */ #define FloorN(x, n) ((x) - (x) % (n)) /* Nの倍数に切り下げ */ #define IsOdd(x) (((x)&0x01UL) == 0x01UL) #define IsEven(x) (!IsOdd((x))) #define BitSetV(Val, Bit) ((Val) |= (Bit)) #define BitTstV(Val, Bit) ((Val) & (Bit)) #define ArrayLength(x) (sizeof(x) / sizeof(x[0])) #define MAX_QWORD ((QWORD)0xFFFFFFFFFFFFFFFF) #define M_PI 3.14159265358979323846 typedef long long ll; typedef unsigned long long int QWORD; typedef pair<ll, ll> P; /*-----------------------------------------------------------------------------  処理 -------------------------------------------------------------------------------*/ ll dfs(bool prevLineExist, int i, int num) { if ((num <= 0) || (num < i)) { return 1; } if (i == num) { return 1; } ll cnt = 0; int next = i + 1; if (prevLineExist) { // 引けない cnt = dfs(false, next, num); } else { // 引く or 引かない cnt = dfs(true, next, num); cnt += dfs(false, next, num); } cnt %= MOD; return cnt; } int main() { int H, W, K; cin >> H >> W >> K; // vector<vector<ll>> dp(H + 1, vector<ll>(W, 0)); static ll dp[20][20]; dp[0][0] = 1; REP(i, H) { REP(j, W) { if (0 < dp[i][j]) { ll sum; ll ptnCnt; ll ptnNoneL = dfs(false, 0, j - 1); ll ptnExistL = dfs(false, 0, j - 2); ll ptnNoneR = dfs(false, j + 1, W - 1); ll ptnExistR = dfs(false, j + 2, W - 1); // ひだり if (j != 0) { ptnCnt = (ptnExistL * ptnNoneR) % MOD; sum = (dp[i][j] * ptnCnt) % MOD; dp[i + 1][j - 1] += sum; dp[i + 1][j - 1] %= MOD; } // まんなか ptnCnt = (ptnNoneL * ptnNoneR) % MOD; sum = (dp[i][j] * ptnCnt) % MOD; dp[i + 1][j] += sum; dp[i + 1][j] %= MOD; // みぎ if (j != W - 1) { ptnCnt = (ptnNoneL * ptnExistR) % MOD; sum = (dp[i][j] * ptnCnt) % MOD; dp[i + 1][j + 1] += sum; dp[i + 1][j + 1] %= MOD; } } } } cout << dp[H][K - 1] << endl; return 0; }
// #include "stdafx.h" #include <algorithm> #include <assert.h> #include <climits> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <vector> using namespace std; /*-----------------------------------------------------------------------------  定義 -------------------------------------------------------------------------------*/ #define REP(i, n) for (int(i) = 0; (i) < (int)(n); ++(i)) #define REPN(i, m, n) for (int(i) = m; (i) < (int)(n); ++(i)) #define INF 2e9 #define MOD (1000 * 1000 * 1000 + 7) #define Ceil(x, n) (((((x)) + ((n)-1)) / n)) /* Nの倍数に切り上げ割り算 */ #define CeilN(x, n) (((((x)) + ((n)-1)) / n) * n) /* Nの倍数に切り上げ */ #define FloorN(x, n) ((x) - (x) % (n)) /* Nの倍数に切り下げ */ #define IsOdd(x) (((x)&0x01UL) == 0x01UL) #define IsEven(x) (!IsOdd((x))) #define BitSetV(Val, Bit) ((Val) |= (Bit)) #define BitTstV(Val, Bit) ((Val) & (Bit)) #define ArrayLength(x) (sizeof(x) / sizeof(x[0])) #define MAX_QWORD ((QWORD)0xFFFFFFFFFFFFFFFF) #define M_PI 3.14159265358979323846 typedef long long ll; typedef unsigned long long int QWORD; typedef pair<ll, ll> P; /*-----------------------------------------------------------------------------  処理 -------------------------------------------------------------------------------*/ ll dfs(bool prevLineExist, int i, int num) { if ((num <= 0) || (num < i)) { return 1; } if (i == num) { return 1; } ll cnt = 0; int next = i + 1; if (prevLineExist) { // 引けない cnt = dfs(false, next, num); } else { // 引く or 引かない cnt = dfs(true, next, num); cnt += dfs(false, next, num); } cnt %= MOD; return cnt; } int main() { int H, W, K; cin >> H >> W >> K; vector<vector<ll>> dp(H + 1, vector<ll>(W, 0)); // static ll dp[20][20]; dp[0][0] = 1; REP(i, H) { REP(j, W) { if (0 < dp[i][j]) { ll sum; ll ptnCnt; ll ptnNoneL = dfs(false, 0, j - 1); ll ptnExistL = dfs(false, 0, j - 2); ll ptnNoneR = dfs(false, j + 1, W - 1); ll ptnExistR = dfs(false, j + 2, W - 1); // ひだり if (j != 0) { ptnCnt = (ptnExistL * ptnNoneR) % MOD; sum = (dp[i][j] * ptnCnt) % MOD; dp[i + 1][j - 1] += sum; dp[i + 1][j - 1] %= MOD; } // まんなか ptnCnt = (ptnNoneL * ptnNoneR) % MOD; sum = (dp[i][j] * ptnCnt) % MOD; dp[i + 1][j] += sum; dp[i + 1][j] %= MOD; // みぎ if (j != W - 1) { ptnCnt = (ptnNoneL * ptnExistR) % MOD; sum = (dp[i][j] * ptnCnt) % MOD; dp[i + 1][j + 1] += sum; dp[i + 1][j + 1] %= MOD; } } } } cout << dp[H][K - 1] << endl; return 0; }
replace
75
77
75
77
0
p03222
Python
Runtime Error
def count(length, on): """Count of possible amida patterns""" if length < 0: return 1 if length == 0: return 1 ret = count(length - 1, False) if not on: ret += count(length - 1, True) return ret # for i in range(1, 9): # print(count(i, True) + count(i, False)) if __name__ == "__main__": H, W, K = map(int, input().split()) # Count B = [0 for _ in range(W)] B[0] = 1 for j in range(H): C = [0 for _ in range(W)] for i in range(W): left_off = count(i - 1, False) left_on = count(i - 1, True) right_off = count(W - i - 2, False) right_on = count(W - i - 2, True) # print(i, left_off, left_on, right_off, right_on) if B[i] > 0: C[i] += B[i] * (left_off * right_off) if i > 0 and B[i - 1] > 0: C[i] += B[i - 1] * (left_on * right_off) if i < W - 1 and B[i + 1] > 0: C[i] += B[i + 1] * (left_off * right_on) B = [ci for ci in C] # print(B) MOD = 1_000_000_007 ANS = C[K - 1] % MOD print(ANS)
def count(length, on): """Count of possible amida patterns""" if length < 0: return 1 if length == 0: return 1 ret = count(length - 1, False) if not on: ret += count(length - 1, True) return ret # for i in range(1, 9): # print(count(i, True) + count(i, False)) if __name__ == "__main__": H, W, K = map(int, input().split()) # Count B = [0 for _ in range(W)] B[0] = 1 for j in range(H): C = [0 for _ in range(W)] for i in range(W): left_off = count(i - 1, False) left_on = count(i - 1, True) right_off = count(W - i - 2, False) right_on = count(W - i - 2, True) # print(i, left_off, left_on, right_off, right_on) if B[i] > 0: C[i] += B[i] * (left_off * right_off) if i > 0 and B[i - 1] > 0: C[i] += B[i - 1] * (left_on * right_off) if i < W - 1 and B[i + 1] > 0: C[i] += B[i + 1] * (left_off * right_on) B = [ci for ci in C] # print(B) # MOD = 1_000_000_007 # Underscore is not supported until 3.6 MOD = 1000000007 ANS = C[K - 1] % MOD print(ANS)
replace
43
44
43
45
0
p03222
C++
Runtime Error
#include <iostream> #include <map> #include <tuple> #include <vector> using ull = unsigned long long; static ull const Mod = 1000000007; std::vector<ull> Fib; std::map<std::tuple<int, int, int>, int> Memo; ull Amida1(int W, int J, int K) { if (J < 1 || K < 1 || J > W || K > W || std::abs(J - K) > 1) { return 0; } auto s = std::min(J, K); auto l = std::max(J, K); return (Fib[s - 1] * Fib[W - l]) % Mod; } ull Amida(int H, int W, int K) { if (K < 1 || K > W || std::abs(K - 1) > H) { return 0; } auto key = std::make_tuple(H, W, K); if (Memo.count(key) > 0) return Memo.at(key); if (H == 1) { auto ans = Amida1(W, 1, K); Memo.insert(std::make_pair(key, ans)); return ans; } ull ans; ans = Amida(H - 1, W, K - 1) * Amida1(W, K - 1, K); ans %= Mod; ans += Amida(H - 1, W, K) * Amida1(W, K, K); ans %= Mod; ans += Amida(H - 1, W, K + 1) * Amida1(W, K + 1, K); ans %= Mod; Memo.insert(std::make_pair(key, ans)); return ans; } int main() { int H, W, K; std::cin >> H >> W >> K; Fib.resize(W); Fib[0] = 1; Fib[1] = 1; for (size_t i = 2; i < W + 1; i++) Fib[i] = Fib[i - 2] + Fib[i - 1]; std::cout << Amida(H, W, K) << std::endl; return 0; }
#include <iostream> #include <map> #include <tuple> #include <vector> using ull = unsigned long long; static ull const Mod = 1000000007; std::vector<ull> Fib; std::map<std::tuple<int, int, int>, int> Memo; ull Amida1(int W, int J, int K) { if (J < 1 || K < 1 || J > W || K > W || std::abs(J - K) > 1) { return 0; } auto s = std::min(J, K); auto l = std::max(J, K); return (Fib[s - 1] * Fib[W - l]) % Mod; } ull Amida(int H, int W, int K) { if (K < 1 || K > W || std::abs(K - 1) > H) { return 0; } auto key = std::make_tuple(H, W, K); if (Memo.count(key) > 0) return Memo.at(key); if (H == 1) { auto ans = Amida1(W, 1, K); Memo.insert(std::make_pair(key, ans)); return ans; } ull ans; ans = Amida(H - 1, W, K - 1) * Amida1(W, K - 1, K); ans %= Mod; ans += Amida(H - 1, W, K) * Amida1(W, K, K); ans %= Mod; ans += Amida(H - 1, W, K + 1) * Amida1(W, K + 1, K); ans %= Mod; Memo.insert(std::make_pair(key, ans)); return ans; } int main() { int H, W, K; std::cin >> H >> W >> K; Fib.resize(W + 1); Fib[0] = 1; Fib[1] = 1; for (size_t i = 2; i < W + 1; i++) Fib[i] = Fib[i - 2] + Fib[i - 1]; std::cout << Amida(H, W, K) << std::endl; return 0; }
replace
54
55
54
55
-6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
p03222
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vi>; using vvl = vector<vl>; const int INF = 1 << 28; const ll MOD = 1'000'000'007; template <class T> bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; } template <class T> bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; } int main() { int h, w, k; cin >> h >> w >> k; vvl dp(h + 1, vl(w, 0)); dp[0][0] = 1; vl cases(7, 0); cases[0] = 1; for (int i = 1; i <= 7; ++i) { for (int j = 0; j < 1 << i; ++j) { bool valid = true; for (int k = 0; k < i - 1; ++k) { if ((j & 1 << k) && (j & 1 << (k + 1))) { valid = false; break; } } if (valid) cases[i]++; } } for (int i = 1; i <= h; ++i) { for (int j = 0; j < w; ++j) { ll tempmid = dp[i - 1][j]; if (j > 1) tempmid = tempmid * cases[j - 1] % MOD; if (j < w - 2) tempmid = tempmid * cases[w - (j + 2)] % MOD; ll templeft = 0; ll tempright = 0; if (j > 0) { templeft = dp[i - 1][j - 1]; if (j > 2) templeft = templeft * cases[j - 2] % MOD; if (j < w - 2) templeft = templeft * cases[w - (j + 2)] % MOD; } if (j < w - 1) { tempright = dp[i - 1][j + 1]; if (j > 1) tempright = tempright * cases[j - 1] % MOD; if (j < w - 3) tempright = tempright * cases[w - (j + 3)] % MOD; } dp[i][j] = (tempmid + templeft + tempright) % MOD; } } cout << dp[h][k - 1] << endl; return 0; }
#include "bits/stdc++.h" using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vi>; using vvl = vector<vl>; const int INF = 1 << 28; const ll MOD = 1'000'000'007; template <class T> bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; } template <class T> bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; } int main() { int h, w, k; cin >> h >> w >> k; vvl dp(h + 1, vl(w, 0)); dp[0][0] = 1; vl cases(8, 0); cases[0] = 1; for (int i = 1; i <= 7; ++i) { for (int j = 0; j < 1 << i; ++j) { bool valid = true; for (int k = 0; k < i - 1; ++k) { if ((j & 1 << k) && (j & 1 << (k + 1))) { valid = false; break; } } if (valid) cases[i]++; } } for (int i = 1; i <= h; ++i) { for (int j = 0; j < w; ++j) { ll tempmid = dp[i - 1][j]; if (j > 1) tempmid = tempmid * cases[j - 1] % MOD; if (j < w - 2) tempmid = tempmid * cases[w - (j + 2)] % MOD; ll templeft = 0; ll tempright = 0; if (j > 0) { templeft = dp[i - 1][j - 1]; if (j > 2) templeft = templeft * cases[j - 2] % MOD; if (j < w - 2) templeft = templeft * cases[w - (j + 2)] % MOD; } if (j < w - 1) { tempright = dp[i - 1][j + 1]; if (j > 1) tempright = tempright * cases[j - 1] % MOD; if (j < w - 3) tempright = tempright * cases[w - (j + 3)] % MOD; } dp[i][j] = (tempmid + templeft + tempright) % MOD; } } cout << dp[h][k - 1] << endl; return 0; }
replace
23
24
23
24
0
p03222
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define pt(sth) cout << sth << "\n" #define chmax(a, b) \ { \ if (a < b) \ a = b; \ } #define chmin(a, b) \ { \ if (a > b) \ a = b; \ } #define moC(a, s, b) (a) = ((a)s(b) + MOD) % MOD using namespace std; typedef long long ll; typedef pair<ll, ll> P; static const ll INF = 1e18; static const ll MAX = 101010; static const ll MOD = 1e9 + 7; ll moP(ll x, ll n) { ll res = 1; while (n > 0) { if (n & 1) moC(res, *, x); moC(x, *, x); n >>= 1; } return res; } ll H, W, K; ll f(ll w) { ll i; ll res = 0; for (ll S = 0; S < 1 << w; S++) { vector<ll> v; for (i = 0; i < w; i++) { if (S >> i & 1) v.push_back(i); } ll f = 1; for (i = 0; i < (ll)v.size() - 1; i++) { if (v[i] + 1 == v[i + 1]) f = 0; } if (f) res++; } return res; } int main(void) { cin >> H >> W >> K; ll i, j, k, l; ll dp[111][11] = {}; dp[0][1] = 1; for (i = 0; i < H; i++) { for (j = 1; j <= W; j++) { // left if (j == 2 || j == W) { moC(dp[i + 1][j - 1], +, dp[i][j] * f(W - 3) % MOD); } else if (2 < j && j < W) { moC(dp[i + 1][j - 1], +, dp[i][j] * f(j - 3) % MOD * f(W - j - 1) % MOD); } // right if (j == 1 || j == W - 1) { moC(dp[i + 1][j + 1], +, dp[i][j] * f(W - 3) % MOD); } else if (1 < j && j < W - 1) { moC(dp[i + 1][j + 1], +, dp[i][j] * f(j - 2) % MOD * f(W - j - 2) % MOD); } // down if (j == 1 || j == W) { moC(dp[i + 1][j], +, dp[i][j] * f(W - 2) % MOD); } else { moC(dp[i + 1][j], +, dp[i][j] * f(j - 2) % MOD * f(W - j - 1) % MOD); } } } pt(dp[H][K]); }
#include <bits/stdc++.h> #define pt(sth) cout << sth << "\n" #define chmax(a, b) \ { \ if (a < b) \ a = b; \ } #define chmin(a, b) \ { \ if (a > b) \ a = b; \ } #define moC(a, s, b) (a) = ((a)s(b) + MOD) % MOD using namespace std; typedef long long ll; typedef pair<ll, ll> P; static const ll INF = 1e18; static const ll MAX = 101010; static const ll MOD = 1e9 + 7; ll moP(ll x, ll n) { ll res = 1; while (n > 0) { if (n & 1) moC(res, *, x); moC(x, *, x); n >>= 1; } return res; } ll H, W, K; ll f(ll w) { if (w < 0) return 1; ll i; ll res = 0; for (ll S = 0; S < 1 << w; S++) { vector<ll> v; for (i = 0; i < w; i++) { if (S >> i & 1) v.push_back(i); } ll f = 1; for (i = 0; i < (ll)v.size() - 1; i++) { if (v[i] + 1 == v[i + 1]) f = 0; } if (f) res++; } return res; } int main(void) { cin >> H >> W >> K; ll i, j, k, l; ll dp[111][11] = {}; dp[0][1] = 1; for (i = 0; i < H; i++) { for (j = 1; j <= W; j++) { // left if (j == 2 || j == W) { moC(dp[i + 1][j - 1], +, dp[i][j] * f(W - 3) % MOD); } else if (2 < j && j < W) { moC(dp[i + 1][j - 1], +, dp[i][j] * f(j - 3) % MOD * f(W - j - 1) % MOD); } // right if (j == 1 || j == W - 1) { moC(dp[i + 1][j + 1], +, dp[i][j] * f(W - 3) % MOD); } else if (1 < j && j < W - 1) { moC(dp[i + 1][j + 1], +, dp[i][j] * f(j - 2) % MOD * f(W - j - 2) % MOD); } // down if (j == 1 || j == W) { moC(dp[i + 1][j], +, dp[i][j] * f(W - 2) % MOD); } else { moC(dp[i + 1][j], +, dp[i][j] * f(j - 2) % MOD * f(W - j - 1) % MOD); } } } pt(dp[H][K]); }
insert
34
34
34
36
TLE
p03223
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> using namespace std; #define Maxn 100005 #define LL long long #define R register int n, a[Maxn]; LL ans; int main() { scanf("%d", &n); for (R int i = 1; i <= n; ++i) scanf("%d", &a[i]), a[n + i] = a[i]; sort(a + 1, a + n * 2 + 1); // for (R int i=1;i<=2*n;++i)printf("%d ",a[i]);puts(""); if (n == 2) { printf("%d\n", abs(a[3] - a[2])); return 0; } if (n & 1) { for (R int i = 2 * n; i >= n + 4; --i) ans += a[i]; for (R int i = 1; i <= n - 3; ++i) ans -= a[i]; ans += a[n + 3] - a[n - 2]; ans = max(ans + a[n + 2] - a[n + 1], ans + a[n] - a[n - 1]); } else { for (R int i = 2 * n; i >= n + 3; --i) ans += a[i]; for (R int i = 1; i <= n - 2; ++i) ans -= a[i]; ans += a[n + 2] - a[n - 1]; } printf("%lld\n", ans); return 0; }
#include <algorithm> #include <cstdio> #include <cstring> using namespace std; #define Maxn 200005 #define LL long long #define R register int n, a[Maxn]; LL ans; int main() { scanf("%d", &n); for (R int i = 1; i <= n; ++i) scanf("%d", &a[i]), a[n + i] = a[i]; sort(a + 1, a + n * 2 + 1); // for (R int i=1;i<=2*n;++i)printf("%d ",a[i]);puts(""); if (n == 2) { printf("%d\n", abs(a[3] - a[2])); return 0; } if (n & 1) { for (R int i = 2 * n; i >= n + 4; --i) ans += a[i]; for (R int i = 1; i <= n - 3; ++i) ans -= a[i]; ans += a[n + 3] - a[n - 2]; ans = max(ans + a[n + 2] - a[n + 1], ans + a[n] - a[n - 1]); } else { for (R int i = 2 * n; i >= n + 3; --i) ans += a[i]; for (R int i = 1; i <= n - 2; ++i) ans -= a[i]; ans += a[n + 2] - a[n - 1]; } printf("%lld\n", ans); return 0; }
replace
6
7
6
7
0
p03223
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; const int MAX = 10000; int main() { int N; int A[MAX]; cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; } sort(A, A + N); vector<int> v1, v2; long long ans1 = 0; long long ans2 = 0; v1.push_back(-1); v1.push_back(N & 1 ? -1 : 1); v2.push_back(1); v2.push_back(N & 1 ? 1 : -1); for (int i = 0; i < N - 2; i++) { v1.push_back(i & 1 ? -2 : 2); v2.push_back(i & 1 ? 2 : -2); } sort(v1.begin(), v1.end()); sort(v2.begin(), v2.end()); for (int i = 0; i < N; i++) { ans1 += A[i] * v1[i]; ans2 += A[i] * v2[i]; } cout << max(ans1, ans2) << endl; return 0; }
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; const int MAX = 100000; int main() { int N; int A[MAX]; cin >> N; for (int i = 0; i < N; i++) { cin >> A[i]; } sort(A, A + N); vector<int> v1, v2; long long ans1 = 0; long long ans2 = 0; v1.push_back(-1); v1.push_back(N & 1 ? -1 : 1); v2.push_back(1); v2.push_back(N & 1 ? 1 : -1); for (int i = 0; i < N - 2; i++) { v1.push_back(i & 1 ? -2 : 2); v2.push_back(i & 1 ? 2 : -2); } sort(v1.begin(), v1.end()); sort(v2.begin(), v2.end()); for (int i = 0; i < N; i++) { ans1 += A[i] * v1[i]; ans2 += A[i] * v2[i]; } cout << max(ans1, ans2) << endl; return 0; }
replace
11
12
11
12
0
p03223
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; using Int = long long; vector<int> doit(const vector<int> &A) { int N = A.size(); vector<int> B(N); for (int i = 0; i < N / 2; i++) { B[N / 2 - 1 - i] = A[i]; B[N / 2 + i] = A[N - 1 - i]; if (i % 2) swap(B[N / 2 - i - i], B[N / 2 + i]); } if (N % 2 == 1) B[N - 1] = A[N / 2]; return B; } Int sumdiff(const vector<int> &A) { Int diff = 0; for (int i = 0; i < A.size() - 1; i++) { diff += abs((Int)A[i + 1] - A[i]); } return diff; } void print(const vector<int> &A) { for (int i = 0; i < A.size(); i++) cout << A[i] << ' '; cout << endl; } int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; sort(A.begin(), A.end()); vector<int> B = doit(A); Int b = sumdiff(B); sort(A.rbegin(), A.rend()); vector<int> C = doit(A); Int c = sumdiff(C); cout << max(b, c) << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <tuple> #include <utility> #include <vector> using namespace std; using Int = long long; vector<int> doit(const vector<int> &A) { int N = A.size(); vector<int> B(N); for (int i = 0; i < N / 2; i++) { B[N / 2 - 1 - i] = A[i]; B[N / 2 + i] = A[N - 1 - i]; if (i % 2) swap(B[N / 2 - 1 - i], B[N / 2 + i]); } if (N % 2 == 1) B[N - 1] = A[N / 2]; return B; } Int sumdiff(const vector<int> &A) { Int diff = 0; for (int i = 0; i < A.size() - 1; i++) { diff += abs((Int)A[i + 1] - A[i]); } return diff; } void print(const vector<int> &A) { for (int i = 0; i < A.size(); i++) cout << A[i] << ' '; cout << endl; } int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) cin >> A[i]; sort(A.begin(), A.end()); vector<int> B = doit(A); Int b = sumdiff(B); sort(A.rbegin(), A.rend()); vector<int> C = doit(A); Int c = sumdiff(C); cout << max(b, c) << endl; return 0; }
replace
16
17
16
17
0
p03223
C++
Runtime Error
#include <bits/stdc++.h> #define maxn 500005 #define int long long using namespace std; inline int read() { char x = getchar(); int lin = 0, f = 1; while (x < '0' || x > '9') { if (x == '-') f = -1; x = getchar(); } while (x >= '0' && x <= '9') { lin = (lin << 1) + (lin << 3) + x - '0'; x = getchar(); } return lin * f; } #define PII pair<int, int> #define fir first #define sec second #define ma(a, b) make_pair(a, b) #define db double multiset<int> sett; deque<int> q; int n, val[maxn], ans, jie, s[maxn], tot; void insert_big() { int val = *(--sett.end()); sett.erase(--sett.end()); if (q.size()) { if (abs(q.front() - val) <= abs(q.back() - val)) ans += abs(q.back() - val), q.push_back(val); else ans += abs(q.front() - val), q.push_front(val); } else q.push_front(val); } void insert_small() { int val = *sett.begin(); sett.erase(sett.begin()); if (q.size()) { if (abs(q.front() - val) <= abs(q.back() - val)) ans += abs(q.back() - val), q.push_back(val); else ans += abs(q.front() - val), q.push_front(val); } else q.push_front(val); } signed main() { // freopen("1.in","r",stdin); // freopen("1.out","w",stdout); n = read(); for (int i = 1; i <= n; i++) { val[i] = read(); } if (n & 1) { for (int i = 1; i <= n; i++) sett.insert(val[i]); for (int i = 1; i <= n; i++) if (!(i & 1)) insert_big(); else insert_small(); jie = ans; ans = 0; while (q.size()) q.pop_front(); for (int i = 1; i <= n; i++) sett.insert(val[i]); for (int i = 1; i <= n; i++) if (i & 1) insert_big(); else insert_small(); jie = max(ans, jie); ans = jie; cout << ans; return 0; } sort(val + 1, val + 1 + n); int v1 = val[n / 2], v2 = val[n / 2 + 1]; for (int i = 1; i <= n; i++) if (i != n / 2 && i != n / 2 + 1) s[++tot] = val[i]; n -= 2; for (int i = 1; i <= n; i++) val[i] = s[i]; for (int i = 1; i <= n; i++) sett.insert(val[i]); for (int i = 1; i <= n; i++) if (i & 1) insert_big(); else insert_small(); ans += max(abs(q.front() - v1) + abs(q.back() - v2), abs(q.front() - v2) + abs(q.back() - v1)); jie = ans; ans = 0; while (q.size()) q.pop_back(); for (int i = 1; i <= n; i++) sett.insert(val[i]); for (int i = 1; i <= n; i++) if (!(i & 1)) insert_big(); else insert_small(); ans += max(abs(q.front() - v1) + abs(q.back() - v2), abs(q.front() - v2) + abs(q.back() - v1)); ans = max(ans, jie); cout << ans; }
#include <bits/stdc++.h> #define maxn 500005 #define int long long using namespace std; inline int read() { char x = getchar(); int lin = 0, f = 1; while (x < '0' || x > '9') { if (x == '-') f = -1; x = getchar(); } while (x >= '0' && x <= '9') { lin = (lin << 1) + (lin << 3) + x - '0'; x = getchar(); } return lin * f; } #define PII pair<int, int> #define fir first #define sec second #define ma(a, b) make_pair(a, b) #define db double multiset<int> sett; deque<int> q; int n, val[maxn], ans, jie, s[maxn], tot; void insert_big() { int val = *(--sett.end()); sett.erase(--sett.end()); if (q.size()) { if (abs(q.front() - val) <= abs(q.back() - val)) ans += abs(q.back() - val), q.push_back(val); else ans += abs(q.front() - val), q.push_front(val); } else q.push_front(val); } void insert_small() { int val = *sett.begin(); sett.erase(sett.begin()); if (q.size()) { if (abs(q.front() - val) <= abs(q.back() - val)) ans += abs(q.back() - val), q.push_back(val); else ans += abs(q.front() - val), q.push_front(val); } else q.push_front(val); } signed main() { // freopen("1.in","r",stdin); // freopen("1.out","w",stdout); n = read(); for (int i = 1; i <= n; i++) { val[i] = read(); } if (n == 2) { cout << abs(val[1] - val[2]); return 0; } if (n & 1) { for (int i = 1; i <= n; i++) sett.insert(val[i]); for (int i = 1; i <= n; i++) if (!(i & 1)) insert_big(); else insert_small(); jie = ans; ans = 0; while (q.size()) q.pop_front(); for (int i = 1; i <= n; i++) sett.insert(val[i]); for (int i = 1; i <= n; i++) if (i & 1) insert_big(); else insert_small(); jie = max(ans, jie); ans = jie; cout << ans; return 0; } sort(val + 1, val + 1 + n); int v1 = val[n / 2], v2 = val[n / 2 + 1]; for (int i = 1; i <= n; i++) if (i != n / 2 && i != n / 2 + 1) s[++tot] = val[i]; n -= 2; for (int i = 1; i <= n; i++) val[i] = s[i]; for (int i = 1; i <= n; i++) sett.insert(val[i]); for (int i = 1; i <= n; i++) if (i & 1) insert_big(); else insert_small(); ans += max(abs(q.front() - v1) + abs(q.back() - v2), abs(q.front() - v2) + abs(q.back() - v1)); jie = ans; ans = 0; while (q.size()) q.pop_back(); for (int i = 1; i <= n; i++) sett.insert(val[i]); for (int i = 1; i <= n; i++) if (!(i & 1)) insert_big(); else insert_small(); ans += max(abs(q.front() - v1) + abs(q.back() - v2), abs(q.front() - v2) + abs(q.back() - v1)); ans = max(ans, jie); cout << ans; }
insert
54
54
54
58
0
p03223
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <complex> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <utility> #include <vector> #define M_PI 3.14159265358979323846 using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; typedef unsigned long long ULL; typedef vector<LL> VLL; typedef vector<VLL> VVLL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define MT make_tuple #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) #define FILL(a, x) memset(a, x, sizeof(a)) // repetition //------------------------------------------ #define FOR(i, s, n) for (int i = s; i < (int)n; ++i) #define REP(i, n) FOR(i, 0, n) int main() { int n; scanf("%d", &n); VLL a(n); REP(i, n) scanf("%lld", &a[i]); sort(ALL(a)); LL x[2] = {a[0], a[0]}; int l = 1, r = n - 1; LL ans = 0; while (l <= r) { VLL d(4); d[0] = abs(a[l] - x[0]); d[1] = abs(a[r] - x[0]); d[2] = abs(a[l] - x[1]); d[3] = abs(a[r] - x[1]); int maxidx = -1; LL maxd = 0; REP(i, 4) { if (maxd < d[i]) { maxd = d[i]; maxidx = i; } } ans += maxd; if (maxidx == 0) x[0] = a[l++]; else if (maxidx == 1) x[0] = a[r--]; else if (maxidx == 2) x[1] = a[l++]; else if (maxidx == 3) x[1] = a[r--]; } cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <complex> #include <cstdint> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <utility> #include <vector> #define M_PI 3.14159265358979323846 using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; typedef unsigned long long ULL; typedef vector<LL> VLL; typedef vector<VLL> VVLL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define MT make_tuple #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) #define FILL(a, x) memset(a, x, sizeof(a)) // repetition //------------------------------------------ #define FOR(i, s, n) for (int i = s; i < (int)n; ++i) #define REP(i, n) FOR(i, 0, n) int main() { int n; scanf("%d", &n); VLL a(n); REP(i, n) scanf("%lld", &a[i]); sort(ALL(a)); LL x[2] = {a[0], a[0]}; int l = 1, r = n - 1; LL ans = 0; while (l <= r) { VLL d(4); d[0] = abs(a[l] - x[0]); d[1] = abs(a[r] - x[0]); d[2] = abs(a[l] - x[1]); d[3] = abs(a[r] - x[1]); int maxidx = -1; LL maxd = -1; REP(i, 4) { if (maxd < d[i]) { maxd = d[i]; maxidx = i; } } ans += maxd; if (maxidx == 0) x[0] = a[l++]; else if (maxidx == 1) x[0] = a[r--]; else if (maxidx == 2) x[1] = a[l++]; else if (maxidx == 3) x[1] = a[r--]; } cout << ans << endl; return 0; }
replace
92
93
92
93
TLE
p03223
C++
Runtime Error
#include <algorithm> #include <iostream> using namespace std; int main(void) { int n, a[10000], b[10000]; long long c = 0, d = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); if (n % 2 == 0) { b[0] = a[n / 2]; for (int i = 1; i < n; i++) { if (i % 2 == 0) { b[i] = a[n / 2 + i / 2]; } else { b[i] = a[i / 2]; } c += abs(b[i] - b[i - 1]); } } else { b[0] = a[n / 2]; for (int i = 1; i < n; i++) { if (i % 2 == 0) { b[i] = a[(i - 1) / 2]; } else { b[i] = a[(n + i) / 2]; } c += abs(b[i] - b[i - 1]); } b[0] = a[n / 2]; for (int i = 1; i < n; i++) { if (i % 2 == 0) { b[i] = a[n - i / 2]; } else { b[i] = a[i / 2]; } d += abs(b[i] - b[i - 1]); } } cout << max(c, d) << endl; }
#include <algorithm> #include <iostream> using namespace std; int main(void) { int n, a[100000], b[100000]; long long c = 0, d = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); if (n % 2 == 0) { b[0] = a[n / 2]; for (int i = 1; i < n; i++) { if (i % 2 == 0) { b[i] = a[n / 2 + i / 2]; } else { b[i] = a[i / 2]; } c += abs(b[i] - b[i - 1]); } } else { b[0] = a[n / 2]; for (int i = 1; i < n; i++) { if (i % 2 == 0) { b[i] = a[(i - 1) / 2]; } else { b[i] = a[(n + i) / 2]; } c += abs(b[i] - b[i - 1]); } b[0] = a[n / 2]; for (int i = 1; i < n; i++) { if (i % 2 == 0) { b[i] = a[n - i / 2]; } else { b[i] = a[i / 2]; } d += abs(b[i] - b[i - 1]); } } cout << max(c, d) << endl; }
replace
4
5
4
5
0
p03224
C++
Runtime Error
#include "bits/stdc++.h" #define in std::cin #define out std::cout #define rep(i, N) for (int i = 0; i < N; ++i) typedef long long int LL; int main() { LL N; in >> N; if (N * 2 != (LL)sqrt(N * 2) * ((LL)sqrt(N * 2) + 1)) { out << "No" << std::endl; return 0; } LL size = sqrt(N * 2); std::vector<std::vector<LL>> field(size); LL num = 1; rep(i, size) { rep(j, i + 1) { field[i].push_back(num); ++num; } } std::vector<std::vector<LL>> ans(size + 1); rep(i, size) { ans[0].push_back(field[i][0]); ans[1].push_back(field[size - 1][i]); ans[2].push_back(field[i][i]); } rep(i, size - 2) { rep(j, i + 1) ans[i + 3].push_back(field[i + 1][j]); rep(j, size - i - 1) ans[i + 3].push_back(field[i + 1 + j][i + 1]); } out << "Yes" << std::endl << ans.size() << std::endl; rep(i, ans.size()) { out << ans[i].size() << " "; rep(j, ans[i].size()) out << ans[i][j] << (j < ans[i].size() - 1 ? " " : "\n"); } return 0; }
#include "bits/stdc++.h" #define in std::cin #define out std::cout #define rep(i, N) for (int i = 0; i < N; ++i) typedef long long int LL; int main() { LL N; in >> N; if (N * 2 != (LL)sqrt(N * 2) * ((LL)sqrt(N * 2) + 1)) { out << "No" << std::endl; return 0; } if (N == 1) { out << "Yes" << std::endl << 2 << std::endl << 1 << " " << 1 << std::endl << 1 << " " << 1 << std::endl; return 0; } LL size = sqrt(N * 2); std::vector<std::vector<LL>> field(size); LL num = 1; rep(i, size) { rep(j, i + 1) { field[i].push_back(num); ++num; } } std::vector<std::vector<LL>> ans(size + 1); rep(i, size) { ans[0].push_back(field[i][0]); ans[1].push_back(field[size - 1][i]); ans[2].push_back(field[i][i]); } rep(i, size - 2) { rep(j, i + 1) ans[i + 3].push_back(field[i + 1][j]); rep(j, size - i - 1) ans[i + 3].push_back(field[i + 1 + j][i + 1]); } out << "Yes" << std::endl << ans.size() << std::endl; rep(i, ans.size()) { out << ans[i].size() << " "; rep(j, ans[i].size()) out << ans[i][j] << (j < ans[i].size() - 1 ? " " : "\n"); } return 0; }
insert
12
12
12
19
0
p03224
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) typedef long long LL; int N; vector<int> G[401]; void answer(int x) { cout << "Yes" << endl; cout << x + 1 << endl; int now = 1; REP(i, x) { REP(j, x - i) { G[i].push_back(now); G[i + 1 + j].push_back(now); now++; } } REP(i, x + 1) { cout << x << " "; REP(j, x) { cout << G[i][j]; if (j != x - 1) { cout << " "; } else { cout << endl; } } } } int main() { cin >> N; REP(i, N + 1) { if (2 * N == i * (i + 1)) { answer(i); return 0; } } cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) typedef long long LL; int N; vector<int> G[701]; void answer(int x) { cout << "Yes" << endl; cout << x + 1 << endl; int now = 1; REP(i, x) { REP(j, x - i) { G[i].push_back(now); G[i + 1 + j].push_back(now); now++; } } REP(i, x + 1) { cout << x << " "; REP(j, x) { cout << G[i][j]; if (j != x - 1) { cout << " "; } else { cout << endl; } } } } int main() { cin >> N; REP(i, N + 1) { if (2 * N == i * (i + 1)) { answer(i); return 0; } } cout << "No" << endl; return 0; }
replace
8
9
8
9
0
p03224
C++
Runtime Error
//----------------------------おまじない #pragma GCC optimize("O3") #pragma GCC target("tune=native") #pragma GCC target("avx") //---------------------------- #define FOR(i, j, n) for (int i = (j); i < (n); i++) #define REP(i, n) for (int i = 0; i < (n); i++) #define REPN(i, n) for (int i = (n); i > 0; i--) #define I(n) scanf("%d", &(n)) #define LL(n) scanf("%lld", &(n)) #define pb(n) push_back((n)) #define mp(i, j) make_pair((i), (j)) #define eb(i, j) emplace_back((i), (j)) #include <bits/stdc++.h> using namespace std; //------------------------------typedef集 typedef vector<int> vi; typedef pair<int, int> pi; typedef vector<pi> vpi; typedef vector<vi> vvi; typedef vector<vpi> vvpi; typedef vector<vvi> vvvi; typedef long long ll; const int mod = 1000000009; int n; vvi ans; int main() { cin >> n; int k = sqrt((double)n * 2); if (n == 1) { cout << "Yes" << endl; cout << 2 << endl; cout << "1 1" << endl; cout << "1 1" << endl; } else if (k * (k + 1) == 2 * n) { cout << "Yes" << endl; cout << k + 1 << endl; ans.resize(k + 1); int elm = 1; REP(i, n) { int st = ans[i].size(); FOR(j, st + 1, k + 1) { ans[i].pb(elm); ans[j].pb(elm); elm++; } cout << k << " "; for (auto v : ans[i]) cout << v << " "; cout << endl; } } else { cout << "No" << endl; } }
//----------------------------おまじない #pragma GCC optimize("O3") #pragma GCC target("tune=native") #pragma GCC target("avx") //---------------------------- #define FOR(i, j, n) for (int i = (j); i < (n); i++) #define REP(i, n) for (int i = 0; i < (n); i++) #define REPN(i, n) for (int i = (n); i > 0; i--) #define I(n) scanf("%d", &(n)) #define LL(n) scanf("%lld", &(n)) #define pb(n) push_back((n)) #define mp(i, j) make_pair((i), (j)) #define eb(i, j) emplace_back((i), (j)) #include <bits/stdc++.h> using namespace std; //------------------------------typedef集 typedef vector<int> vi; typedef pair<int, int> pi; typedef vector<pi> vpi; typedef vector<vi> vvi; typedef vector<vpi> vvpi; typedef vector<vvi> vvvi; typedef long long ll; const int mod = 1000000009; int n; vvi ans; int main() { cin >> n; int k = sqrt((double)n * 2); if (n == 1) { cout << "Yes" << endl; cout << 2 << endl; cout << "1 1" << endl; cout << "1 1" << endl; } else if (k * (k + 1) == 2 * n) { cout << "Yes" << endl; cout << k + 1 << endl; ans.resize(k + 1); int elm = 1; REP(i, k + 1) { int st = ans[i].size(); FOR(j, st + 1, k + 1) { ans[i].pb(elm); ans[j].pb(elm); elm++; } cout << k << " "; for (auto v : ans[i]) cout << v << " "; cout << endl; } } else { cout << "No" << endl; } }
replace
44
45
44
45
0
p03224
C++
Runtime Error
#include <iostream> using namespace std; int ans[350][350]; int main() { int n, k = 1; scanf("%d", &n); while (k * (k - 1) / 2 < n) k++; if (k * (k - 1) / 2 == n) { printf("Yes\n%d\n", k); int cur = 1; for (int i = 0; i < k - 1; i++) { for (int j = i; j < k - 1; j++) ans[i][j] = cur + j - i; for (int j = i + 1; j < k; j++) ans[j][i] = cur + j - i - 1; cur += k - i - 1; } for (int i = 0; i < k; i++) { printf("%d", k - 1); for (int j = 0; j < k - 1; j++) printf(" %d", ans[i][j]); printf("\n"); } } else printf("No"); }
#include <iostream> using namespace std; int ans[500][500]; int main() { int n, k = 1; scanf("%d", &n); while (k * (k - 1) / 2 < n) k++; if (k * (k - 1) / 2 == n) { printf("Yes\n%d\n", k); int cur = 1; for (int i = 0; i < k - 1; i++) { for (int j = i; j < k - 1; j++) ans[i][j] = cur + j - i; for (int j = i + 1; j < k; j++) ans[j][i] = cur + j - i - 1; cur += k - i - 1; } for (int i = 0; i < k; i++) { printf("%d", k - 1); for (int j = 0; j < k - 1; j++) printf(" %d", ans[i][j]); printf("\n"); } } else printf("No"); }
replace
2
3
2
3
0
p03224
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef pair<int, int> pii; const int inf = 0x3f3f3f3f, oo = inf; #define pi 3.14159265358979323846 #define IL inline #define RG register #define rep(i, a, b) for (RG int i = (a); i < int(b); ++i) #define Rep(i, a, b) for (RG int i = (a); i <= (b); ++i) #define Dep(i, a, b) for (RG int i = (a); i >= (b); --i) #define pc putchar #define gc getchar IL ll read() { RG ll x = 0; char f = 0; RG char c = gc(); for (; !isdigit(c); c = gc()) f |= (c == '-'); for (; isdigit(c); c = gc()) x = (x << 1) + (x << 3) + (c ^ 48); return f ? -x : x; } IL void write(ll x) { if (x < 0) x = -x, pc('-'); if (x >= 10) write(x / 10); pc(x % 10 + '0'); } IL void writeln(ll x) { write(x); puts(""); } IL void writeln(ll x, char c, ll y) { write(x); pc(c); writeln(y); } IL void writeln(ll x, char c, ll y, char d, ll z) { write(x); pc(c); write(y); pc(d); writeln(z); } #define debug(x) printf(#x " = %d\n", x); #define rd() read() #define rdb() readdb() #define mem(x, v) memset(x, v, sizeof(x)) #define pb push_back #define mp make_pair #define sqr(x) ((x) * (x)) #define lowbit(x) ((x) & (-(x))) #define fin(x) freopen(#x ".in", "r", stdin) #define fout(x) freopen(#x ".out", "w", stdout) #define y1 ____y1 #define markh __markh #define union _union const int maxn = 1e5 + 233; int n, a[353][maxn]; int vis[maxn], mark[maxn], cnt[maxn]; void solve(int k) { puts("Yes"); printf("%d\n", k + 1); mem(vis, 0); Rep(i, 1, n) cnt[i] = 2; for (int i = 1; i <= k + 1; ++i) { printf("%d ", k); mem(mark, true); Rep(j, 1, n) if (cnt[j] == 0) mark[j] = false; int res = 0; for (int j = 1; j <= n; ++j) { if (mark[j]) { a[i][++a[i][0]] = j; --cnt[j]; printf("%d ", j); if (vis[j] == 0) vis[j] = i; else { for (int w = 1; w <= a[vis[j]][0]; ++w) { mark[a[vis[j]][w]] = false; } } if (++res == k) break; } } puts(""); } } // k+1个长度为k的元素 int main() { n = read(); for (int k = 1; k * (k + 1) <= 2 * n; ++k) { if (k * (k + 1) == 2 * n) { solve(k); return 0; } } puts("No"); return 0; } // 长度为k // k*(k+1)=2*n /*n = 6 1 2 3 3 4 5 1 4 6 2 5 6*/
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> vi; typedef pair<int, int> pii; const int inf = 0x3f3f3f3f, oo = inf; #define pi 3.14159265358979323846 #define IL inline #define RG register #define rep(i, a, b) for (RG int i = (a); i < int(b); ++i) #define Rep(i, a, b) for (RG int i = (a); i <= (b); ++i) #define Dep(i, a, b) for (RG int i = (a); i >= (b); --i) #define pc putchar #define gc getchar IL ll read() { RG ll x = 0; char f = 0; RG char c = gc(); for (; !isdigit(c); c = gc()) f |= (c == '-'); for (; isdigit(c); c = gc()) x = (x << 1) + (x << 3) + (c ^ 48); return f ? -x : x; } IL void write(ll x) { if (x < 0) x = -x, pc('-'); if (x >= 10) write(x / 10); pc(x % 10 + '0'); } IL void writeln(ll x) { write(x); puts(""); } IL void writeln(ll x, char c, ll y) { write(x); pc(c); writeln(y); } IL void writeln(ll x, char c, ll y, char d, ll z) { write(x); pc(c); write(y); pc(d); writeln(z); } #define debug(x) printf(#x " = %d\n", x); #define rd() read() #define rdb() readdb() #define mem(x, v) memset(x, v, sizeof(x)) #define pb push_back #define mp make_pair #define sqr(x) ((x) * (x)) #define lowbit(x) ((x) & (-(x))) #define fin(x) freopen(#x ".in", "r", stdin) #define fout(x) freopen(#x ".out", "w", stdout) #define y1 ____y1 #define markh __markh #define union _union const int maxn = 1e5 + 233; int n, a[853][maxn]; int vis[maxn], mark[maxn], cnt[maxn]; void solve(int k) { puts("Yes"); printf("%d\n", k + 1); mem(vis, 0); Rep(i, 1, n) cnt[i] = 2; for (int i = 1; i <= k + 1; ++i) { printf("%d ", k); mem(mark, true); Rep(j, 1, n) if (cnt[j] == 0) mark[j] = false; int res = 0; for (int j = 1; j <= n; ++j) { if (mark[j]) { a[i][++a[i][0]] = j; --cnt[j]; printf("%d ", j); if (vis[j] == 0) vis[j] = i; else { for (int w = 1; w <= a[vis[j]][0]; ++w) { mark[a[vis[j]][w]] = false; } } if (++res == k) break; } } puts(""); } } // k+1个长度为k的元素 int main() { n = read(); for (int k = 1; k * (k + 1) <= 2 * n; ++k) { if (k * (k + 1) == 2 * n) { solve(k); return 0; } } puts("No"); return 0; } // 长度为k // k*(k+1)=2*n /*n = 6 1 2 3 3 4 5 1 4 6 2 5 6*/
replace
62
63
62
63
-11
p03224
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using i64 = int64_t; #define rep(i, x, y) \ for (i64 i = i64(x), i##_max_for_repmacro = i64(y); \ i < i##_max_for_repmacro; ++i) #define debug(x) #x << "=" << (x) #ifdef DEBUG #define _GLIBCXX_DEBUG #define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl #else #define print(x) #endif const int inf = 1.01e9; const i64 inf64 = 4.01e18; const double eps = 1e-9; template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (const auto &v : vec) { os << v << ","; } os << "]"; return os; } void solve() { int N; cin >> N; int k = 1; while (k * (k - 1) / 2 <= N) { if (k * (k - 1) / 2 == N) { break; } ++k; } if (k * (k - 1) / 2 != N) { cout << "No" << endl; return; } cout << "Yes" << endl; vector<pair<int, int>> x(N); int j = 0; rep(i, 0, k) { rep(l, i + 1, k) { x[j] = make_pair(i, l); ++j; } } cout << k << endl; vector<vector<int>> ans(k); rep(i, 0, N) { ans[x[i].first].push_back(i + 1); ans[x[i].second].push_back(i + 1); } rep(i, 0, k) { cout << ans[i].size(); for (int j : ans[k]) { cout << " " << j; } cout << endl; } } int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(16); solve(); return 0; }
#include <bits/stdc++.h> using namespace std; using i64 = int64_t; #define rep(i, x, y) \ for (i64 i = i64(x), i##_max_for_repmacro = i64(y); \ i < i##_max_for_repmacro; ++i) #define debug(x) #x << "=" << (x) #ifdef DEBUG #define _GLIBCXX_DEBUG #define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl #else #define print(x) #endif const int inf = 1.01e9; const i64 inf64 = 4.01e18; const double eps = 1e-9; template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (const auto &v : vec) { os << v << ","; } os << "]"; return os; } void solve() { int N; cin >> N; int k = 1; while (k * (k - 1) / 2 <= N) { if (k * (k - 1) / 2 == N) { break; } ++k; } if (k * (k - 1) / 2 != N) { cout << "No" << endl; return; } cout << "Yes" << endl; vector<pair<int, int>> x(N); int j = 0; rep(i, 0, k) { rep(l, i + 1, k) { x[j] = make_pair(i, l); ++j; } } cout << k << endl; vector<vector<int>> ans(k); rep(i, 0, N) { ans[x[i].first].push_back(i + 1); ans[x[i].second].push_back(i + 1); } rep(i, 0, k) { cout << ans[i].size(); for (int j : ans[i]) { cout << " " << j; } cout << endl; } } int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); cout.setf(ios::fixed); cout.precision(16); solve(); return 0; }
replace
67
68
67
68
-11
p03224
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, Ans[400][400], cnt[400]; int main() { cin >> n; int k = 0; for (int i = 1; i * (i - 1) / 2 <= n; i++) if (i * (i - 1) / 2 == n) k = i; if (!k) return puts("No"), 0; printf("Yes\n%d\n", k); for (int i = 1, id = 1; i <= k; i++) for (int j = i + 1; j <= k; j++) { Ans[i][++cnt[i]] = id; Ans[j][++cnt[j]] = id; id++; } for (int i = 1; i <= k; i++) { printf("%d ", k - 1); for (int j = 1; j < k; j++) printf("%d ", Ans[i][j]); puts(""); } return 0; }
#include <bits/stdc++.h> using namespace std; int n, Ans[1000][1000], cnt[1000]; int main() { cin >> n; int k = 0; for (int i = 1; i * (i - 1) / 2 <= n; i++) if (i * (i - 1) / 2 == n) k = i; if (!k) return puts("No"), 0; printf("Yes\n%d\n", k); for (int i = 1, id = 1; i <= k; i++) for (int j = i + 1; j <= k; j++) { Ans[i][++cnt[i]] = id; Ans[j][++cnt[j]] = id; id++; } for (int i = 1; i <= k; i++) { printf("%d ", k - 1); for (int j = 1; j < k; j++) printf("%d ", Ans[i][j]); puts(""); } return 0; }
replace
2
3
2
3
0
p03224
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long LL; typedef pair<int, int> pii; const int MAXN = 123456; vector<int> ans[MAXN]; int main() { int n; scanf("%d", &n); int tmp = n * 2; int k = sqrt(tmp); if (k * (k + 1) != tmp) return puts("87"); printf("Yes\n%d\n", k); int cur = 1; for (int i = 1; i <= k + 1; i++) { printf("%d ", k); int cnt = 0; for (int j = 1; j < i; j++) { printf("%d ", ans[j].back()); ans[j].pop_back(); cnt++; } for (int j = 0; j < k - cnt; j++) { printf("%d ", cur); ans[i].push_back(cur++); } puts(""); } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; typedef long long LL; typedef pair<int, int> pii; const int MAXN = 123456; vector<int> ans[MAXN]; int main() { int n; scanf("%d", &n); int tmp = n * 2; int k = sqrt(tmp); if (k * (k + 1) != tmp) return !printf("No\n"); printf("Yes\n%d\n", k + 1); int cur = 1; for (int i = 1; i <= k + 1; i++) { printf("%d ", k); int cnt = 0; for (int j = 1; j < i; j++) { printf("%d ", ans[j].back()); ans[j].pop_back(); cnt++; } for (int j = 0; j < k - cnt; j++) { printf("%d ", cur); ans[i].push_back(cur++); } puts(""); } return 0; }
replace
26
28
26
28
0
p03224
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef int sign; typedef long long ll; #define For(i, a, b) for (register sign i = (sign)(a); i <= (sign)(b); ++i) #define Fordown(i, a, b) for (register sign i = (sign)(a); i >= (sign)(b); --i) const int N = 320 + 5; template <typename T> bool cmax(T &a, T b) { return (a < b) ? a = b, 1 : 0; } template <typename T> bool cmin(T &a, T b) { return (a > b) ? a = b, 1 : 0; } template <typename T> T read() { T ans = 0, f = 1; char ch = getchar(); while (!isdigit(ch) && ch != '-') ch = getchar(); if (ch == '-') f = -1, ch = getchar(); while (isdigit(ch)) ans = (ans << 3) + (ans << 1) + (ch - '0'), ch = getchar(); return ans * f; } template <typename T> void write(T x, char y) { if (x == 0) { putchar('0'), putchar(y); return; } if (x < 0) { putchar('-'); x = -x; } static char wr[20]; int top = 0; for (; x; x /= 10) wr[++top] = x % 10 + '0'; while (top) putchar(wr[top--]); putchar(y); } void file() { #ifndef ONLINE_JUDGE freopen("in", "r", stdin); freopen("out", "w", stdout); #endif } int n; void input() { n = read<int>(); } vector<int> E[N]; #define pb push_back void work() { int m = 0; for (int i = 1; i * (i - 1) <= n * 2; i++) if (i * (i - 1) == n * 2) m = i; if (!m) { puts("No"); return; } int now = 1; puts("Yes"); write(m, '\n'); For(i, 1, m) For(j, i + 1, m) E[i].pb(now), E[j].pb(now), now++; For(i, 1, m) { write(E[i].size(), ' '); for (int v : E[i]) write(v, ' '); puts(""); } } int main() { // file(); input(); work(); return 0; }
#include <bits/stdc++.h> using namespace std; typedef int sign; typedef long long ll; #define For(i, a, b) for (register sign i = (sign)(a); i <= (sign)(b); ++i) #define Fordown(i, a, b) for (register sign i = (sign)(a); i >= (sign)(b); --i) const int N = 1e3 + 5; template <typename T> bool cmax(T &a, T b) { return (a < b) ? a = b, 1 : 0; } template <typename T> bool cmin(T &a, T b) { return (a > b) ? a = b, 1 : 0; } template <typename T> T read() { T ans = 0, f = 1; char ch = getchar(); while (!isdigit(ch) && ch != '-') ch = getchar(); if (ch == '-') f = -1, ch = getchar(); while (isdigit(ch)) ans = (ans << 3) + (ans << 1) + (ch - '0'), ch = getchar(); return ans * f; } template <typename T> void write(T x, char y) { if (x == 0) { putchar('0'), putchar(y); return; } if (x < 0) { putchar('-'); x = -x; } static char wr[20]; int top = 0; for (; x; x /= 10) wr[++top] = x % 10 + '0'; while (top) putchar(wr[top--]); putchar(y); } void file() { #ifndef ONLINE_JUDGE freopen("in", "r", stdin); freopen("out", "w", stdout); #endif } int n; void input() { n = read<int>(); } vector<int> E[N]; #define pb push_back void work() { int m = 0; for (int i = 1; i * (i - 1) <= n * 2; i++) if (i * (i - 1) == n * 2) m = i; if (!m) { puts("No"); return; } int now = 1; puts("Yes"); write(m, '\n'); For(i, 1, m) For(j, i + 1, m) E[i].pb(now), E[j].pb(now), now++; For(i, 1, m) { write(E[i].size(), ' '); for (int v : E[i]) write(v, ' '); puts(""); } } int main() { // file(); input(); work(); return 0; }
replace
6
7
6
7
0
p03224
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <vector> using namespace std; template <typename Tp> inline void getint(Tp &num) { register int ch, neg = 0; while (!isdigit(ch = getchar())) if (ch == '-') neg = 1; num = ch & 15; while (isdigit(ch = getchar())) num = num * 10 + (ch & 15); if (neg) num = -num; } int N, k; vector<int> S[320]; int main() { getint(N), k = (int)sqrt((N << 3) + 1.0) + 1 >> 1; if (k * (k - 1) != N << 1) return puts("No"), 0; for (register int i = 1, cur = 0; i <= k; i++) for (register int j = i + 1; j <= k; j++) S[i].push_back(++cur), S[j].push_back(cur); puts("Yes"), printf("%d\n", k); for (register int i = 1, siz; i <= k; i++, puts("")) { printf("%d ", siz = S[i].size()); for (register int j = 0; j < siz; j++) printf("%d ", S[i][j]); } return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <vector> using namespace std; template <typename Tp> inline void getint(Tp &num) { register int ch, neg = 0; while (!isdigit(ch = getchar())) if (ch == '-') neg = 1; num = ch & 15; while (isdigit(ch = getchar())) num = num * 10 + (ch & 15); if (neg) num = -num; } int N, k; vector<int> S[450]; int main() { getint(N), k = (int)sqrt((N << 3) + 1.0) + 1 >> 1; if (k * (k - 1) != N << 1) return puts("No"), 0; for (register int i = 1, cur = 0; i <= k; i++) for (register int j = i + 1; j <= k; j++) S[i].push_back(++cur), S[j].push_back(cur); puts("Yes"), printf("%d\n", k); for (register int i = 1, siz; i <= k; i++, puts("")) { printf("%d ", siz = S[i].size()); for (register int j = 0; j < siz; j++) printf("%d ", S[i][j]); } return 0; }
replace
22
23
22
23
0
p03224
C++
Runtime Error
#include <bits/stdc++.h> #define r(i, n) for (int i = 0; i < n; i++) #define int long long using namespace std; typedef pair<int, int> P; typedef pair<int, P> P2; #define fi first #define sese cond int dx[] = {0, 1, 0, -1}; int dy[] = {-1, 0, 1, 0}; map<int, int> st; signed main() { int x = 1; for (int i = 2; i <= 100000; i++) { st[x] = i - 1; x += i; } int n; cin >> n; if (!st.count(n)) { cout << "No" << endl; return 0; } cout << "Yes" << endl; cout << st[n] + 1 << endl; int a = st[n]; int ans[a][a + 1], cnt = 1; for (int i = a, k = 0; i >= 1; i--, k++) { for (int j = 0; j < i; j++) { ans[k][j + k] = cnt; ans[k + j + 1][k] = cnt; cnt++; } } r(i, a + 1) { cout << a; r(j, a) { cout << ' '; cout << ans[i][j]; } cout << endl; } }
#include <bits/stdc++.h> #define r(i, n) for (int i = 0; i < n; i++) #define int long long using namespace std; typedef pair<int, int> P; typedef pair<int, P> P2; #define fi first #define sese cond int dx[] = {0, 1, 0, -1}; int dy[] = {-1, 0, 1, 0}; map<int, int> st; signed main() { int x = 1; for (int i = 2; i <= 100000; i++) { st[x] = i - 1; x += i; } int n; cin >> n; if (!st.count(n)) { cout << "No" << endl; return 0; } cout << "Yes" << endl; cout << st[n] + 1 << endl; int a = st[n]; int ans[a + 1][a], cnt = 1; for (int i = a, k = 0; i >= 1; i--, k++) { for (int j = 0; j < i; j++) { ans[k][j + k] = cnt; ans[k + j + 1][k] = cnt; cnt++; } } r(i, a + 1) { cout << a; r(j, a) { cout << ' '; cout << ans[i][j]; } cout << endl; } }
replace
33
34
33
34
0
p03224
C++
Runtime Error
#include <cstdio> #include <cstring> int a[400][400]; int main() { int n; scanf("%d", &n); int id = -1; for (int i = 1; i * (i + 1) / 2 <= n; i++) { if (n == i * (i + 1) / 2) { id = i; break; } } if (id == -1) return 0 * puts("No"); puts("Yes"); printf("%d\n", id + 1); int s = 0; for (int i = 1; i <= id + 1; i++) { printf("%d ", id); for (int j = 1; j < i; j++) { a[i][j] = a[j][i - 1]; } for (int j = i; j <= id; j++) a[i][j] = ++s; for (int j = 1; j <= id; j++) printf("%d ", a[i][j]); puts(""); } return 0; }
#include <cstdio> #include <cstring> int a[1000][1000]; int main() { int n; scanf("%d", &n); int id = -1; for (int i = 1; i * (i + 1) / 2 <= n; i++) { if (n == i * (i + 1) / 2) { id = i; break; } } if (id == -1) return 0 * puts("No"); puts("Yes"); printf("%d\n", id + 1); int s = 0; for (int i = 1; i <= id + 1; i++) { printf("%d ", id); for (int j = 1; j < i; j++) { a[i][j] = a[j][i - 1]; } for (int j = i; j <= id; j++) a[i][j] = ++s; for (int j = 1; j <= id; j++) printf("%d ", a[i][j]); puts(""); } return 0; }
replace
3
4
3
4
0
p03224
C++
Runtime Error
#include <bits/stdc++.h> int n, m, i, j, x; std::vector<int> v[999]; int main() { scanf("%d", &n); m = (1 + sqrt(1 + 8 * n)) / 2; if (m * (m - 1) / 2 != n) return puts("No"); for (i = 1; i < m; ++i) for (j = i + 1; j <= m; ++j) ++x, v[i].push_back(x), v[j].push_back(x); printf("Yes\n%d\n", m); for (i = 1; i <= m; ++i) for (int x : v[printf("%d ", m - 1), i]) printf("%d%c", x, x == v[i].back() ? '\n' : ' '); return 0; }
#include <bits/stdc++.h> int n, m, i, j, x; std::vector<int> v[999]; int main() { scanf("%d", &n); m = (1 + sqrt(1 + 8 * n)) / 2; if (m * (m - 1) / 2 != n) return puts("No"), 0; for (i = 1; i < m; ++i) for (j = i + 1; j <= m; ++j) ++x, v[i].push_back(x), v[j].push_back(x); printf("Yes\n%d\n", m); for (i = 1; i <= m; ++i) for (int x : v[printf("%d ", m - 1), i]) printf("%d%c", x, x == v[i].back() ? '\n' : ' '); return 0; }
replace
7
8
7
8
0
p03224
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int d[350][350]; void solve() { int n; cin >> n; int k = 1; auto c2 = [](int x) { return x * (x - 1) / 2; }; while (c2(k) < n) { k++; } if (c2(k) != n) { cout << "No"; return; } int edge_cnt = 1; for (int i = 0; i < k; i++) { for (int j = i + 1; j < k; j++) { d[i][j] = d[j][i] = edge_cnt++; } } cout << "Yes\n"; cout << k << "\n"; for (int i = 0; i < k; i++) { cout << (k - 1) << ' '; for (int j = 0; j < k; j++) { if (i != j) { cout << d[i][j] << ' '; } } cout << "\n"; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); cout << endl; }
#include <bits/stdc++.h> using namespace std; int d[450][450]; void solve() { int n; cin >> n; int k = 1; auto c2 = [](int x) { return x * (x - 1) / 2; }; while (c2(k) < n) { k++; } if (c2(k) != n) { cout << "No"; return; } int edge_cnt = 1; for (int i = 0; i < k; i++) { for (int j = i + 1; j < k; j++) { d[i][j] = d[j][i] = edge_cnt++; } } cout << "Yes\n"; cout << k << "\n"; for (int i = 0; i < k; i++) { cout << (k - 1) << ' '; for (int j = 0; j < k; j++) { if (i != j) { cout << d[i][j] << ' '; } } cout << "\n"; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); cout << endl; }
replace
4
5
4
5
0
p03224
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long /* */ // #undef int #define INF 1000000009ll #define INFL 1000000000000000018ll #define mod 1000000007 #define pb push_back #define fi first #define se second #define mk make_pair typedef pair<int, int> PA; typedef priority_queue<int> PQ; typedef priority_queue<pair<int, PA>, vector<pair<int, PA>>, greater<pair<int, PA>>> PQG; int N; vector<int> V[1000]; signed main() { cin >> N; if (N == 1) return 1; bool flag = true; int res; int ans; for (int i = 2; i * (i + 1) / 2 <= N; i++) { if (i * (i + 1) / 2 == N) { res = i; ans = i; flag = false; } } if (flag) { printf("No\n"); return 0; } else { printf("Yes\n"); } int in1 = 0, in2 = 1; for (int i = 1; i <= N; i++) { V[in1].pb(i); V[in2 + in1].pb(i); if (in2 % res == 0) { res--; in1++; in2 = 1; } else in2++; } printf("%lld\n", ans + 1); for (int i = 0; i <= ans; i++) { printf("%lld ", (int)V[i].size()); for (int j = 0; j < (int)V[i].size(); j++) { printf("%lld", V[i][j]); if (j < (int)V[i].size() - 1) { printf(" "); } } printf("\n"); } return 0; } /* */
#include <bits/stdc++.h> using namespace std; #define int long long /* */ // #undef int #define INF 1000000009ll #define INFL 1000000000000000018ll #define mod 1000000007 #define pb push_back #define fi first #define se second #define mk make_pair typedef pair<int, int> PA; typedef priority_queue<int> PQ; typedef priority_queue<pair<int, PA>, vector<pair<int, PA>>, greater<pair<int, PA>>> PQG; int N; vector<int> V[1000]; signed main() { cin >> N; if (N == 1) { printf("Yes\n2\n1 1\n1 1\n"); return 0; } bool flag = true; int res; int ans; for (int i = 2; i * (i + 1) / 2 <= N; i++) { if (i * (i + 1) / 2 == N) { res = i; ans = i; flag = false; } } if (flag) { printf("No\n"); return 0; } else { printf("Yes\n"); } int in1 = 0, in2 = 1; for (int i = 1; i <= N; i++) { V[in1].pb(i); V[in2 + in1].pb(i); if (in2 % res == 0) { res--; in1++; in2 = 1; } else in2++; } printf("%lld\n", ans + 1); for (int i = 0; i <= ans; i++) { printf("%lld ", (int)V[i].size()); for (int j = 0; j < (int)V[i].size(); j++) { printf("%lld", V[i][j]); if (j < (int)V[i].size() - 1) { printf(" "); } } printf("\n"); } return 0; } /* */
replace
23
25
23
27
0
p03224
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<int, ll> pil; const int maxN = 1e5 + 10; int a[maxN]; int b[maxN]; int c[maxN]; vector<int> w[maxN]; int n; int main() { scanf("%d", &n); for (int i = 2; i <= 1000; i++) { int k = (i) * (i - 1) / 2; b[k] = 1; c[k] = i; } if (b[n] != 1) { puts("No"); return 0; } else { puts("Yes"); printf("%d\n", c[n]); int cnt = 0; for (int i = 1; i < c[n]; i++) { for (int j = i + 1; j <= c[n]; j++) { cnt++; w[i].push_back(cnt); w[j].push_back(cnt); } } for (int i = 1; i <= c[n]; i++) { int sz = w[i].size(); printf("%d ", sz); for (int j = 0; j < w[i].size() - 1; j++) { printf("%d ", w[i][j]); } printf("%d\n", w[i][sz - 1]); } } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, int> pli; typedef pair<int, ll> pil; const int maxN = 1e5 + 10; int a[maxN]; int b[10 * maxN]; int c[10 * maxN]; vector<int> w[maxN]; int n; int main() { scanf("%d", &n); for (int i = 2; i <= 1000; i++) { int k = (i) * (i - 1) / 2; b[k] = 1; c[k] = i; } if (b[n] != 1) { puts("No"); return 0; } else { puts("Yes"); printf("%d\n", c[n]); int cnt = 0; for (int i = 1; i < c[n]; i++) { for (int j = i + 1; j <= c[n]; j++) { cnt++; w[i].push_back(cnt); w[j].push_back(cnt); } } for (int i = 1; i <= c[n]; i++) { int sz = w[i].size(); printf("%d ", sz); for (int j = 0; j < w[i].size() - 1; j++) { printf("%d ", w[i][j]); } printf("%d\n", w[i][sz - 1]); } } return 0; }
replace
11
13
11
13
-11
p03224
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = int64_t; #define int ll #define FOR(i, a, b) for (int i = int(a); i < int(b); i++) #define REP(i, b) FOR(i, 0, b) #define MP make_pair #define PB push_back #define ALL(x) x.begin(), x.end() #ifdef LOCAL #define cerr (cerr << "-- line " << __LINE__ << " -- ") #else class CerrDummy { } cerrDummy; template <class T> CerrDummy &operator<<(CerrDummy &cd, const T &) { return cd; } using charTDummy = char; using traitsDummy = char_traits<charTDummy>; CerrDummy &operator<<(CerrDummy &cd, basic_ostream<charTDummy, traitsDummy> &( basic_ostream<charTDummy, traitsDummy> &)) { return cd; } #define cerr cerrDummy #endif #define REACH cerr << "reached" << endl #define DMP(x) cerr << #x << ":" << x << endl #define ZERO(x) memset(x, 0, sizeof(x)) #define ONE(x) memset(x, -1, sizeof(x)) using pi = pair<int, int>; using vi = vector<int>; using ld = long double; template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; REP(i, (int)v.size()) { if (i) os << ","; os << v[i]; } os << "}"; return os; } ll read() { ll i; scanf("%" SCNd64, &i); return i; } void printSpace() { printf(" "); } void printEoln() { printf("\n"); } void print(ll x, int suc = 1) { printf("%" PRId64, x); if (suc == 1) printEoln(); if (suc == 2) printSpace(); } string readString() { static char buf[3341000]; scanf("%s", buf); return string(buf); } char *readCharArray() { static char buf[3341000]; static int bufUsed = 0; char *ret = buf + bufUsed; scanf("%s", ret); bufUsed += strlen(ret) + 1; return ret; } template <class T, class U> void chmax(T &a, U b) { if (a < b) a = b; } template <class T, class U> void chmin(T &a, U b) { if (b < a) a = b; } template <class T> T Sq(const T &t) { return t * t; } // #define CAPITAL void Yes(bool ex = true) { #ifdef CAPITAL cout << "YES" << endl; #else cout << "Yes" << endl; #endif if (ex) exit(0); } void No(bool ex = true) { #ifdef CAPITAL cout << "NO" << endl; #else cout << "No" << endl; #endif if (ex) exit(0); } const ll infLL = LLONG_MAX / 3; #ifdef int const int inf = infLL; #else const int inf = INT_MAX / 2 - 100; #endif signed main() { int n = read(); int k; { int m = n * 8 + 1; int w = round(sqrt(double(m))); if (w * w != m) { No(); } w++; if (w % 2) No(); k = w / 2; } vector<vi> ans(k); int idx = 0; REP(i, k) FOR(j, i + 1, n) { ans[i].PB(idx); ans[j].PB(idx); idx++; } Yes(false); print(k); for (auto s : ans) { print(s.size(), 2); for (auto v : s) { print(v + 1, 2); } puts(""); } }
#include <bits/stdc++.h> using namespace std; using ll = int64_t; #define int ll #define FOR(i, a, b) for (int i = int(a); i < int(b); i++) #define REP(i, b) FOR(i, 0, b) #define MP make_pair #define PB push_back #define ALL(x) x.begin(), x.end() #ifdef LOCAL #define cerr (cerr << "-- line " << __LINE__ << " -- ") #else class CerrDummy { } cerrDummy; template <class T> CerrDummy &operator<<(CerrDummy &cd, const T &) { return cd; } using charTDummy = char; using traitsDummy = char_traits<charTDummy>; CerrDummy &operator<<(CerrDummy &cd, basic_ostream<charTDummy, traitsDummy> &( basic_ostream<charTDummy, traitsDummy> &)) { return cd; } #define cerr cerrDummy #endif #define REACH cerr << "reached" << endl #define DMP(x) cerr << #x << ":" << x << endl #define ZERO(x) memset(x, 0, sizeof(x)) #define ONE(x) memset(x, -1, sizeof(x)) using pi = pair<int, int>; using vi = vector<int>; using ld = long double; template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; REP(i, (int)v.size()) { if (i) os << ","; os << v[i]; } os << "}"; return os; } ll read() { ll i; scanf("%" SCNd64, &i); return i; } void printSpace() { printf(" "); } void printEoln() { printf("\n"); } void print(ll x, int suc = 1) { printf("%" PRId64, x); if (suc == 1) printEoln(); if (suc == 2) printSpace(); } string readString() { static char buf[3341000]; scanf("%s", buf); return string(buf); } char *readCharArray() { static char buf[3341000]; static int bufUsed = 0; char *ret = buf + bufUsed; scanf("%s", ret); bufUsed += strlen(ret) + 1; return ret; } template <class T, class U> void chmax(T &a, U b) { if (a < b) a = b; } template <class T, class U> void chmin(T &a, U b) { if (b < a) a = b; } template <class T> T Sq(const T &t) { return t * t; } // #define CAPITAL void Yes(bool ex = true) { #ifdef CAPITAL cout << "YES" << endl; #else cout << "Yes" << endl; #endif if (ex) exit(0); } void No(bool ex = true) { #ifdef CAPITAL cout << "NO" << endl; #else cout << "No" << endl; #endif if (ex) exit(0); } const ll infLL = LLONG_MAX / 3; #ifdef int const int inf = infLL; #else const int inf = INT_MAX / 2 - 100; #endif signed main() { int n = read(); int k; { int m = n * 8 + 1; int w = round(sqrt(double(m))); if (w * w != m) { No(); } w++; if (w % 2) No(); k = w / 2; } vector<vi> ans(k); int idx = 0; REP(i, k) FOR(j, i + 1, k) { ans[i].PB(idx); ans[j].PB(idx); idx++; } Yes(false); print(k); for (auto s : ans) { print(s.size(), 2); for (auto v : s) { print(v + 1, 2); } puts(""); } }
replace
143
144
143
144
0
p03224
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; typedef long long ll; typedef long double ld; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) #define F first #define S second const int mx = 200010; const ll mod = 1e9 + 7; #define bit(n, k) ((n >> k) & 1) //*n no k bit me 1 or 0*/ int main() { int n; cin >> n; rep(i, 1000) { int res = i * (i - 1) / 2; if (n != res) continue; cout << "Yes" << endl; cout << i << endl; vector<int> v[n]; int cnt = 1; rep(j, i) REP(k, j + 1, i) { v[j].emplace_back(cnt); v[k].emplace_back(cnt); cnt++; } rep(j, i) { cout << v[j].size() << " "; for (auto it : v[j]) cout << it << " "; cout << endl; } return 0; } cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; typedef long long ll; typedef long double ld; const int inf = 1e9 + 7; const ll longinf = 1LL << 60; #define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i) #define rep(i, n) REP(i, 0, n) #define F first #define S second const int mx = 200010; const ll mod = 1e9 + 7; #define bit(n, k) ((n >> k) & 1) //*n no k bit me 1 or 0*/ int main() { int n; cin >> n; rep(i, 1000) { int res = i * (i - 1) / 2; if (n != res) continue; cout << "Yes" << endl; cout << i << endl; vector<int> v[i]; int cnt = 1; rep(j, i) REP(k, j + 1, i) { v[j].emplace_back(cnt); v[k].emplace_back(cnt); cnt++; } rep(j, i) { cout << v[j].size() << " "; for (auto it : v[j]) cout << it << " "; cout << endl; } return 0; } cout << "No" << endl; return 0; }
replace
26
27
26
27
0
p03224
C++
Runtime Error
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; const int MAX_K = 1e3; int main() { int N; scanf("%d", &N); int k = 0; for (int res = 1; res <= MAX_K; res++) { if ((res * (res + 1)) / 2 == N) { k = res; break; } } if (k == 0) { printf("%s\n", "No"); return 0; } vector<int> vec[k + 1]; int cnt = 0; for (int i = 2; i <= k - 1; i++) { // 上から何段目スタートか for (int h = i * (i - 1) / 2 + 1; h <= i * (i + 1) / 2; h++) { vec[cnt].push_back(h); } int w = i * (i + 1) / 2; for (int times = 0; i + times < k; times++) { w += i + times; vec[cnt].push_back(w); } cnt++; } for (int s = 0; s < k; s++) { vec[cnt].push_back(((s * (s + 1)) / 2) + 1); } cnt++; for (int t = (k * (k - 1)) / 2 + 1; t <= k * (k + 1) / 2; t++) { vec[cnt].push_back(t); } cnt++; for (int u = 1; u <= k; u++) { vec[cnt].push_back((u * (u + 1)) / 2); } printf("%s\n", "Yes"); printf("%d\n", k + 1); for (int i = 0; i <= k; i++) { printf("%d ", (int)vec[i].size()); for (auto n : vec[i]) { printf("%d ", n); } printf("\n"); } return 0; }
#include <algorithm> #include <iostream> #include <vector> using namespace std; typedef long long ll; const int MAX_K = 1e3; int main() { int N; scanf("%d", &N); if (N == 1) { printf("%s\n", "Yes"); printf("%d\n", 2); printf("%d %d\n", 1, 1); printf("%d %d\n", 1, 1); return 0; } int k = 0; for (int res = 1; res <= MAX_K; res++) { if ((res * (res + 1)) / 2 == N) { k = res; break; } } if (k == 0) { printf("%s\n", "No"); return 0; } vector<int> vec[k + 1]; int cnt = 0; for (int i = 2; i <= k - 1; i++) { // 上から何段目スタートか for (int h = i * (i - 1) / 2 + 1; h <= i * (i + 1) / 2; h++) { vec[cnt].push_back(h); } int w = i * (i + 1) / 2; for (int times = 0; i + times < k; times++) { w += i + times; vec[cnt].push_back(w); } cnt++; } for (int s = 0; s < k; s++) { vec[cnt].push_back(((s * (s + 1)) / 2) + 1); } cnt++; for (int t = (k * (k - 1)) / 2 + 1; t <= k * (k + 1) / 2; t++) { vec[cnt].push_back(t); } cnt++; for (int u = 1; u <= k; u++) { vec[cnt].push_back((u * (u + 1)) / 2); } printf("%s\n", "Yes"); printf("%d\n", k + 1); for (int i = 0; i <= k; i++) { printf("%d ", (int)vec[i].size()); for (auto n : vec[i]) { printf("%d ", n); } printf("\n"); } return 0; }
insert
11
11
11
20
0
p03225
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, P> Q; typedef complex<double> C; #define cx real() #define cy imag() const ll INF = 1LL << 60; const double DINF = 1e30; const ll mod = 1000000007; const ll dx[4] = {1, 0, -1, 0}; const ll dy[4] = {0, -1, 0, 1}; const C I = C(0, 1); const double EPS = 1e-10; const ll NCK_MAX = 510000; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll extgcd(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1, y = 0; return a; } ll q = a / b, g = extgcd(b, a - q * b, x, y); ll z = x - q * y; x = y; y = z; return g; } ll invmod(ll a, ll m) { // a^-1 mod m ll x, y; extgcd(a, m, x, y); x %= m; if (x < 0) x += m; return x; } ll *fac, *finv, *inv; void nCk_init(ll mod) { fac = new ll[NCK_MAX]; finv = new ll[NCK_MAX]; inv = new ll[NCK_MAX]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < NCK_MAX; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } ll nCk(ll n, ll k, ll mod) { if (fac == NULL) nCk_init(mod); if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } template <typename T> class Zip { vector<T> d; bool flag; void init() { sort(d.begin(), d.end()); d.erase(unique(d.begin(), d.end()), d.end()); flag = false; } public: Zip() { flag = false; } void add(T x) { d.push_back(x); flag = true; } ll getNum(T x) { if (flag) init(); return lower_bound(d.begin(), d.end(), x) - d.begin(); } ll size() { if (flag) init(); return (ll)d.size(); } }; class UnionFind { vector<ll> par, rank; // par > 0: number, par < 0: -par public: UnionFind(ll n) : par(n, 1), rank(n, 0) {} ll getSize(ll x) { return par[find(x)]; } ll find(ll x) { if (par[x] > 0) return x; return -(par[x] = -find(-par[x])); } void merge(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = -y; } else { par[x] += par[y]; par[y] = -x; if (rank[x] == rank[y]) rank[x]++; } } bool isSame(ll x, ll y) { return find(x) == find(y); } }; template <typename T> class SegmentTree { ll n; vector<T> node; function<T(T, T)> fun, fun2; bool customChange; T outValue, initValue; public: void init(ll num, function<T(T, T)> resultFunction, T init, T out, function<T(T, T)> changeFunction = NULL) { // changeFunction: (input, beforevalue) => newvalue fun = resultFunction; fun2 = changeFunction; customChange = changeFunction != NULL; n = 1; while (n < num) n *= 2; node.resize(2 * n - 1); fill(node.begin(), node.end(), init); outValue = out; initValue = init; } void valueChange(ll num, T value) { num += n - 1; if (customChange) node[num] = fun2(value, node[num]); else node[num] = value; while (num > 0) num = (num - 1) / 2, node[num] = fun(node[num * 2 + 1], node[num * 2 + 2]); } T rangeQuery(ll a, ll b, ll l = 0, ll r = -1, ll k = 0) { // [a, b) if (r == -1) r = n; if (a <= l && r <= b) return node[k]; if (b <= l || r <= a) return outValue; ll mid = (l + r) / 2; return fun(rangeQuery(a, b, l, mid, 2 * k + 1), rangeQuery(a, b, mid, r, 2 * k + 2)); } }; template <typename T> class Graph { struct edge { ll to; T cost; }; struct edge_data { ll from, to; T cost; }; ll v; vector<vector<edge>> e, re; vector<edge_data> ed; vector<bool> used; vector<ll> vs, cmp; bool isDirected, isMinasEdge; public: Graph(ll _v, bool _isDirected = true, ll range_add = 0) { // range_add 0:no / 1:in / 2:out / 3:in+out //_v++; v = _v, isDirected = _isDirected; isMinasEdge = false; e.resize(v), re.resize(v); } void add_edge(ll s, ll t, T cost = 1) { e[s].push_back((edge){t, cost}); if (!isDirected) e[t].push_back((edge){s, cost}); else re[t].push_back((edge){s, cost}); ed.push_back((edge_data){s, t, cost}); if (cost < 0) isMinasEdge = true; } vector<T> dijkstra(ll s) { vector<T> d(v, INF); d[s] = 0; auto edge_cmp = [](const edge &a, const edge &b) { return a.cost > b.cost; }; priority_queue<edge, vector<edge>, decltype(edge_cmp)> pq(edge_cmp); pq.push((edge){s, 0}); while (!pq.empty()) { edge temp = pq.top(); pq.pop(); if (d[temp.to] < temp.cost) continue; for (const edge &next : e[temp.to]) { T cost = temp.cost + next.cost; if (d[next.to] > cost) { d[next.to] = cost; pq.push((edge){next.to, cost}); } } } return d; } vector<T> bellmanford(ll s) { vector<T> d(v, INF); d[s] = 0; for (ll i = 0; i < v; i++) { for (const edge_data &temp : ed) { if (d[temp.from] != INF && d[temp.to] > d[temp.from] + temp.cost) d[temp.to] = d[temp.from] + temp.cost; if (!isDirected && d[temp.to] != INF && d[temp.from] > d[temp.to] + temp.cost) d[temp.from] = d[temp.to] + temp.cost; } } for (ll i = 0; i < v; i++) { for (const edge_data &temp : ed) { if (d[temp.from] != INF && d[temp.to] > d[temp.from] + temp.cost) d[temp.to] = -INF; if (!isDirected && d[temp.to] != INF && d[temp.from] > d[temp.to] + temp.cost) d[temp.from] = -INF; } } return d; } vector<T> shortest_path(ll s) { if (isMinasEdge) return bellmanford(s); else return dijkstra(s); } T kruskal() { // if (isDirected) UnionFind uf(v); auto edge_data_cmp = [](const edge_data &a, const edge_data &b) { return a.cost < b.cost; }; sort(ed.begin(), ed.end(), edge_data_cmp); T ans = 0; for (const edge_data &temp : ed) { if (uf.isSame(temp.from, temp.to)) continue; uf.merge(temp.from, temp.to); ans += temp.cost; } return ans; } void scc_dfs(ll s) { used[s] = true; for (const edge &i : e[s]) if (!used[i.to]) scc_dfs(i.to); vs.push_back(s); } void scc_rdfs(ll s, ll k) { used[s] = true; cmp[s] = k; for (const edge &i : re[s]) if (!used[i.to]) scc_rdfs(i.to, k); } vector<ll> scc() { used.resize(v); fill(used.begin(), used.end(), false); cmp.resize(v); vs.clear(); for (ll i = 0; i < v; i++) if (!used[i]) scc_dfs(i); used.resize(v); fill(used.begin(), used.end(), false); ll k = 0; for (ll i = vs.size() - 1; i >= 0; i--) if (!used[vs[i]]) scc_rdfs(vs[i], k++); return cmp; } }; ll h, w, ans; char s[300][301]; bool d[610][610]; ll vsum[610][610], hsum[610][610]; ll get_h(ll i, ll j, ll k) { if (i < 0 || i >= h) return 0; return hsum[i][k + 1] - hsum[i][j]; } ll get_v(ll i, ll j, ll k) { if (i < 0 || i >= w) return 0; return vsum[k + 1][i] - vsum[j][i]; } bool get(ll i, ll j) { if (i < 0 || j < 0 || i >= h + w || j >= h + w) return false; return d[i][j]; } int main() { scanf("%lld%lld", &h, &w); for (ll i = 0; i < h; i++) { scanf("%s", s[i]); for (ll j = 0; j < w; j++) d[i + j][i - j + w - 1] = s[i][j] == '#'; } h = w = h + w; for (ll i = 0; i < h; i++) { for (ll j = 0; j < w; j++) { hsum[i][j + 1] = hsum[i][j] + (ll)d[i][j]; } } for (ll j = 0; j < w; j++) { for (ll i = 0; i < h; i++) { vsum[i + 1][j] = vsum[i][j] + (ll)d[i][j]; } } for (ll i = 0; i < h; i++) { for (ll j = 0; j < w; j++) if (d[i][j]) { for (ll k = j + 1; k < w; k++) if (d[i][k]) { ll diff = k - j; ans += get_h(i - diff, j, k) + get_h(i + diff, j, k); } } } for (ll i = 0; i < w; i++) { for (ll j = 0; j < h; j++) if (d[j][i]) { for (ll k = j + 1; k < h; k++) if (d[k][i]) { ll diff = k - j; ans += get_v(i - diff, j, k) + get_v(i + diff, j, k); } } } for (ll i = 0; i < h; i++) { for (ll j = 0; j < w; j++) if (d[i][j]) { for (ll x = 1; x < h; x++) { bool temp[5] = {get(i, j - x), get(i - x, j), get(i, j + x), get(i + x, j), get(i, j - x)}; for (ll k = 0; k < 4; k++) if (temp[k] && temp[k + 1]) ans--; } } } printf("%lld\n", ans); }
#include <algorithm> #include <bitset> #include <cassert> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, P> Q; typedef complex<double> C; #define cx real() #define cy imag() const ll INF = 1LL << 60; const double DINF = 1e30; const ll mod = 1000000007; const ll dx[4] = {1, 0, -1, 0}; const ll dy[4] = {0, -1, 0, 1}; const C I = C(0, 1); const double EPS = 1e-10; const ll NCK_MAX = 510000; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll extgcd(ll a, ll b, ll &x, ll &y) { if (b == 0) { x = 1, y = 0; return a; } ll q = a / b, g = extgcd(b, a - q * b, x, y); ll z = x - q * y; x = y; y = z; return g; } ll invmod(ll a, ll m) { // a^-1 mod m ll x, y; extgcd(a, m, x, y); x %= m; if (x < 0) x += m; return x; } ll *fac, *finv, *inv; void nCk_init(ll mod) { fac = new ll[NCK_MAX]; finv = new ll[NCK_MAX]; inv = new ll[NCK_MAX]; fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < NCK_MAX; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } ll nCk(ll n, ll k, ll mod) { if (fac == NULL) nCk_init(mod); if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } template <typename T> class Zip { vector<T> d; bool flag; void init() { sort(d.begin(), d.end()); d.erase(unique(d.begin(), d.end()), d.end()); flag = false; } public: Zip() { flag = false; } void add(T x) { d.push_back(x); flag = true; } ll getNum(T x) { if (flag) init(); return lower_bound(d.begin(), d.end(), x) - d.begin(); } ll size() { if (flag) init(); return (ll)d.size(); } }; class UnionFind { vector<ll> par, rank; // par > 0: number, par < 0: -par public: UnionFind(ll n) : par(n, 1), rank(n, 0) {} ll getSize(ll x) { return par[find(x)]; } ll find(ll x) { if (par[x] > 0) return x; return -(par[x] = -find(-par[x])); } void merge(ll x, ll y) { x = find(x); y = find(y); if (x == y) return; if (rank[x] < rank[y]) { par[y] += par[x]; par[x] = -y; } else { par[x] += par[y]; par[y] = -x; if (rank[x] == rank[y]) rank[x]++; } } bool isSame(ll x, ll y) { return find(x) == find(y); } }; template <typename T> class SegmentTree { ll n; vector<T> node; function<T(T, T)> fun, fun2; bool customChange; T outValue, initValue; public: void init(ll num, function<T(T, T)> resultFunction, T init, T out, function<T(T, T)> changeFunction = NULL) { // changeFunction: (input, beforevalue) => newvalue fun = resultFunction; fun2 = changeFunction; customChange = changeFunction != NULL; n = 1; while (n < num) n *= 2; node.resize(2 * n - 1); fill(node.begin(), node.end(), init); outValue = out; initValue = init; } void valueChange(ll num, T value) { num += n - 1; if (customChange) node[num] = fun2(value, node[num]); else node[num] = value; while (num > 0) num = (num - 1) / 2, node[num] = fun(node[num * 2 + 1], node[num * 2 + 2]); } T rangeQuery(ll a, ll b, ll l = 0, ll r = -1, ll k = 0) { // [a, b) if (r == -1) r = n; if (a <= l && r <= b) return node[k]; if (b <= l || r <= a) return outValue; ll mid = (l + r) / 2; return fun(rangeQuery(a, b, l, mid, 2 * k + 1), rangeQuery(a, b, mid, r, 2 * k + 2)); } }; template <typename T> class Graph { struct edge { ll to; T cost; }; struct edge_data { ll from, to; T cost; }; ll v; vector<vector<edge>> e, re; vector<edge_data> ed; vector<bool> used; vector<ll> vs, cmp; bool isDirected, isMinasEdge; public: Graph(ll _v, bool _isDirected = true, ll range_add = 0) { // range_add 0:no / 1:in / 2:out / 3:in+out //_v++; v = _v, isDirected = _isDirected; isMinasEdge = false; e.resize(v), re.resize(v); } void add_edge(ll s, ll t, T cost = 1) { e[s].push_back((edge){t, cost}); if (!isDirected) e[t].push_back((edge){s, cost}); else re[t].push_back((edge){s, cost}); ed.push_back((edge_data){s, t, cost}); if (cost < 0) isMinasEdge = true; } vector<T> dijkstra(ll s) { vector<T> d(v, INF); d[s] = 0; auto edge_cmp = [](const edge &a, const edge &b) { return a.cost > b.cost; }; priority_queue<edge, vector<edge>, decltype(edge_cmp)> pq(edge_cmp); pq.push((edge){s, 0}); while (!pq.empty()) { edge temp = pq.top(); pq.pop(); if (d[temp.to] < temp.cost) continue; for (const edge &next : e[temp.to]) { T cost = temp.cost + next.cost; if (d[next.to] > cost) { d[next.to] = cost; pq.push((edge){next.to, cost}); } } } return d; } vector<T> bellmanford(ll s) { vector<T> d(v, INF); d[s] = 0; for (ll i = 0; i < v; i++) { for (const edge_data &temp : ed) { if (d[temp.from] != INF && d[temp.to] > d[temp.from] + temp.cost) d[temp.to] = d[temp.from] + temp.cost; if (!isDirected && d[temp.to] != INF && d[temp.from] > d[temp.to] + temp.cost) d[temp.from] = d[temp.to] + temp.cost; } } for (ll i = 0; i < v; i++) { for (const edge_data &temp : ed) { if (d[temp.from] != INF && d[temp.to] > d[temp.from] + temp.cost) d[temp.to] = -INF; if (!isDirected && d[temp.to] != INF && d[temp.from] > d[temp.to] + temp.cost) d[temp.from] = -INF; } } return d; } vector<T> shortest_path(ll s) { if (isMinasEdge) return bellmanford(s); else return dijkstra(s); } T kruskal() { // if (isDirected) UnionFind uf(v); auto edge_data_cmp = [](const edge_data &a, const edge_data &b) { return a.cost < b.cost; }; sort(ed.begin(), ed.end(), edge_data_cmp); T ans = 0; for (const edge_data &temp : ed) { if (uf.isSame(temp.from, temp.to)) continue; uf.merge(temp.from, temp.to); ans += temp.cost; } return ans; } void scc_dfs(ll s) { used[s] = true; for (const edge &i : e[s]) if (!used[i.to]) scc_dfs(i.to); vs.push_back(s); } void scc_rdfs(ll s, ll k) { used[s] = true; cmp[s] = k; for (const edge &i : re[s]) if (!used[i.to]) scc_rdfs(i.to, k); } vector<ll> scc() { used.resize(v); fill(used.begin(), used.end(), false); cmp.resize(v); vs.clear(); for (ll i = 0; i < v; i++) if (!used[i]) scc_dfs(i); used.resize(v); fill(used.begin(), used.end(), false); ll k = 0; for (ll i = vs.size() - 1; i >= 0; i--) if (!used[vs[i]]) scc_rdfs(vs[i], k++); return cmp; } }; ll h, w, ans; char s[300][301]; bool d[610][610]; ll vsum[610][610], hsum[610][610]; ll get_h(ll i, ll j, ll k) { if (i < 0 || i >= h) return 0; return hsum[i][k + 1] - hsum[i][j]; } ll get_v(ll i, ll j, ll k) { if (i < 0 || i >= w) return 0; return vsum[k + 1][i] - vsum[j][i]; } bool get(ll i, ll j) { if (i < 0 || j < 0 || i >= h || j >= w) return false; return d[i][j]; } int main() { scanf("%lld%lld", &h, &w); for (ll i = 0; i < h; i++) { scanf("%s", s[i]); for (ll j = 0; j < w; j++) d[i + j][i - j + w - 1] = s[i][j] == '#'; } h = w = h + w; for (ll i = 0; i < h; i++) { for (ll j = 0; j < w; j++) { hsum[i][j + 1] = hsum[i][j] + (ll)d[i][j]; } } for (ll j = 0; j < w; j++) { for (ll i = 0; i < h; i++) { vsum[i + 1][j] = vsum[i][j] + (ll)d[i][j]; } } for (ll i = 0; i < h; i++) { for (ll j = 0; j < w; j++) if (d[i][j]) { for (ll k = j + 1; k < w; k++) if (d[i][k]) { ll diff = k - j; ans += get_h(i - diff, j, k) + get_h(i + diff, j, k); } } } for (ll i = 0; i < w; i++) { for (ll j = 0; j < h; j++) if (d[j][i]) { for (ll k = j + 1; k < h; k++) if (d[k][i]) { ll diff = k - j; ans += get_v(i - diff, j, k) + get_v(i + diff, j, k); } } } for (ll i = 0; i < h; i++) { for (ll j = 0; j < w; j++) if (d[i][j]) { for (ll x = 1; x < h; x++) { bool temp[5] = {get(i, j - x), get(i - x, j), get(i, j + x), get(i + x, j), get(i, j - x)}; for (ll k = 0; k < 4; k++) if (temp[k] && temp[k + 1]) ans--; } } } printf("%lld\n", ans); }
replace
338
339
338
339
0
p03225
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using lint = long long int; template <class T = int> using V = vector<T>; template <class T = int> using VV = V<V<T>>; template <class T> void assign(V<T> &v, int n, const T &a = T()) { v.assign(n, a); } template <class T, class... Args> void assign(V<T> &v, int n, const Args &...args) { v.resize(n); for (auto &&e : v) assign(e, args...); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int h, w; cin >> h >> w; V<string> s(h); for (int i = 0; i < h; ++i) cin >> s[i]; int res = 0; for (int xl = 0; xl < h; ++xl) for (int xr = xl + 1; xr < h; ++xr) for (int yl = 0; yl < w; ++yl) { for (int yr = yl + (xr - xl + 1 >> 1); yr <= yl + 2 * (xr - xl) and yr < w; ++yr) if ((xr - xl + yr - yl) % 3 == 0) { int l = xr - xl + yr - yl << 1; if (s[xl][yl] == '#') { res += s[xr][yl + l / 3 - (xr - xl)] == '#' and s[xl + l / 3 - (yr - yl)][yr] == '#'; } if (s[xl][yr] == '#' and xr - xl != yr - yl << 1 and xr - xl << 1 != yr - yl) { res += s[xr][yr - l / 3 + (xr - xl)] == '#' and s[xl + l / 3 - (yr - yl)][yl] == '#'; } if (s[xr][yl] == '#' and xr - xl != yr - yl << 1 and xr - xl << 1 != yr - yl) { res += s[xl][yl + l / 3 - (xr - xl)] == '#' and s[xr - l / 3 + (yr - yl)][yr] == '#'; } if (s[xr][yr] == '#') { res += s[xl][yr - l / 3 + (xr - xl)] == '#' and s[xr - l / 3 + (yr - yl)][yl] == '#'; } } } cout << res << '\n'; }
#include <bits/stdc++.h> using namespace std; using lint = long long int; template <class T = int> using V = vector<T>; template <class T = int> using VV = V<V<T>>; template <class T> void assign(V<T> &v, int n, const T &a = T()) { v.assign(n, a); } template <class T, class... Args> void assign(V<T> &v, int n, const Args &...args) { v.resize(n); for (auto &&e : v) assign(e, args...); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int h, w; cin >> h >> w; V<string> s(h); for (int i = 0; i < h; ++i) cin >> s[i]; VV<> cY; assign(cY, h + w - 1, h + w); VV<> cX; assign(cX, h + w - 1, h + w); for (int X = 0; X < h + w - 1; ++X) for (int Y = 0; Y < h + w - 1; ++Y) { int d = 1; if (X - Y + h - 1 & 1 or X + Y - h + 1 & 1) d = 0; int x = X - Y + h - 1 >> 1, y = X + Y - h + 1 >> 1; if (x < 0 or x >= h or y < 0 or y >= w) d = 0; else if (s[x][y] != '#') d = 0; cY[X][Y + 1] = cY[X][Y] + d; cX[Y][X + 1] = cX[Y][X] + d; } lint res = 0; for (int X = 0; X < h + w - 1; ++X) for (int Yl = 0; Yl < h + w - 1; ++Yl) for (int Yr = Yl + 1; Yr < h + w - 1; ++Yr) { if (X - Yl + h - 1 & 1 or X + Yl - h + 1 & 1 or X - Yr + h - 1 & 1 or X + Yr - h + 1 & 1) continue; int xl = X - Yl + h - 1 >> 1, yl = X + Yl - h + 1 >> 1; int xr = X - Yr + h - 1 >> 1, yr = X + Yr - h + 1 >> 1; if (xl < 0 or xl >= h or yl < 0 or yl >= w or xr < 0 or xr >= h or yr < 0 or yr >= w) continue; if (s[xl][yl] != '#' or s[xr][yr] != '#') continue; if (X - Yr + Yl >= 0) res += cY[X - Yr + Yl][Yr + 1] - cY[X - Yr + Yl][Yl]; if (X + Yr - Yl < h + w - 1) res += cY[X + Yr - Yl][Yr + 1] - cY[X + Yr - Yl][Yl]; } for (int Y = 0; Y < h + w - 1; ++Y) for (int Xl = 0; Xl < h + w - 1; ++Xl) for (int Xr = Xl + 1; Xr < h + w - 1; ++Xr) { if (Xl - Y + h - 1 & 1 or Xl + Y - h + 1 & 1 or Xr - Y + h - 1 & 1 or Xr + Y - h + 1 & 1) continue; int xl = Xl - Y + h - 1 >> 1, yl = Xl + Y - h + 1 >> 1; int xr = Xr - Y + h - 1 >> 1, yr = Xr + Y - h + 1 >> 1; if (xl < 0 or xl >= h or yl < 0 or yl >= w or xr < 0 or xr >= h or yr < 0 or yr >= w) continue; if (s[xl][yl] != '#' or s[xr][yr] != '#') continue; if (Y - Xr + Xl >= 0) res += cX[Y - Xr + Xl][Xr] - cX[Y - Xr + Xl][Xl + 1]; if (Y + Xr - Xl < h + w - 1) res += cX[Y + Xr - Xl][Xr] - cX[Y + Xr - Xl][Xl + 1]; } cout << res << '\n'; }
replace
23
50
23
76
TLE
p03225
C++
Runtime Error
/** * author: otera **/ #include <algorithm> #include <bitset> #include <cassert> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; #define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; typedef long double ld; const int inf = 1e9 + 7; const ll INF = 1LL << 60; const ll mod = 1e9 + 7; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<int, int> P; typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; #define fr first #define sc second #define all(c) c.begin(), c.end() #define pb push_back #define debug(x) cerr << #x << " = " << (x) << endl; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int h, w; vector<vector<char>> s; int c[800][800]; int x[800][800], y[800][800]; void solve() { cin >> h >> w; s.assign(h, vector<char>(w)); rep(i, 800) { rep(j, 800) { c[i][j] = x[i][j] = y[i][j] = 0; } } rep(i, h) { rep(j, w) { cin >> s[i][j]; if (s[i][j] == '#') c[i + j + 350][i - j + 350]++; } } rep(i, 700) { rep(j, 700) { y[i][j + 1] = y[i][j] + c[i][j]; } } rep(i, 700) { rep(j, 700) { x[i + 1][j] = x[i][j] + c[i][j]; } } int ans = 0; rep(i, 700) { for (int j = 1; j < 700; ++j) { for (int k = j + 1; k < 700; ++k) { if (!c[j][i] || !c[k][i]) continue; int d = k - j; if (i - d >= 0) ans += x[k + 1][i - d] - x[j][i - d]; if (i + d < 700) ans += x[k + 1][i + d] - x[j][i + d]; } } } rep(i, 700) { for (int j = 1; j < 700; ++j) { for (int k = j + 1; k < 700; ++k) { if (!c[i][j] || !c[i][k]) continue; int d = k - j; if (i - d >= 0) ans += y[i - d][k] - y[i - d][j + 1]; if (i + d < 700) ans += y[i + d][k] - y[i + d][j + 1]; } } } cout << ans << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(0); // cout << fixed << setprecision(10); // int t; cin >> t; rep(i, t)solve(); solve(); return 0; }
/** * author: otera **/ #include <algorithm> #include <bitset> #include <cassert> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; #define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; typedef long double ld; const int inf = 1e9 + 7; const ll INF = 1LL << 60; const ll mod = 1e9 + 7; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<int, int> P; typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; #define fr first #define sc second #define all(c) c.begin(), c.end() #define pb push_back #define debug(x) cerr << #x << " = " << (x) << endl; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int h, w; vector<vector<char>> s; int c[800][800]; int x[800][800], y[800][800]; void solve() { cin >> h >> w; s.assign(h, vector<char>(w)); rep(i, 800) { rep(j, 800) { c[i][j] = x[i][j] = y[i][j] = 0; } } rep(i, h) { rep(j, w) { cin >> s[i][j]; if (s[i][j] == '#') c[i + j + 20][i - j + 350]++; } } rep(i, 700) { rep(j, 700) { y[i][j + 1] = y[i][j] + c[i][j]; } } rep(i, 700) { rep(j, 700) { x[i + 1][j] = x[i][j] + c[i][j]; } } int ans = 0; rep(i, 700) { for (int j = 1; j < 700; ++j) { for (int k = j + 1; k < 700; ++k) { if (!c[j][i] || !c[k][i]) continue; int d = k - j; if (i - d >= 0) ans += x[k + 1][i - d] - x[j][i - d]; if (i + d < 700) ans += x[k + 1][i + d] - x[j][i + d]; } } } rep(i, 700) { for (int j = 1; j < 700; ++j) { for (int k = j + 1; k < 700; ++k) { if (!c[i][j] || !c[i][k]) continue; int d = k - j; if (i - d >= 0) ans += y[i - d][k] - y[i - d][j + 1]; if (i + d < 700) ans += y[i + d][k] - y[i + d][j + 1]; } } } cout << ans << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(0); // cout << fixed << setprecision(10); // int t; cin >> t; rep(i, t)solve(); solve(); return 0; }
replace
82
83
82
83
0
p03225
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> using namespace std; int H, W, N, p[609][609], q[609][609]; int vals(int px, int py) { px = min(px, 2 * N); py = min(py, 2 * N); if (px < 0 || py < 0) return 0; return p[px][py]; } int valm(int px, int py) { if (px < 0 || py < 0 || px > 2 * N || py > 2 * N) return 0; return q[px][py]; } int range_sum(int px, int py, int qx, int qy) { return vals(qx, qy) + vals(px - 1, py - 1) - vals(px - 1, qy) - vals(qx, py - 1); } int main() { cin >> H >> W; N = max(H, W); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { char c; cin >> c; if (c == '#') { p[i + j][i - j + N] = 1; q[i + j][i - j + N] = 1; } } } for (int i = 0; i <= 2 * N; i++) { for (int j = 1; j <= 2 * N; j++) p[i][j] += p[i][j - 1]; } for (int i = 0; i <= 2 * N; i++) { for (int j = 1; j <= 2 * N; j++) p[j][i] += p[j - 1][i]; } long long ans = 0; for (int i = 0; i <= 2 * N; i++) { for (int j = 0; j <= 2 * N; j++) { for (int k = 1; k <= N; k++) { int V1 = valm(i - k, j - k) * valm(i - k, j + k) * range_sum(i + k, j - k, i + k, j + k); int V2 = valm(i + k, j - k) * valm(i + k, j + k) * range_sum(i - k, j - k, i - k, j + k); int V3 = valm(i - k, j - k) * valm(i + k, j - k) * range_sum(i - k + 1, j + k, i + k - 1, j + k); int V4 = valm(i - k, j + k) * valm(i + k, j + k) * range_sum(i - k + 1, j - k, i + k - 1, j - k); ans += (V1 + V2 + V3 + V4); } } } cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> using namespace std; int H, W, N, p[609][609], q[609][609]; int vals(int px, int py) { px = min(px, 2 * N); py = min(py, 2 * N); if (px < 0 || py < 0) return 0; return p[px][py]; } int valm(int px, int py) { if (px < 0 || py < 0 || px > 2 * N || py > 2 * N) return 0; return q[px][py]; } int range_sum(int px, int py, int qx, int qy) { return vals(qx, qy) + vals(px - 1, py - 1) - vals(px - 1, qy) - vals(qx, py - 1); } int main() { cin >> H >> W; N = max(H, W); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { char c; cin >> c; if (c == '#') { p[i + j][i - j + N] = 1; q[i + j][i - j + N] = 1; } } } for (int i = 0; i <= 2 * N; i++) { for (int j = 1; j <= 2 * N; j++) p[i][j] += p[i][j - 1]; } for (int i = 0; i <= 2 * N; i++) { for (int j = 1; j <= 2 * N; j++) p[j][i] += p[j - 1][i]; } long long ans = 0; for (int i = 0; i <= 2 * N; i++) { for (int j = 0; j <= 2 * N; j++) { int S = min({i, j, 2 * N - i, 2 * N - j}); for (int k = 1; k <= S; k++) { int V1 = valm(i - k, j - k) * valm(i - k, j + k) * range_sum(i + k, j - k, i + k, j + k); int V2 = valm(i + k, j - k) * valm(i + k, j + k) * range_sum(i - k, j - k, i - k, j + k); int V3 = valm(i - k, j - k) * valm(i + k, j - k) * range_sum(i - k + 1, j + k, i + k - 1, j + k); int V4 = valm(i - k, j + k) * valm(i + k, j + k) * range_sum(i - k + 1, j - k, i + k - 1, j - k); ans += (V1 + V2 + V3 + V4); } } } cout << ans << endl; return 0; }
replace
50
51
50
52
TLE
p03225
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define all(v) (v).begin(), (v).end() #define sz(v) ((int)((v).size())) typedef long long ll; typedef pair<int, int> ii; const int MAXN = 305; const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0}; int n, m, diagCount; int d1[2 * MAXN][2 * MAXN]; int d2[2 * MAXN][2 * MAXN]; int p1[2 * MAXN][2 * MAXN]; int p2[2 * MAXN][2 * MAXN]; char a[MAXN][MAXN]; inline bool ok(int x, int y) { return (0 <= x && x < n) && (0 <= y && y < m); } inline void makePrefixSum(int *arr) { for (int i = 1; i < diagCount; i++) { arr[i] += arr[i - 1]; } } inline int prefSum(int *p, int a, int b, int dist) { if (a > b) { int t = a; a = b; b = t; } if (b >= diagCount) { b = diagCount - 1; } if (a < 0) { a = 0; } b -= dist; if (a > b) return 0; int res = p[b]; if (a > 0) res -= p[a - 1]; return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed); cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i]; } diagCount = n + m - 1; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i][j] == '#') { int z1 = i + j; int z2 = i + (m - j - 1); d1[z1][z2]++; d2[z2][z1]++; } } } ll ans = 0; for (int dist = 2; dist <= n + m - 2; dist += 2) { for (int z1 = 0; z1 < diagCount; z1++) { for (int z2 = 0; z2 < diagCount; z2++) { p1[z1][z2] = 0; p2[z1][z2] = 0; } } for (int z1 = 0; z1 < diagCount; z1++) { for (int z2 = 0; z2 < diagCount; z2++) { if (d1[z1][z2] == 1 && z2 + dist < diagCount && d1[z1][z2 + dist] == 1) { p1[z1][z2] = 1; } if (d2[z2][z1] == 1 && z1 + dist < diagCount && d2[z2][z1 + dist] == 1) { p2[z2][z1] = 1; } } } for (int z = 0; z < diagCount; z++) makePrefixSum(p1[z]); for (int z = 0; z < diagCount; z++) makePrefixSum(p2[z]); ll curDistAns = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i][j] == '#') { int cellAns = 0; for (int k = 0; k < 4; k++) { int xs = i + dist * dx[k]; int ys = j + dist * dy[k]; int xf = i + dist * dx[(k + 1) & 3]; int yf = j + dist * dy[(k + 1) & 3]; int z1s = xs + ys; int z2s = xs + (m - ys - 1); int z1f = xf + yf; int z2f = xf + (m - yf - 1); if (z1s == z1f) { if (0 <= z1s && z1s < diagCount) { int add = prefSum(p1[z1s], z2s, z2f, dist); cellAns += add; } } else if (z2s == z2f) { if (0 <= z2s && z2s < diagCount) { int add = prefSum(p2[z2s], z1s, z1f, dist); cellAns += add; } } else { throw 0; } int xm = (xs + xf) / 2; int ym = (ys + yf) / 2; if (ok(xs, ys) && ok(xm, ym)) { if (a[xs][ys] == '#' && a[xm][ym] == '#') { cellAns--; } } } curDistAns += cellAns; } } } ans += curDistAns; } cout << ans << endl; }
// #include <bits/stdc++.h> #include <cstdio> #include <iostream> using namespace std; #define all(v) (v).begin(), (v).end() #define sz(v) ((int)((v).size())) typedef long long ll; typedef pair<int, int> ii; const int MAXN = 305; const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0}; int n, m, diagCount; int d1[2 * MAXN][2 * MAXN]; int d2[2 * MAXN][2 * MAXN]; int p1[2 * MAXN][2 * MAXN]; int p2[2 * MAXN][2 * MAXN]; char a[MAXN][MAXN]; inline bool ok(int x, int y) { return (0 <= x && x < n) && (0 <= y && y < m); } inline void makePrefixSum(int *arr) { for (int i = 1; i < diagCount; i++) { arr[i] += arr[i - 1]; } } inline int prefSum(int *p, int a, int b, int dist) { if (a > b) { int t = a; a = b; b = t; } if (b >= diagCount) { b = diagCount - 1; } if (a < 0) { a = 0; } b -= dist; if (a > b) return 0; int res = p[b]; if (a > 0) res -= p[a - 1]; return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed); cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i]; } diagCount = n + m - 1; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i][j] == '#') { int z1 = i + j; int z2 = i + (m - j - 1); d1[z1][z2]++; d2[z2][z1]++; } } } ll ans = 0; for (int dist = 2; dist <= n + m - 2; dist += 2) { for (int z1 = 0; z1 < diagCount; z1++) { for (int z2 = 0; z2 < diagCount; z2++) { p1[z1][z2] = 0; p2[z1][z2] = 0; } } for (int z1 = 0; z1 < diagCount; z1++) { for (int z2 = 0; z2 < diagCount; z2++) { if (d1[z1][z2] == 1 && z2 + dist < diagCount && d1[z1][z2 + dist] == 1) { p1[z1][z2] = 1; } if (d2[z2][z1] == 1 && z1 + dist < diagCount && d2[z2][z1 + dist] == 1) { p2[z2][z1] = 1; } } } for (int z = 0; z < diagCount; z++) makePrefixSum(p1[z]); for (int z = 0; z < diagCount; z++) makePrefixSum(p2[z]); ll curDistAns = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (a[i][j] == '#') { int cellAns = 0; for (int k = 0; k < 4; k++) { int xs = i + dist * dx[k]; int ys = j + dist * dy[k]; int xf = i + dist * dx[(k + 1) & 3]; int yf = j + dist * dy[(k + 1) & 3]; int z1s = xs + ys; int z2s = xs + (m - ys - 1); int z1f = xf + yf; int z2f = xf + (m - yf - 1); if (z1s == z1f) { if (0 <= z1s && z1s < diagCount) { int add = prefSum(p1[z1s], z2s, z2f, dist); cellAns += add; } } else if (z2s == z2f) { if (0 <= z2s && z2s < diagCount) { int add = prefSum(p2[z2s], z1s, z1f, dist); cellAns += add; } } else { throw 0; } int xm = (xs + xf) / 2; int ym = (ys + yf) / 2; if (ok(xs, ys) && ok(xm, ym)) { if (a[xs][ys] == '#' && a[xm][ym] == '#') { cellAns--; } } } curDistAns += cellAns; } } } ans += curDistAns; } cout << ans << endl; }
replace
0
1
0
3
TLE
p03225
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; vector<string> rotate(int h, int w, vector<string> &grid) { vector<string> ngrid(w); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ngrid[w - 1 - j].push_back(grid[i][j]); } } return ngrid; } /** .............. # ....... . . . # **/ const int maxn = 620; char G[maxn][maxn]; int line_by_d[maxn][maxn], rows[maxn][maxn], cols[maxn][maxn]; int get_in_rows(int row, int x, int y) { if (x > y) return 0; int sum = rows[row][y]; if (x) sum -= rows[row][x - 1]; return sum; } int get_in_cols(int col, int x, int y) { if (x > y) return 0; int sum = cols[col][y]; if (x) sum -= cols[col][x - 1]; return sum; } int get_in_d(int row, int x, int y) { if (x > y) return 0; int sum = line_by_d[row][y]; if (x) sum -= line_by_d[row][x - 1]; return sum; } int solve(int h, int w, vector<string> &grid) { memset(G, '.', sizeof(G)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (grid[i][j] == '#') { G[i - j + w - 1][i + j] = '#'; } } } int n = h + w - 1; int ans = 0; int l = 2 * n / 3; for (int i = 0; i < n; i++) { rows[i][0] = G[i][0] == '#'; cols[i][0] = G[0][i] == '#'; for (int j = 1; j < n; j++) { rows[i][j] = G[i][j] == '#'; cols[i][j] = G[j][i] == '#'; rows[i][j] += rows[i][j - 1]; cols[i][j] += cols[i][j - 1]; } } int md2 = (w - 1) % 2; for (int d = 1; d <= l; d++) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { line_by_d[i][j] = 0; } for (int j = 0; j + d < n; j++) { line_by_d[i][j] = G[i][j] == '#' && G[i][j + d] == '#'; } for (int j = 1; j < n; j++) { line_by_d[i][j] += line_by_d[i][j - 1]; } } for (int i = d; i < n; i++) { int from = 0; if ((i + from) % 2 != md2) from++; for (int j = from; j < n; j += 2) { if (G[i][j] == '#') { int nans = 0; nans += get_in_d(i - d, max(j - d + 1, 0), j - 1); if (G[i - d][j] == '#' && j - d >= 0) { nans += get_in_cols(j - d, i - d + 1, i - 1); } if (j - d >= 0 && G[i][j - d] == '#') { nans += get_in_rows(i - d, j - d + 1, j - 1); } if (G[i - d][j] == '#' && j - d >= 0 && G[i][j - d] == '#') { nans += 1; } if (G[i - d][j] == '#' && j - d >= 0 && G[i - d][j - d] == '#') { nans += 1; } if (j - d >= 0 && G[i][j - d] == '#' && G[i - d][j - d] == '#') { nans += 1; } ans += nans; } } } } return ans; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); int h, w; cin >> h >> w; vector<string> grid(h); for (int i = 0; i < h; i++) cin >> grid[i]; long long ans = 0; for (int i = 0; i < 4; i++) { grid = rotate(h, w, grid); swap(h, w); ans += solve(h, w, grid); } cout << ans / 3 << endl; return 0; }
#include <bits/stdc++.h> using namespace std; vector<string> rotate(int h, int w, vector<string> &grid) { vector<string> ngrid(w); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { ngrid[w - 1 - j].push_back(grid[i][j]); } } return ngrid; } /** .............. # ....... . . . # **/ const int maxn = 620; char G[maxn][maxn]; int line_by_d[maxn][maxn], rows[maxn][maxn], cols[maxn][maxn]; int get_in_rows(int row, int x, int y) { if (x > y) return 0; int sum = rows[row][y]; if (x) sum -= rows[row][x - 1]; return sum; } int get_in_cols(int col, int x, int y) { if (x > y) return 0; int sum = cols[col][y]; if (x) sum -= cols[col][x - 1]; return sum; } int get_in_d(int row, int x, int y) { if (x > y) return 0; int sum = line_by_d[row][y]; if (x) sum -= line_by_d[row][x - 1]; return sum; } int solve(int h, int w, vector<string> &grid) { memset(G, '.', sizeof(G)); for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { if (grid[i][j] == '#') { G[i - j + w - 1][i + j] = '#'; } } } int n = h + w - 1; int ans = 0; int l = 2 * n / 3; for (int i = 0; i < n; i++) { rows[i][0] = G[i][0] == '#'; cols[i][0] = G[0][i] == '#'; for (int j = 1; j < n; j++) { rows[i][j] = G[i][j] == '#'; cols[i][j] = G[j][i] == '#'; rows[i][j] += rows[i][j - 1]; cols[i][j] += cols[i][j - 1]; } } int md2 = (w - 1) % 2; for (int d = 2; d <= l; d += 2) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { line_by_d[i][j] = 0; } for (int j = 0; j + d < n; j++) { line_by_d[i][j] = G[i][j] == '#' && G[i][j + d] == '#'; } for (int j = 1; j < n; j++) { line_by_d[i][j] += line_by_d[i][j - 1]; } } for (int i = d; i < n; i++) { int from = 0; if ((i + from) % 2 != md2) from++; for (int j = from; j < n; j += 2) { if (G[i][j] == '#') { int nans = 0; nans += get_in_d(i - d, max(j - d + 1, 0), j - 1); if (G[i - d][j] == '#' && j - d >= 0) { nans += get_in_cols(j - d, i - d + 1, i - 1); } if (j - d >= 0 && G[i][j - d] == '#') { nans += get_in_rows(i - d, j - d + 1, j - 1); } if (G[i - d][j] == '#' && j - d >= 0 && G[i][j - d] == '#') { nans += 1; } if (G[i - d][j] == '#' && j - d >= 0 && G[i - d][j - d] == '#') { nans += 1; } if (j - d >= 0 && G[i][j - d] == '#' && G[i - d][j - d] == '#') { nans += 1; } ans += nans; } } } } return ans; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); int h, w; cin >> h >> w; vector<string> grid(h); for (int i = 0; i < h; i++) cin >> grid[i]; long long ans = 0; for (int i = 0; i < 4; i++) { grid = rotate(h, w, grid); swap(h, w); ans += solve(h, w, grid); } cout << ans / 3 << endl; return 0; }
replace
72
73
72
73
TLE
p03225
C++
Runtime Error
/* :> */ #pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; random_device(rd); mt19937 rng(rd()); const long long FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); struct custom_hash { template <class T> unsigned long long operator()(T v) const { unsigned long long x = v; x += FIXED_RANDOM; x += 11400714819323198485ull; x = (x ^ (x >> 30)) * 13787848793156543929ull; x = (x ^ (x >> 27)) * 10723151780598845931ull; return x ^ (x >> 31); } }; template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <class T, class U> using hash_table = gp_hash_table<T, U, custom_hash>; template <class T> void readi(T &x) { x = 0; bool negative = false; char c = ' '; while (c < '-') { c = getchar(); } if (c == '-') { negative = true; c = getchar(); } while (c >= '0') { x = x * 10 + (c - '0'); c = getchar(); } if (negative) { x = -x; } } template <class T> void printi(T output) { if (output == 0) { putchar('0'); return; } if (output < 0) { putchar('-'); output = -output; } int buf[20], n = 0; while (output) { buf[n] = ((output % 10)); output /= 10; n++; } for (n--; n >= 0; n--) { putchar(buf[n] + '0'); } return; } template <class T> void ckmin(T &a, T b) { a = min(a, b); } template <class T> void ckmax(T &a, T b) { a = max(a, b); } long long expo(long long a, long long e, long long mod) { return ((e == 0) ? 1 : ((expo(a * a % mod, e >> 1, mod)) * ((e & 1) ? a : 1) % mod)); } template <class T, class U> T nmod(T &x, U mod) { if (x >= mod) x -= mod; } template <class T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); } template <class T> T randomize(T mod) { return (uniform_int_distribution<T>(0, mod - 1))(rng); } #define y0 ___y0 #define y1 ___y1 #define MP make_pair #define MT make_tuple #define PB push_back #define PF push_front #define fi first #define se second #define debug(x) cerr << #x << " = " << x << endl; #define sz(x) ((int)(x.size())) const long double PI = 4.0 * atan(1.0); const long double EPS = 1e-9; #define MAGIC 347 #define SINF 10007 #define CO 1000007 #define INF 1000000007 #define BIG 1000000931 #define LARGE 1696969696967ll #define GIANT 2564008813937411ll #define LLINF 2696969696969696969ll #define MAXN 613 typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ld, ld> pdd; int N, M; bitset<MAXN> grid[MAXN]; int ans; int vsum[MAXN][MAXN], hsum[MAXN][MAXN]; bool chk(int x, int y) { return (0 <= x && x < N && 0 <= y && y < N && grid[x][y]); } int vertsum(int y, int l, int r) { if (l > r || l >= N || r < 0) return 0; ckmax(y, 0); ckmin(y, N - 1); ckmax(l, 0); ckmin(l, N - 1); ckmax(r, 0); ckmin(r, N - 1); return vsum[r + 1][y] - vsum[l][y]; } int horzsum(int x, int l, int r) { if (l > r || l >= N || r < 0) return 0; ckmax(x, 0); ckmin(x, N - 1); ckmax(l, 0); ckmin(l, N - 1); ckmax(r, 0); ckmin(r, N - 1); return hsum[x][r + 1] - hsum[x][l]; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); // cout << fixed << setprecision(10); // cerr << fixed << setprecision(10); // freopen ("file.in", "r", stdin); // freopen ("file.out", "w", stdout); cin >> N >> M; for (int i = 0; i < N; i++) { string temps; cin >> temps; for (int j = 0; j < M; j++) { grid[i + j][i - j + M - 1] = (bool)(temps[j] == '#'); } } N = N + M - 1; // for (int i = 0; i < N; i++) // { // for (int j = 0; j < N; j++) // { // cerr << grid[i][j]; // } // cerr << endl; // } for (int k = 2; k <= N; k += 2) { for (int i = 0; i <= N; i++) { for (int j = 0; j <= N; j++) { vsum[i][j] = 0; hsum[i][j] = 0; } } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { vsum[i + 1][j] = vsum[i][j] + (bool)(grid[i][j] & grid[i + k][j]); hsum[i][j + 1] = hsum[i][j] + (bool)(grid[i][j] & grid[i][j + k]); } } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (!grid[i][j]) continue; ans += horzsum(i - k, j - k, j - 1); ans += horzsum(i + k, j - k + 1, j); ans += vertsum(j - k, i - k + 1, i); ans += vertsum(j + k, i - k, i - 1); } } } // we win! cout << ans << '\n'; // cerr << "time elapsed = " << (clock() / (CLOCKS_PER_SEC / 1000)) << " ms" // << endl; return 0; }
/* :> */ #pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/rope> using namespace std; using namespace __gnu_pbds; using namespace __gnu_cxx; random_device(rd); mt19937 rng(rd()); const long long FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); struct custom_hash { template <class T> unsigned long long operator()(T v) const { unsigned long long x = v; x += FIXED_RANDOM; x += 11400714819323198485ull; x = (x ^ (x >> 30)) * 13787848793156543929ull; x = (x ^ (x >> 27)) * 10723151780598845931ull; return x ^ (x >> 31); } }; template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <class T, class U> using hash_table = gp_hash_table<T, U, custom_hash>; template <class T> void readi(T &x) { x = 0; bool negative = false; char c = ' '; while (c < '-') { c = getchar(); } if (c == '-') { negative = true; c = getchar(); } while (c >= '0') { x = x * 10 + (c - '0'); c = getchar(); } if (negative) { x = -x; } } template <class T> void printi(T output) { if (output == 0) { putchar('0'); return; } if (output < 0) { putchar('-'); output = -output; } int buf[20], n = 0; while (output) { buf[n] = ((output % 10)); output /= 10; n++; } for (n--; n >= 0; n--) { putchar(buf[n] + '0'); } return; } template <class T> void ckmin(T &a, T b) { a = min(a, b); } template <class T> void ckmax(T &a, T b) { a = max(a, b); } long long expo(long long a, long long e, long long mod) { return ((e == 0) ? 1 : ((expo(a * a % mod, e >> 1, mod)) * ((e & 1) ? a : 1) % mod)); } template <class T, class U> T nmod(T &x, U mod) { if (x >= mod) x -= mod; } template <class T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); } template <class T> T randomize(T mod) { return (uniform_int_distribution<T>(0, mod - 1))(rng); } #define y0 ___y0 #define y1 ___y1 #define MP make_pair #define MT make_tuple #define PB push_back #define PF push_front #define fi first #define se second #define debug(x) cerr << #x << " = " << x << endl; #define sz(x) ((int)(x.size())) const long double PI = 4.0 * atan(1.0); const long double EPS = 1e-9; #define MAGIC 347 #define SINF 10007 #define CO 1000007 #define INF 1000000007 #define BIG 1000000931 #define LARGE 1696969696967ll #define GIANT 2564008813937411ll #define LLINF 2696969696969696969ll #define MAXN 1213 typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ld, ld> pdd; int N, M; bitset<MAXN> grid[MAXN]; int ans; int vsum[MAXN][MAXN], hsum[MAXN][MAXN]; bool chk(int x, int y) { return (0 <= x && x < N && 0 <= y && y < N && grid[x][y]); } int vertsum(int y, int l, int r) { if (l > r || l >= N || r < 0) return 0; ckmax(y, 0); ckmin(y, N - 1); ckmax(l, 0); ckmin(l, N - 1); ckmax(r, 0); ckmin(r, N - 1); return vsum[r + 1][y] - vsum[l][y]; } int horzsum(int x, int l, int r) { if (l > r || l >= N || r < 0) return 0; ckmax(x, 0); ckmin(x, N - 1); ckmax(l, 0); ckmin(l, N - 1); ckmax(r, 0); ckmin(r, N - 1); return hsum[x][r + 1] - hsum[x][l]; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); // cout << fixed << setprecision(10); // cerr << fixed << setprecision(10); // freopen ("file.in", "r", stdin); // freopen ("file.out", "w", stdout); cin >> N >> M; for (int i = 0; i < N; i++) { string temps; cin >> temps; for (int j = 0; j < M; j++) { grid[i + j][i - j + M - 1] = (bool)(temps[j] == '#'); } } N = N + M - 1; // for (int i = 0; i < N; i++) // { // for (int j = 0; j < N; j++) // { // cerr << grid[i][j]; // } // cerr << endl; // } for (int k = 2; k <= N; k += 2) { for (int i = 0; i <= N; i++) { for (int j = 0; j <= N; j++) { vsum[i][j] = 0; hsum[i][j] = 0; } } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { vsum[i + 1][j] = vsum[i][j] + (bool)(grid[i][j] & grid[i + k][j]); hsum[i][j + 1] = hsum[i][j] + (bool)(grid[i][j] & grid[i][j + k]); } } for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (!grid[i][j]) continue; ans += horzsum(i - k, j - k, j - 1); ans += horzsum(i + k, j - k + 1, j); ans += vertsum(j - k, i - k + 1, i); ans += vertsum(j + k, i - k, i - 1); } } } // we win! cout << ans << '\n'; // cerr << "time elapsed = " << (clock() / (CLOCKS_PER_SEC / 1000)) << " ms" // << endl; return 0; }
replace
112
113
112
113
0
p03225
C++
Runtime Error
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define NMAX 310 #define BMAX (NMAX * 3 + 6) typedef long long i64; static int n, m; static char map[NMAX + 10][NMAX + 10]; static int pre[3 * NMAX + 10][3 * NMAX + 10]; #define S(i, j) pre[NMAX + (i)][NMAX + (j)] void show() { for (int i = 1; i <= n; i++) printf("%s\n", map[i] + 1); puts(""); } void rotate() { static char buf[NMAX + 10][NMAX + 10]; memcpy(buf, map, sizeof(buf)); memset(map, 0, sizeof(map)); for (int i = 1; i <= m; i++) for (int j = 1; j <= n; j++) map[i][j] = buf[n - j + 1][i]; swap(n, m); // show(); } i64 eval() { memset(pre, 0, sizeof(pre)); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) S(i, j) = map[i][j] == '#'; for (int i = 0; i <= BMAX; i++) for (int j = 1; i >= j; j++) pre[i - j][j] += pre[i - j + 1][j - 1]; i64 r = 0; for (int i = 1; i <= n + m; i++) for (int j = 0; i - j >= 1; j++) if (map[i - j][j + 1] == '#') for (int k = j + 1; i - k >= 1; k++) if (map[i - k][k + 1] == '#') { int d = (k - j) << 1; r += S(i - j - d, j + 1) - S(i - k, k - d + 1); } return r; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%s", map[i] + 1); i64 ans = eval(); rotate(); ans += eval(); rotate(); ans += eval(); rotate(); ans += eval(); printf("%lld\n", ans); return 0; }
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define NMAX 600 #define BMAX (NMAX * 3 + 6) typedef long long i64; static int n, m; static char map[NMAX + 10][NMAX + 10]; static int pre[3 * NMAX + 10][3 * NMAX + 10]; #define S(i, j) pre[NMAX + (i)][NMAX + (j)] void show() { for (int i = 1; i <= n; i++) printf("%s\n", map[i] + 1); puts(""); } void rotate() { static char buf[NMAX + 10][NMAX + 10]; memcpy(buf, map, sizeof(buf)); memset(map, 0, sizeof(map)); for (int i = 1; i <= m; i++) for (int j = 1; j <= n; j++) map[i][j] = buf[n - j + 1][i]; swap(n, m); // show(); } i64 eval() { memset(pre, 0, sizeof(pre)); for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) S(i, j) = map[i][j] == '#'; for (int i = 0; i <= BMAX; i++) for (int j = 1; i >= j; j++) pre[i - j][j] += pre[i - j + 1][j - 1]; i64 r = 0; for (int i = 1; i <= n + m; i++) for (int j = 0; i - j >= 1; j++) if (map[i - j][j + 1] == '#') for (int k = j + 1; i - k >= 1; k++) if (map[i - k][k + 1] == '#') { int d = (k - j) << 1; r += S(i - j - d, j + 1) - S(i - k, k - d + 1); } return r; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%s", map[i] + 1); i64 ans = eval(); rotate(); ans += eval(); rotate(); ans += eval(); rotate(); ans += eval(); printf("%lld\n", ans); return 0; }
replace
7
8
7
8
0
p03225
C++
Runtime Error
#include <bits/stdc++.h> #include <sys/time.h> using namespace std; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) #define repi(i, a, b) \ for (long long i = (long long)(a); i < (long long)(b); i++) #define pb push_back #define all(x) (x).begin(), (x).end() #define fi first #define se second #define mt make_tuple #define mp make_pair template <class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); } template <class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>; ll ugauss(ll a, ll b) { if (!a) return 0; if (a > 0 ^ b > 0) return a / b; else return (a + (a > 0 ? -1 : 1)) / b + 1; } ll lgauss(ll a, ll b) { if (!a) return 0; if (a > 0 ^ b > 0) return (a + (a > 0 ? -1 : 1)) / b - 1; else return a / b; } template <typename T, typename U> ostream &operator<<(ostream &o, const pair<T, U> &v) { o << "(" << v.first << ", " << v.second << ")"; return o; } template <size_t...> struct seq {}; template <size_t N, size_t... Is> struct gen_seq : gen_seq<N - 1, N - 1, Is...> {}; template <size_t... Is> struct gen_seq<0, Is...> : seq<Is...> {}; template <class Ch, class Tr, class Tuple, size_t... Is> void print_tuple(basic_ostream<Ch, Tr> &os, Tuple const &t, seq<Is...>) { using s = int[]; (void)s{0, (void(os << (Is == 0 ? "" : ", ") << get<Is>(t)), 0)...}; } template <class Ch, class Tr, class... Args> auto operator<<(basic_ostream<Ch, Tr> &os, tuple<Args...> const &t) -> basic_ostream<Ch, Tr> & { os << "("; print_tuple(os, t, gen_seq<sizeof...(Args)>()); return os << ")"; } ostream &operator<<(ostream &o, const vvll &v) { rep(i, v.size()) { rep(j, v[i].size()) o << v[i][j] << " "; o << endl; } return o; } template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '['; rep(i, v.size()) o << v[i] << (i != v.size() - 1 ? ", " : ""); o << "]"; return o; } template <typename T> ostream &operator<<(ostream &o, const deque<T> &v) { o << '['; rep(i, v.size()) o << v[i] << (i != v.size() - 1 ? ", " : ""); o << "]"; return o; } template <typename T> ostream &operator<<(ostream &o, const set<T> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]"; return o; } template <typename T> ostream &operator<<(ostream &o, const unordered_set<T> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]"; return o; } template <typename T, typename U> ostream &operator<<(ostream &o, const map<T, U> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]"; return o; } template <typename T, typename U, typename V> ostream &operator<<(ostream &o, const unordered_map<T, U, V> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it; o << "]"; return o; } vector<int> range(const int x, const int y) { vector<int> v(y - x + 1); iota(v.begin(), v.end(), x); return v; } template <typename T> istream &operator>>(istream &i, vector<T> &o) { rep(j, o.size()) i >> o[j]; return i; } template <typename T, typename S, typename U> ostream &operator<<(ostream &o, const priority_queue<T, S, U> &v) { auto tmp = v; while (tmp.size()) { auto x = tmp.top(); tmp.pop(); o << x << " "; } return o; } template <typename T> ostream &operator<<(ostream &o, const queue<T> &v) { auto tmp = v; while (tmp.size()) { auto x = tmp.front(); tmp.pop(); o << x << " "; } return o; } template <typename T> ostream &operator<<(ostream &o, const stack<T> &v) { auto tmp = v; while (tmp.size()) { auto x = tmp.top(); tmp.pop(); o << x << " "; } return o; } template <typename T> unordered_map<T, ll> counter(vector<T> vec) { unordered_map<T, ll> ret; for (auto &&x : vec) ret[x]++; return ret; }; void vizGraph(vvll &g, int mode = 0, string filename = "out.png") { ofstream ofs("./out.dot"); ofs << "digraph graph_name {" << endl; set<P> memo; rep(i, g.size()) rep(j, g[i].size()) { if (mode && (memo.count(P(i, g[i][j])) || memo.count(P(g[i][j], i)))) continue; memo.insert(P(i, g[i][j])); ofs << " " << i << " -> " << g[i][j] << (mode ? " [arrowhead = none]" : "") << endl; } ofs << "}" << endl; ofs.close(); system(((string) "dot -T png out.dot >" + filename).c_str()); } struct timeval start; double sec() { struct timeval tv; gettimeofday(&tv, NULL); return (tv.tv_sec - start.tv_sec) + (tv.tv_usec - start.tv_usec) * 1e-6; } size_t random_seed; struct init_ { init_() { ios::sync_with_stdio(false); cin.tie(0); gettimeofday(&start, NULL); struct timeval myTime; struct tm *time_st; gettimeofday(&myTime, NULL); time_st = localtime(&myTime.tv_sec); srand(myTime.tv_usec); random_seed = RAND_MAX / 2 + rand() / 2; } } init__; #define ldout fixed << setprecision(40) #define EPS (double)1e-14 #define INF (ll)1e18 #define mo (ll)(1e9 + 7) P c(P x) { return P((x.fi + x.se) / 2ll, (x.fi - x.se) / 2ll); } const ll o = 800; int16_t jsum[2 * o][2 * o]; ll count(vector<P> p, bool strict = false) { map<ll, vll> memo; for (auto x : p) { ll i = x.fi; ll j = x.se; memo[i].pb(j); } for (auto &x : memo) { sort(all(x.se)); } rep(i, 2 * o) rep(j, 2 * o) jsum[i][j] = 0; for (auto &x : p) { jsum[x.fi + o][x.se + o + 1]++; } rep(i, 2 * o) { rep(j, 2 * o - 1) { jsum[i][j + 1] += jsum[i][j]; } } ll ret = 0; for (auto &x : memo) { ll i = x.fi; auto &q = x.se; rep(j1, q.size()) repi(j2, j1 + 1, q.size()) { ll l = abs(q[j1] - q[j2]); if (strict) { ret += jsum[i + l + o][q[j1] + o + 1] - jsum[i + l + o][q[j1] + o]; ret += jsum[i + l + o][q[j2] + o + 1] - jsum[i + l + o][q[j2] + o]; ret += jsum[i - l + o][q[j1] + o + 1] - jsum[i - l + o][q[j1] + o]; ret += jsum[i - l + o][q[j2] + o + 1] - jsum[i - l + o][q[j2] + o]; } else { ret += jsum[i + l + o][q[j2] + o + 1] - jsum[i + l + o][q[j1] + o]; ret += jsum[i - l + o][q[j2] + o + 1] - jsum[i - l + o][q[j1] + o]; } /* ll tmp = 0; // (i+l, [q[j1], q[j2]])に含まれる点の数 for (auto j_plus : memo[i + l]) { if (!(q[j1] <= j_plus && j_plus <= q[j2])) continue; if (strict && q[j1] < j_plus && j_plus < q[j2]) continue; ret++; tmp++; } if (!strict) { cout << tmp << " " << jsum[i+l+o][q[j2]+o+1] - jsum[i+l+o][q[j1]+o] << endl; } */ /* for (auto j_minus : memo[i - l]) if (q[j1] <= j_minus && j_minus <= q[j2]) { if (!(q[j1] <= j_minus && j_minus <= q[j2])) continue; if (strict && q[j1] < j_minus && j_minus < q[j2]) continue; ret++; } */ } } // cout << ret << endl; return ret; } ll countAll(vector<P> p) { ll ret1 = count(p); // cout << ret1 << endl; rep(i, p.size()) { ll x = p[i].fi; ll y = p[i].se; p[i] = P(y, -x); } ll ret2 = count(p); // cout << ret2 << endl; ll ret3 = count(p, true); // cout << ret3 << endl; // cout << ret1 + ret2 - ret3 << endl; return ret1 + ret2 - ret3; } bool isOK(P a, P b, P c) { ll ab = max(abs(a.fi - b.fi), abs(a.se - b.se)); ll bc = max(abs(b.fi - c.fi), abs(b.se - c.se)); ll ca = max(abs(c.fi - a.fi), abs(c.se - a.se)); // cout << a<<" " << b << " "<< c<<mt(ab,bc,ca)<<endl; return ab == bc && bc == ca; } ll countBrutal(vector<P> p) { ll n = p.size(); ll ret = 0; rep(i, n) repi(j, i + 1, n) repi(h, j + 1, n) { ret += isOK(p[i], p[j], p[h]); } return ret; } int main(void) { ll h, w; cin >> h >> w; vector<string> b(h); rep(i, h) cin >> b[i]; vector<P> p; rep(i, h) rep(j, w) if (b[i][j] == '#') { p.pb(P(i + j, i - j)); } // cout << p << endl; cout << countAll(p) << endl; // cout << countBrutal(p) << endl; /* if (countBrutal(p) != countAll(p)) { cout <<"HIT!" << endl; } */ return 0; }
#include <bits/stdc++.h> #include <sys/time.h> using namespace std; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) #define repi(i, a, b) \ for (long long i = (long long)(a); i < (long long)(b); i++) #define pb push_back #define all(x) (x).begin(), (x).end() #define fi first #define se second #define mt make_tuple #define mp make_pair template <class T1, class T2> bool chmin(T1 &a, T2 b) { return b < a && (a = b, true); } template <class T1, class T2> bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); } using ll = long long; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>; ll ugauss(ll a, ll b) { if (!a) return 0; if (a > 0 ^ b > 0) return a / b; else return (a + (a > 0 ? -1 : 1)) / b + 1; } ll lgauss(ll a, ll b) { if (!a) return 0; if (a > 0 ^ b > 0) return (a + (a > 0 ? -1 : 1)) / b - 1; else return a / b; } template <typename T, typename U> ostream &operator<<(ostream &o, const pair<T, U> &v) { o << "(" << v.first << ", " << v.second << ")"; return o; } template <size_t...> struct seq {}; template <size_t N, size_t... Is> struct gen_seq : gen_seq<N - 1, N - 1, Is...> {}; template <size_t... Is> struct gen_seq<0, Is...> : seq<Is...> {}; template <class Ch, class Tr, class Tuple, size_t... Is> void print_tuple(basic_ostream<Ch, Tr> &os, Tuple const &t, seq<Is...>) { using s = int[]; (void)s{0, (void(os << (Is == 0 ? "" : ", ") << get<Is>(t)), 0)...}; } template <class Ch, class Tr, class... Args> auto operator<<(basic_ostream<Ch, Tr> &os, tuple<Args...> const &t) -> basic_ostream<Ch, Tr> & { os << "("; print_tuple(os, t, gen_seq<sizeof...(Args)>()); return os << ")"; } ostream &operator<<(ostream &o, const vvll &v) { rep(i, v.size()) { rep(j, v[i].size()) o << v[i][j] << " "; o << endl; } return o; } template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << '['; rep(i, v.size()) o << v[i] << (i != v.size() - 1 ? ", " : ""); o << "]"; return o; } template <typename T> ostream &operator<<(ostream &o, const deque<T> &v) { o << '['; rep(i, v.size()) o << v[i] << (i != v.size() - 1 ? ", " : ""); o << "]"; return o; } template <typename T> ostream &operator<<(ostream &o, const set<T> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]"; return o; } template <typename T> ostream &operator<<(ostream &o, const unordered_set<T> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]"; return o; } template <typename T, typename U> ostream &operator<<(ostream &o, const map<T, U> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it << (next(it) != m.end() ? ", " : ""); o << "]"; return o; } template <typename T, typename U, typename V> ostream &operator<<(ostream &o, const unordered_map<T, U, V> &m) { o << '['; for (auto it = m.begin(); it != m.end(); it++) o << *it; o << "]"; return o; } vector<int> range(const int x, const int y) { vector<int> v(y - x + 1); iota(v.begin(), v.end(), x); return v; } template <typename T> istream &operator>>(istream &i, vector<T> &o) { rep(j, o.size()) i >> o[j]; return i; } template <typename T, typename S, typename U> ostream &operator<<(ostream &o, const priority_queue<T, S, U> &v) { auto tmp = v; while (tmp.size()) { auto x = tmp.top(); tmp.pop(); o << x << " "; } return o; } template <typename T> ostream &operator<<(ostream &o, const queue<T> &v) { auto tmp = v; while (tmp.size()) { auto x = tmp.front(); tmp.pop(); o << x << " "; } return o; } template <typename T> ostream &operator<<(ostream &o, const stack<T> &v) { auto tmp = v; while (tmp.size()) { auto x = tmp.top(); tmp.pop(); o << x << " "; } return o; } template <typename T> unordered_map<T, ll> counter(vector<T> vec) { unordered_map<T, ll> ret; for (auto &&x : vec) ret[x]++; return ret; }; void vizGraph(vvll &g, int mode = 0, string filename = "out.png") { ofstream ofs("./out.dot"); ofs << "digraph graph_name {" << endl; set<P> memo; rep(i, g.size()) rep(j, g[i].size()) { if (mode && (memo.count(P(i, g[i][j])) || memo.count(P(g[i][j], i)))) continue; memo.insert(P(i, g[i][j])); ofs << " " << i << " -> " << g[i][j] << (mode ? " [arrowhead = none]" : "") << endl; } ofs << "}" << endl; ofs.close(); system(((string) "dot -T png out.dot >" + filename).c_str()); } struct timeval start; double sec() { struct timeval tv; gettimeofday(&tv, NULL); return (tv.tv_sec - start.tv_sec) + (tv.tv_usec - start.tv_usec) * 1e-6; } size_t random_seed; struct init_ { init_() { ios::sync_with_stdio(false); cin.tie(0); gettimeofday(&start, NULL); struct timeval myTime; struct tm *time_st; gettimeofday(&myTime, NULL); time_st = localtime(&myTime.tv_sec); srand(myTime.tv_usec); random_seed = RAND_MAX / 2 + rand() / 2; } } init__; #define ldout fixed << setprecision(40) #define EPS (double)1e-14 #define INF (ll)1e18 #define mo (ll)(1e9 + 7) P c(P x) { return P((x.fi + x.se) / 2ll, (x.fi - x.se) / 2ll); } const ll o = 1500; int16_t jsum[2 * o][2 * o]; ll count(vector<P> p, bool strict = false) { map<ll, vll> memo; for (auto x : p) { ll i = x.fi; ll j = x.se; memo[i].pb(j); } for (auto &x : memo) { sort(all(x.se)); } rep(i, 2 * o) rep(j, 2 * o) jsum[i][j] = 0; for (auto &x : p) { jsum[x.fi + o][x.se + o + 1]++; } rep(i, 2 * o) { rep(j, 2 * o - 1) { jsum[i][j + 1] += jsum[i][j]; } } ll ret = 0; for (auto &x : memo) { ll i = x.fi; auto &q = x.se; rep(j1, q.size()) repi(j2, j1 + 1, q.size()) { ll l = abs(q[j1] - q[j2]); if (strict) { ret += jsum[i + l + o][q[j1] + o + 1] - jsum[i + l + o][q[j1] + o]; ret += jsum[i + l + o][q[j2] + o + 1] - jsum[i + l + o][q[j2] + o]; ret += jsum[i - l + o][q[j1] + o + 1] - jsum[i - l + o][q[j1] + o]; ret += jsum[i - l + o][q[j2] + o + 1] - jsum[i - l + o][q[j2] + o]; } else { ret += jsum[i + l + o][q[j2] + o + 1] - jsum[i + l + o][q[j1] + o]; ret += jsum[i - l + o][q[j2] + o + 1] - jsum[i - l + o][q[j1] + o]; } /* ll tmp = 0; // (i+l, [q[j1], q[j2]])に含まれる点の数 for (auto j_plus : memo[i + l]) { if (!(q[j1] <= j_plus && j_plus <= q[j2])) continue; if (strict && q[j1] < j_plus && j_plus < q[j2]) continue; ret++; tmp++; } if (!strict) { cout << tmp << " " << jsum[i+l+o][q[j2]+o+1] - jsum[i+l+o][q[j1]+o] << endl; } */ /* for (auto j_minus : memo[i - l]) if (q[j1] <= j_minus && j_minus <= q[j2]) { if (!(q[j1] <= j_minus && j_minus <= q[j2])) continue; if (strict && q[j1] < j_minus && j_minus < q[j2]) continue; ret++; } */ } } // cout << ret << endl; return ret; } ll countAll(vector<P> p) { ll ret1 = count(p); // cout << ret1 << endl; rep(i, p.size()) { ll x = p[i].fi; ll y = p[i].se; p[i] = P(y, -x); } ll ret2 = count(p); // cout << ret2 << endl; ll ret3 = count(p, true); // cout << ret3 << endl; // cout << ret1 + ret2 - ret3 << endl; return ret1 + ret2 - ret3; } bool isOK(P a, P b, P c) { ll ab = max(abs(a.fi - b.fi), abs(a.se - b.se)); ll bc = max(abs(b.fi - c.fi), abs(b.se - c.se)); ll ca = max(abs(c.fi - a.fi), abs(c.se - a.se)); // cout << a<<" " << b << " "<< c<<mt(ab,bc,ca)<<endl; return ab == bc && bc == ca; } ll countBrutal(vector<P> p) { ll n = p.size(); ll ret = 0; rep(i, n) repi(j, i + 1, n) repi(h, j + 1, n) { ret += isOK(p[i], p[j], p[h]); } return ret; } int main(void) { ll h, w; cin >> h >> w; vector<string> b(h); rep(i, h) cin >> b[i]; vector<P> p; rep(i, h) rep(j, w) if (b[i][j] == '#') { p.pb(P(i + j, i - j)); } // cout << p << endl; cout << countAll(p) << endl; // cout << countBrutal(p) << endl; /* if (countBrutal(p) != countAll(p)) { cout <<"HIT!" << endl; } */ return 0; }
replace
196
197
196
197
0
p03225
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long LL; char s[200][200]; int pre1[3000][3000] = {0}, pre2[3000][3000] = {0}; const int shift = 1000; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; auto inside = [](int x, int n) { return x >= 0 and x < n; }; for (int i = 0; i < n; ++i) cin >> s[i]; for (int i = 0; i + 1 < 3000; ++i) for (int j = 0; j + 1 < 3000; ++j) { pre1[i + 1][j + 1] = pre1[i][j] + (inside(i - shift, n) and inside(j - shift, m) ? s[i - shift][j - shift] == '#' : 0); } for (int i = 0; i + 1 < 3000; ++i) for (int j = 1; j < 3000; ++j) { pre2[i + 1][j - 1] = pre2[i][j] + (inside(i - shift, n) and inside(j - shift, m) ? s[i - shift][j - shift] == '#' : 0); } LL diag = 0; auto S = [&](int i, int j) { i -= shift, j -= shift; if (inside(i, n) and inside(j, m)) return int(s[i][j] == '#'); else return 0; }; auto go1 = [&](int i, int j, int d) { i += shift, j += shift; diag += S(i, j + 2 * d) + S(i - d, j + d) + S(i + 2 * d, j) + S(i + d, j - d); return pre1[i + 1][j + 2 * d + 1] - pre1[i - d][j + d] + pre1[i + 2 * d + 1][j + 1] - pre1[i + d][j - d]; }; auto go2 = [&](int i, int j, int d) { i += shift, j += shift; diag += S(i + 2 * d, j) + S(i + d, j + d) + S(i, j - 2 * d) + S(i - d, j - d); return pre2[i + 2 * d + 1][j - 1] - pre2[i + d][j + d] + pre2[i + 1][j - 2 * d - 1] - pre2[i - d][j - d]; }; LL ans = 0; for (int d = 1; d < 700; ++d) { for (int i = 0; i + d < n; ++i) { for (int j = 0; j + d < m; ++j) { if (s[i][j] == '#' and s[i + d][j + d] == '#') { ans += go1(i, j, d); } } } } for (int d = 1; d < 700; ++d) { for (int i = 0; i + d < n; ++i) { for (int j = m - 1; j - d >= 0; --j) { if (s[i][j] == '#' and s[i + d][j - d] == '#') { ans += go2(i, j, d); } } } } cout << ans - diag / 2 << '\n'; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; char s[500][500]; int pre1[3000][3000] = {0}, pre2[3000][3000] = {0}; const int shift = 1000; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; auto inside = [](int x, int n) { return x >= 0 and x < n; }; for (int i = 0; i < n; ++i) cin >> s[i]; for (int i = 0; i + 1 < 3000; ++i) for (int j = 0; j + 1 < 3000; ++j) { pre1[i + 1][j + 1] = pre1[i][j] + (inside(i - shift, n) and inside(j - shift, m) ? s[i - shift][j - shift] == '#' : 0); } for (int i = 0; i + 1 < 3000; ++i) for (int j = 1; j < 3000; ++j) { pre2[i + 1][j - 1] = pre2[i][j] + (inside(i - shift, n) and inside(j - shift, m) ? s[i - shift][j - shift] == '#' : 0); } LL diag = 0; auto S = [&](int i, int j) { i -= shift, j -= shift; if (inside(i, n) and inside(j, m)) return int(s[i][j] == '#'); else return 0; }; auto go1 = [&](int i, int j, int d) { i += shift, j += shift; diag += S(i, j + 2 * d) + S(i - d, j + d) + S(i + 2 * d, j) + S(i + d, j - d); return pre1[i + 1][j + 2 * d + 1] - pre1[i - d][j + d] + pre1[i + 2 * d + 1][j + 1] - pre1[i + d][j - d]; }; auto go2 = [&](int i, int j, int d) { i += shift, j += shift; diag += S(i + 2 * d, j) + S(i + d, j + d) + S(i, j - 2 * d) + S(i - d, j - d); return pre2[i + 2 * d + 1][j - 1] - pre2[i + d][j + d] + pre2[i + 1][j - 2 * d - 1] - pre2[i - d][j - d]; }; LL ans = 0; for (int d = 1; d < 700; ++d) { for (int i = 0; i + d < n; ++i) { for (int j = 0; j + d < m; ++j) { if (s[i][j] == '#' and s[i + d][j + d] == '#') { ans += go1(i, j, d); } } } } for (int d = 1; d < 700; ++d) { for (int i = 0; i + d < n; ++i) { for (int j = m - 1; j - d >= 0; --j) { if (s[i][j] == '#' and s[i + d][j - d] == '#') { ans += go2(i, j, d); } } } } cout << ans - diag / 2 << '\n'; }
replace
4
5
4
5
0
p03226
C++
Runtime Error
#include <bits/stdc++.h> typedef long long ll; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, a) FOR(i, 0, a) using namespace std; int N; const int MAX_N = 3e5; const ll MOD = 998244353; typedef pair<int, int> P; vector<P> org; int psm[MAX_N + 1]; int main() { cin >> N; REP(i, N) { int a; cin >> a; if (i == 0 || org.back().first != a) { org.push_back(P(a, 1)); } else { org.back().second++; } } ll ans = 1; if (org[0].second == N) { if (org[0].first != 1) { ans = 0; } else { ans = 1; } REP(i, N) { ans *= (i + 1); ans %= MOD; } } else { if (org[0].first == org.back().first) { org[0].second += org.back().second; org.pop_back(); } { set<int> st; for (auto p : org) { if (st.find(p.first) != st.end()) { ans = 0; goto BREAK; } st.insert(p.first); } } REP(i, (int)org.size()) { psm[i + 1] = psm[i] + org[i].second; } map<int, int> mp; { int cnt = 0; for (auto p : org) { mp[p.first] = cnt++; } } map<int, int> inx; int cap = 0, len; if (mp.find(1) != mp.end()) { inx[psm[mp[1]]] = 1; len = org[mp[1]].second; } else { ans = 0; len = 0; goto BREAK; } FOR(i, 2, N + 1) { if (mp.find(i) == mp.end()) { ans *= cap; ans %= MOD; cap--; } else { int j = mp[i]; if (!(0 <= j && j < (int)org.size())) { return 0; } if (org[j].second > len) { ans = 0; goto BREAK; } int prej; if (j > 0) { prej = j - 1; } else { prej = (int)org.size() - 1; } int nexj; if (j < (int)org.size() - 1) { nexj = j + 1; } else { nexj = 0; } if (!(0 <= prej && prej < (int)org.size())) { return 0; } if (!(0 <= nexj && nexj < (int)org.size())) { return 0; } int iinx; if (org[prej].first < i && org[nexj].first < i) { iinx = psm[j]; ans *= len - org[j].second + 1; ans %= MOD; } else if (org[prej].first < i) { iinx = psm[j] - (len - org[j].second); } else if (org[nexj].first < i) { iinx = psm[j]; } else { iinx = psm[j]; if (org[j].second != len) { ans = 0; goto BREAK; } } int gap; map<int, int>::iterator low, upp; upp = inx.upper_bound(iinx); if (upp == inx.end()) { upp = inx.begin(); gap = N - iinx - 1 + upp->first; } else { gap = upp->first - iinx - 1; } if (gap < len) { cap += gap; } if (upp == inx.begin()) { low = inx.end(); } low--; if (low->first < iinx) { gap = iinx - low->first - 1; } else { gap = iinx + N - low->first - 1; } if (gap < len) { cap += gap; } inx[iinx] = i; } } } BREAK: cout << ans << endl; return 0; }
#include <bits/stdc++.h> typedef long long ll; #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define REP(i, a) FOR(i, 0, a) using namespace std; int N; const int MAX_N = 3e5; const ll MOD = 998244353; typedef pair<int, int> P; vector<P> org; int psm[MAX_N + 1]; int main() { cin >> N; REP(i, N) { int a; cin >> a; if (i == 0 || org.back().first != a) { org.push_back(P(a, 1)); } else { org.back().second++; } } ll ans = 1; if (org[0].second == N) { if (org[0].first != 1) { ans = 0; } else { ans = 1; } REP(i, N) { ans *= (i + 1); ans %= MOD; } } else { if (org[0].first == org.back().first) { org[0].second += org.back().second; org.pop_back(); } { set<int> st; for (auto p : org) { if (st.find(p.first) != st.end()) { ans = 0; goto BREAK; } st.insert(p.first); } } REP(i, (int)org.size()) { psm[i + 1] = psm[i] + org[i].second; } map<int, int> mp; { int cnt = 0; for (auto p : org) { mp[p.first] = cnt++; } } map<int, int> inx; int cap = 0, len; if (mp.find(1) != mp.end()) { inx[psm[mp[1]]] = 1; len = org[mp[1]].second; } else { ans = 0; len = 0; goto BREAK; } FOR(i, 2, N + 1) { if (mp.find(i) == mp.end()) { ans *= cap; ans %= MOD; cap--; } else { int j = mp[i]; if (!(0 <= j && j < (int)org.size())) { return 0; } if (org[j].second > len) { ans = 0; goto BREAK; } int prej; if (j > 0) { prej = j - 1; } else { prej = (int)org.size() - 1; } int nexj; if (j < (int)org.size() - 1) { nexj = j + 1; } else { nexj = 0; } if (!(0 <= prej && prej < (int)org.size())) { return 0; } if (!(0 <= nexj && nexj < (int)org.size())) { return 0; } int iinx; if (org[prej].first < i && org[nexj].first < i) { iinx = psm[j]; ans *= len - org[j].second + 1; ans %= MOD; } else if (org[prej].first < i) { iinx = psm[j] - (len - org[j].second); } else if (org[nexj].first < i) { iinx = psm[j]; } else { iinx = psm[j]; if (org[j].second != len) { ans = 0; goto BREAK; } } int gap; map<int, int>::iterator low, upp; upp = inx.upper_bound(iinx); if (upp == inx.end()) { upp = inx.begin(); gap = N - iinx - 1 + upp->first; } else { gap = upp->first - iinx - 1; } if (gap < len) { cap += gap; } low = upp; if (upp == inx.begin()) { low = inx.end(); } low--; if (low->first < iinx) { gap = iinx - low->first - 1; } else { gap = iinx + N - low->first - 1; } if (gap < len) { cap += gap; } inx[iinx] = i; } } } BREAK: cout << ans << endl; return 0; }
insert
127
127
127
128
0
p03226
C++
Time Limit Exceeded
#include <bits/stdc++.h> // iostream is too mainstream #include <cstdio> // bitch please #include <algorithm> #include <cmath> #include <cstdlib> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <time.h> #include <vector> #define dibs reserve #define OVER9000 1234567890 #define ALL_THE(CAKE, LIE) \ for (auto LIE = CAKE.begin(); LIE != CAKE.end(); LIE++) #define tisic 47 #define soclose 1e-8 #define chocolate win // so much chocolate #define patkan 9 #define ff first #define ss second #define abs(x) (((x) < 0) ? -(x) : (x)) #define uint unsigned int #define dbl long double #define pi 3.14159265358979323846 using namespace std; // mylittledoge using cat = long long; #ifdef DONLINE_JUDGE // palindromic tree is better than splay tree! #define lld I64d #endif int get_min(vector<vector<int>> &RMQ, int l, int r) { int ret = OVER9000; for (int i = 0; i < 19; i++) if (((r - l) >> i) & 1) { ret = min(ret, RMQ[i][l]); l += 1 << i; if (l == r) break; } return ret; } int get_max(vector<vector<int>> &RMQ, int l, int r) { int ret = -1; for (int i = 0; i < 19; i++) if (((r - l) >> i) & 1) { ret = max(ret, RMQ[i][l]); l += 1 << i; if (l == r) break; } return ret; } int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); int N; cin >> N; vector<int> A(N), cnt(N, 0); for (int i = 0; i < N; i++) { cin >> A[i]; cnt[--A[i]]++; } int K = cnt[0]; if (K == 0) { cout << "0\n"; return 0; } vector<vector<int>> occ(N); for (int i = 0; i < N; i++) occ[A[i]].push_back(i); vector<int> first_idx(N); first_idx[0] = occ[0][0]; while (A[(first_idx[0] + N - 1) % N] == 0) first_idx[0] = (first_idx[0] + N - 1) % N; for (int i = 1; i < N; i++) if (cnt[i]) { if (cnt[i] == 1) { first_idx[i] = occ[i][0]; continue; } int x = 0; for (int j = 0; j < (int)occ[i].size(); j++) { int d = occ[i][(j + 1) % occ[i].size()] - occ[i][j]; while (d < 0) d += N; while (d >= N) d -= N; if (d >= N - N / 2) first_idx[i] = occ[i][(j + 1) % occ[i].size()], x++; } if (x != 1) { cout << "0\n"; return 0; } } for (int i = 0; i < N; i++) if (cnt[i]) for (int j = 0; j < (int)occ[i].size(); j++) if (occ[i][j] == first_idx[i]) { vector<int> occ_nw; for (int k = 0; k < (int)occ[i].size(); k++) occ_nw.push_back(occ[i][(j + k) % occ[i].size()]); occ[i] = occ_nw; break; } for (int i = 0; i < K; i++) if (occ[0][i] != (first_idx[0] + i) % N) { cout << "0\n"; return 0; } vector<pair<int, int>> R(N); for (int i = 0; i < N; i++) if (cnt[i]) { int x = occ[i].back() - K + 1; while (x < 0) x += N; x %= N; R[i] = {x, occ[i][0]}; int d = occ[i].back() - occ[i][0]; while (d < 0) d += N; d %= N; if (d >= K) { cout << "0\n"; return 0; } } vector<vector<int>> RMQ_max(19, vector<int>(N)); RMQ_max[0] = A; for (int i = 1; i < 19; i++) for (int j = 0; j < N; j++) RMQ_max[i][j] = max(RMQ_max[i - 1][j], RMQ_max[i - 1][min(N - 1, j + (1 << (i - 1)))]); vector<int> minval(N); for (int i = 0; i < N; i++) { minval[i] = get_max(RMQ_max, i, min(N, i + K)); if (i + K > N) minval[i] = max(minval[i], get_max(RMQ_max, 0, i + K - N)); } vector<vector<int>> RMQ_min(19, vector<int>(N)); RMQ_min[0] = minval; for (int i = 1; i < 19; i++) for (int j = 0; j < N; j++) RMQ_min[i][j] = min(RMQ_min[i - 1][j], RMQ_min[i - 1][min(N - 1, j + (1 << (i - 1)))]); for (int i = 0; i < N; i++) if (cnt[i]) { int r = (R[i].ss >= R[i].ff) ? R[i].ss : (N - 1); for (int j = 18; j >= 0; j--) while (R[i].ff + (1 << j) <= r) { if (RMQ_min[j][R[i].ff] <= i) break; R[i].ff += 1 << j; } for (int j = 0; j < 3; j++) { if (minval[R[i].ff] <= i) break; if (R[i].ff == R[i].ss) { cout << "0\n"; return 0; } R[i].ff = (R[i].ff + 1) % N; } r = (R[i].ss >= R[i].ff) ? R[i].ss : (N - 1); for (int j = 18; j >= 0; j--) while (R[i].ff + (1 << j) <= r) { if (RMQ_min[j][R[i].ff] <= i) break; R[i].ff += 1 << j; } int l = (R[i].ff <= R[i].ss) ? R[i].ff : 0; for (int j = 18; j >= 0; j--) while (R[i].ss - (1 << j) >= l) { if (RMQ_min[j][R[i].ss - (1 << j) + 1] <= i) break; R[i].ss -= 1 << j; } for (int j = 0; j < 3; j++) { if (minval[R[i].ss] <= i) break; if (R[i].ff == R[i].ss) { cout << "0\n"; return 0; } R[i].ss = (R[i].ss + N - 1) % N; } l = (R[i].ff <= R[i].ss) ? R[i].ff : 0; for (int j = 18; j >= 0; j--) while (R[i].ss - (1 << j) >= l) { if (RMQ_min[j][R[i].ss - (1 << j) + 1] <= i) break; R[i].ss -= 1 << j; } } vector<int> cnt_pos0(N, 0); for (int i = 0; i < N; i++) cnt_pos0[minval[i]]++; for (int i = 1; i < N; i++) cnt_pos0[i] += cnt_pos0[i - 1]; cat ans = 1, mod = 998244353; for (int i = 0; i < N; i++) { if (cnt[i] == 0) { if (cnt_pos0[i] <= i) { cout << "0\n"; return 0; } ans = ans * (cnt_pos0[i] - i) % mod; continue; } int d = R[i].ss - R[i].ff; while (d < 0) d += N; d %= N; ans = ans * (d + 1) % mod; } cout << ans << "\n"; return 0; } // look at my code // my code is amazing
#include <bits/stdc++.h> // iostream is too mainstream #include <cstdio> // bitch please #include <algorithm> #include <cmath> #include <cstdlib> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <time.h> #include <vector> #define dibs reserve #define OVER9000 1234567890 #define ALL_THE(CAKE, LIE) \ for (auto LIE = CAKE.begin(); LIE != CAKE.end(); LIE++) #define tisic 47 #define soclose 1e-8 #define chocolate win // so much chocolate #define patkan 9 #define ff first #define ss second #define abs(x) (((x) < 0) ? -(x) : (x)) #define uint unsigned int #define dbl long double #define pi 3.14159265358979323846 using namespace std; // mylittledoge using cat = long long; #ifdef DONLINE_JUDGE // palindromic tree is better than splay tree! #define lld I64d #endif int get_min(vector<vector<int>> &RMQ, int l, int r) { int ret = OVER9000; for (int i = 0; i < 19; i++) if (((r - l) >> i) & 1) { ret = min(ret, RMQ[i][l]); l += 1 << i; if (l == r) break; } return ret; } int get_max(vector<vector<int>> &RMQ, int l, int r) { int ret = -1; for (int i = 0; i < 19; i++) if (((r - l) >> i) & 1) { ret = max(ret, RMQ[i][l]); l += 1 << i; if (l == r) break; } return ret; } int main() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); int N; cin >> N; vector<int> A(N), cnt(N, 0); for (int i = 0; i < N; i++) { cin >> A[i]; cnt[--A[i]]++; } int K = cnt[0]; if (K == 0) { cout << "0\n"; return 0; } if (cnt[0] == N) { cat ans = 1, mod = 998244353; for (int i = 0; i < N; i++) ans = ans * (i + 1) % mod; cout << ans << "\n"; return 0; } vector<vector<int>> occ(N); for (int i = 0; i < N; i++) occ[A[i]].push_back(i); vector<int> first_idx(N); first_idx[0] = occ[0][0]; while (A[(first_idx[0] + N - 1) % N] == 0) first_idx[0] = (first_idx[0] + N - 1) % N; for (int i = 1; i < N; i++) if (cnt[i]) { if (cnt[i] == 1) { first_idx[i] = occ[i][0]; continue; } int x = 0; for (int j = 0; j < (int)occ[i].size(); j++) { int d = occ[i][(j + 1) % occ[i].size()] - occ[i][j]; while (d < 0) d += N; while (d >= N) d -= N; if (d >= N - N / 2) first_idx[i] = occ[i][(j + 1) % occ[i].size()], x++; } if (x != 1) { cout << "0\n"; return 0; } } for (int i = 0; i < N; i++) if (cnt[i]) for (int j = 0; j < (int)occ[i].size(); j++) if (occ[i][j] == first_idx[i]) { vector<int> occ_nw; for (int k = 0; k < (int)occ[i].size(); k++) occ_nw.push_back(occ[i][(j + k) % occ[i].size()]); occ[i] = occ_nw; break; } for (int i = 0; i < K; i++) if (occ[0][i] != (first_idx[0] + i) % N) { cout << "0\n"; return 0; } vector<pair<int, int>> R(N); for (int i = 0; i < N; i++) if (cnt[i]) { int x = occ[i].back() - K + 1; while (x < 0) x += N; x %= N; R[i] = {x, occ[i][0]}; int d = occ[i].back() - occ[i][0]; while (d < 0) d += N; d %= N; if (d >= K) { cout << "0\n"; return 0; } } vector<vector<int>> RMQ_max(19, vector<int>(N)); RMQ_max[0] = A; for (int i = 1; i < 19; i++) for (int j = 0; j < N; j++) RMQ_max[i][j] = max(RMQ_max[i - 1][j], RMQ_max[i - 1][min(N - 1, j + (1 << (i - 1)))]); vector<int> minval(N); for (int i = 0; i < N; i++) { minval[i] = get_max(RMQ_max, i, min(N, i + K)); if (i + K > N) minval[i] = max(minval[i], get_max(RMQ_max, 0, i + K - N)); } vector<vector<int>> RMQ_min(19, vector<int>(N)); RMQ_min[0] = minval; for (int i = 1; i < 19; i++) for (int j = 0; j < N; j++) RMQ_min[i][j] = min(RMQ_min[i - 1][j], RMQ_min[i - 1][min(N - 1, j + (1 << (i - 1)))]); for (int i = 0; i < N; i++) if (cnt[i]) { int r = (R[i].ss >= R[i].ff) ? R[i].ss : (N - 1); for (int j = 18; j >= 0; j--) while (R[i].ff + (1 << j) <= r) { if (RMQ_min[j][R[i].ff] <= i) break; R[i].ff += 1 << j; } for (int j = 0; j < 3; j++) { if (minval[R[i].ff] <= i) break; if (R[i].ff == R[i].ss) { cout << "0\n"; return 0; } R[i].ff = (R[i].ff + 1) % N; } r = (R[i].ss >= R[i].ff) ? R[i].ss : (N - 1); for (int j = 18; j >= 0; j--) while (R[i].ff + (1 << j) <= r) { if (RMQ_min[j][R[i].ff] <= i) break; R[i].ff += 1 << j; } int l = (R[i].ff <= R[i].ss) ? R[i].ff : 0; for (int j = 18; j >= 0; j--) while (R[i].ss - (1 << j) >= l) { if (RMQ_min[j][R[i].ss - (1 << j) + 1] <= i) break; R[i].ss -= 1 << j; } for (int j = 0; j < 3; j++) { if (minval[R[i].ss] <= i) break; if (R[i].ff == R[i].ss) { cout << "0\n"; return 0; } R[i].ss = (R[i].ss + N - 1) % N; } l = (R[i].ff <= R[i].ss) ? R[i].ff : 0; for (int j = 18; j >= 0; j--) while (R[i].ss - (1 << j) >= l) { if (RMQ_min[j][R[i].ss - (1 << j) + 1] <= i) break; R[i].ss -= 1 << j; } } vector<int> cnt_pos0(N, 0); for (int i = 0; i < N; i++) cnt_pos0[minval[i]]++; for (int i = 1; i < N; i++) cnt_pos0[i] += cnt_pos0[i - 1]; cat ans = 1, mod = 998244353; for (int i = 0; i < N; i++) { if (cnt[i] == 0) { if (cnt_pos0[i] <= i) { cout << "0\n"; return 0; } ans = ans * (cnt_pos0[i] - i) % mod; continue; } int d = R[i].ss - R[i].ff; while (d < 0) d += N; d %= N; ans = ans * (d + 1) % mod; } cout << ans << "\n"; return 0; } // look at my code // my code is amazing
insert
81
81
81
88
TLE
p03226
C++
Runtime Error
// pantyhose(black) + glasses = infinity #include <bits/stdc++.h> using namespace std; #define debug(x) cerr << #x << " = " << x << '\n'; #define BP() cerr << "OK!\n"; #define PR(A, n) \ { \ cerr << #A << " = "; \ for (int _ = 1; _ <= n; ++_) \ cerr << A[_] << ' '; \ cerr << '\n'; \ } #define PR0(A, n) \ { \ cerr << #A << " = "; \ for (int _ = 0; _ < n; ++_) \ cerr << A[_] << ' '; \ cerr << '\n'; \ } #define FILE_NAME "circular" const int MAX_N = 300002; const int MOD = 998244353; namespace dsu { int lab[MAX_N]; void init() { memset(lab, -1, sizeof(lab)); } int findset(int u) { return lab[u] < 0 ? u : lab[u] = findset(lab[u]); } int len(int s) { return -lab[findset(s)]; } bool uni(int s, int t) { s = findset(s); t = findset(t); if (s == t) return false; lab[t] += lab[s]; lab[s] = t; return true; } }; // namespace dsu int n, a[MAX_N], nxt[MAX_N], l[MAX_N], r[MAX_N]; void readInput() { cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; --a[i]; } } int calc(int v, int k) { if (v < k) return 0; return v - k + 1; } int dist(int l, int r) { if (l <= r) return r - l + 1; return n - l + r + 1; } int64_t solve() { a[n + 1] = n; for (int i = n - 1; i >= 0; --i) { if (a[i] != a[(i + 1) % n]) nxt[i] = i; else nxt[i] = nxt[i + 1]; } for (int i = n - 1; i >= 0; --i) { if (a[i] != a[(i + 1) % n]) nxt[i] = i; else nxt[i] = nxt[(i + 1) % n]; } memset(l, -1, sizeof(l)); memset(r, -1, sizeof(r)); for (int i = 0; i < n; ++i) { if (a[i] != a[(i - 1 + n) % n]) { if (l[a[i]] != -1) return 0; l[a[i]] = i; r[a[i]] = nxt[i]; } } if (a[0] == 0 && l[0] == -1) { int64_t res = 1; for (int i = 1; i <= n; ++i) res = res * i % MOD; return res; } if (l[0] == -1) return 0; int k = dist(l[0], r[0]), s = 0; for (int i = 0; i < n; ++i) { if (l[i] != -1 && dist(l[i], r[i]) > k) return 0; } int64_t res = 1; dsu::init(); for (int i = 0; i < n; ++i) { if (l[i] == -1) { if (dsu::len(0) == n) res = res * (n - i) % MOD; else res = res * (s - i) % MOD; } else if (a[(l[i] - 1 + n) % n] > i || a[(r[i] + 1) % n] > i) { } else { res = res * (k - dist(l[i], r[i]) + 1) % MOD; } if (l[i] == -1) continue; for (int j = l[i]; j != r[i]; j = (j + 1) % n) dsu::uni(j, (j + 1) % n); if (a[(l[i] - 1 + n) % n] < i) { s -= calc(dsu::len((l[i] - 1 + n) % n), k); dsu::uni(l[i], (l[i] - 1 + n) % n); } if (a[(r[i] + 1) % n] < i) { if (dsu::findset(r[i]) != dsu::findset((r[i] + 1) % n)) s -= calc(dsu::len((r[i] + 1) % n), k); dsu::uni(r[i], (r[i] + 1) % n); } s += calc(dsu::len(l[i]), k); } assert(res >= 0); return res; } int main() { #ifdef GLASSES_GIRL freopen(FILE_NAME ".inp", "r", stdin); freopen(FILE_NAME ".out", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0); readInput(); cout << solve(); }
// pantyhose(black) + glasses = infinity #include <bits/stdc++.h> using namespace std; #define debug(x) cerr << #x << " = " << x << '\n'; #define BP() cerr << "OK!\n"; #define PR(A, n) \ { \ cerr << #A << " = "; \ for (int _ = 1; _ <= n; ++_) \ cerr << A[_] << ' '; \ cerr << '\n'; \ } #define PR0(A, n) \ { \ cerr << #A << " = "; \ for (int _ = 0; _ < n; ++_) \ cerr << A[_] << ' '; \ cerr << '\n'; \ } #define FILE_NAME "circular" const int MAX_N = 300002; const int MOD = 998244353; namespace dsu { int lab[MAX_N]; void init() { memset(lab, -1, sizeof(lab)); } int findset(int u) { return lab[u] < 0 ? u : lab[u] = findset(lab[u]); } int len(int s) { return -lab[findset(s)]; } bool uni(int s, int t) { s = findset(s); t = findset(t); if (s == t) return false; lab[t] += lab[s]; lab[s] = t; return true; } }; // namespace dsu int n, a[MAX_N], nxt[MAX_N], l[MAX_N], r[MAX_N]; void readInput() { cin >> n; for (int i = 0; i < n; ++i) { cin >> a[i]; --a[i]; } } int calc(int v, int k) { if (v < k) return 0; return v - k + 1; } int dist(int l, int r) { if (l <= r) return r - l + 1; return n - l + r + 1; } int64_t solve() { a[n + 1] = n; for (int i = n - 1; i >= 0; --i) { if (a[i] != a[(i + 1) % n]) nxt[i] = i; else nxt[i] = nxt[i + 1]; } for (int i = n - 1; i >= 0; --i) { if (a[i] != a[(i + 1) % n]) nxt[i] = i; else nxt[i] = nxt[(i + 1) % n]; } memset(l, -1, sizeof(l)); memset(r, -1, sizeof(r)); for (int i = 0; i < n; ++i) { if (a[i] != a[(i - 1 + n) % n]) { if (l[a[i]] != -1) return 0; l[a[i]] = i; r[a[i]] = nxt[i]; } } if (a[0] == 0 && l[0] == -1) { int64_t res = 1; for (int i = 1; i <= n; ++i) res = res * i % MOD; return res; } if (l[0] == -1) return 0; int k = dist(l[0], r[0]), s = 0; for (int i = 0; i < n; ++i) { if (l[i] != -1 && dist(l[i], r[i]) > k) return 0; } int64_t res = 1; dsu::init(); for (int i = 0; i < n; ++i) { if (l[i] == -1) { if (dsu::len(0) == n) res = res * (n - i) % MOD; else res = res * (s - i) % MOD; } else if (a[(l[i] - 1 + n) % n] > i || a[(r[i] + 1) % n] > i) { if (a[(l[i] - 1 + n) % n] > i && a[(r[i] + 1) % n] > i && dist(l[i], r[i]) != k) return 0; } else { res = res * (k - dist(l[i], r[i]) + 1) % MOD; } if (l[i] == -1) continue; for (int j = l[i]; j != r[i]; j = (j + 1) % n) dsu::uni(j, (j + 1) % n); if (a[(l[i] - 1 + n) % n] < i) { s -= calc(dsu::len((l[i] - 1 + n) % n), k); dsu::uni(l[i], (l[i] - 1 + n) % n); } if (a[(r[i] + 1) % n] < i) { if (dsu::findset(r[i]) != dsu::findset((r[i] + 1) % n)) s -= calc(dsu::len((r[i] + 1) % n), k); dsu::uni(r[i], (r[i] + 1) % n); } s += calc(dsu::len(l[i]), k); } assert(res >= 0); return res; } int main() { #ifdef GLASSES_GIRL freopen(FILE_NAME ".inp", "r", stdin); freopen(FILE_NAME ".out", "w", stdout); #endif ios::sync_with_stdio(0); cin.tie(0); readInput(); cout << solve(); }
replace
115
116
115
118
0
p03227
C++
Runtime Error
#include <algorithm> #include <iostream> #include <string> using namespace std; int main() { string s; if (s.size() == 2) { cout << s << endl; } else { cout << s.at(2) << s.at(1) << s.at(0) << endl; } }
#include <algorithm> #include <iostream> #include <string> using namespace std; int main() { string s; cin >> s; if (s.size() == 2) { cout << s << endl; } else { cout << s.at(2) << s.at(1) << s.at(0) << endl; } }
insert
6
6
6
7
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::at: __n (which is 2) >= this->size() (which is 0)
p03227
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define start_routine() int begtime = clock(); #define end_routine() \ int endtime = clock(); \ cerr << endl \ << "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC \ << " ms"; \ return 0 #define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false) #define exit(a, b) return cout << a, b; #define PB push_back #define MP make_pair #define sd(n) scanf("%lld", &n) #define pdn(n) printf("%lld\n", n); #define pds(n) printf("%lld ", n); #define endl '\n' #define forn(a, b, i) for (int i = a; i < b; i += 1) #define all(v) v.begin(), v.end() using vi = vector<int>; using vb = vector<bool>; using pii = pair<int, int>; using mii = map<int, int>; #define print(stuff) cout << stuff << endl #define len(stuff) stuff.size() #define int long long const int inf = (int)5e15; const int upper = 1e5 + 10; const int M = 1000000007; int answer = 0; char arr[1005][1005]; // int fac[upper], invfac[upper]; // int modexp (int a, int b, int m) { // if (b == 0) return 1; // int ans = modexp (a, b/2, m); // ans = (ans * ans) % m; // if (b % 2 == 1) ans = (ans * a) % m; // return ans; // } // void prec() { // fac[0] = 1; // for (int i = 1; i < upper; i += 1) fac[i] = (fac[i - 1] * i) % M; // invfac[upper - 1] = modexp(fac[upper - 1], M - 2, M); // for (int i = upper - 2; i >= 0; i -= 1) invfac[i] = (invfac[i + 1] * (i // + 1)) % M; // } signed main() { start_routine(); speed(); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // freopen("errlog.txt", "w", stderr); #endif string s; cin >> s; if (len(s) == 2) { cout << s; } else { reverse(all(s)); cout << s; } end_routine(); }
#include <bits/stdc++.h> using namespace std; #define start_routine() int begtime = clock(); #define end_routine() \ int endtime = clock(); \ cerr << endl \ << "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC \ << " ms"; \ return 0 #define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false) #define exit(a, b) return cout << a, b; #define PB push_back #define MP make_pair #define sd(n) scanf("%lld", &n) #define pdn(n) printf("%lld\n", n); #define pds(n) printf("%lld ", n); #define endl '\n' #define forn(a, b, i) for (int i = a; i < b; i += 1) #define all(v) v.begin(), v.end() using vi = vector<int>; using vb = vector<bool>; using pii = pair<int, int>; using mii = map<int, int>; #define print(stuff) cout << stuff << endl #define len(stuff) stuff.size() #define int long long const int inf = (int)5e15; const int upper = 1e5 + 10; const int M = 1000000007; int answer = 0; char arr[1005][1005]; // int fac[upper], invfac[upper]; // int modexp (int a, int b, int m) { // if (b == 0) return 1; // int ans = modexp (a, b/2, m); // ans = (ans * ans) % m; // if (b % 2 == 1) ans = (ans * a) % m; // return ans; // } // void prec() { // fac[0] = 1; // for (int i = 1; i < upper; i += 1) fac[i] = (fac[i - 1] * i) % M; // invfac[upper - 1] = modexp(fac[upper - 1], M - 2, M); // for (int i = upper - 2; i >= 0; i -= 1) invfac[i] = (invfac[i + 1] * (i // + 1)) % M; // } signed main() { start_routine(); speed(); #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // freopen("errlog.txt", "w", stderr); #endif string s; cin >> s; if (len(s) == 2) { cout << s; } else { reverse(all(s)); cout << s; } end_routine(); }
replace
63
64
63
64
0
Time elapsed: 0 ms
p03227
C++
Runtime Error
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define rep2(i, n) for (int i = 0; i <= n; i++) #define repr(i, a, n) for (int i = a; i < n; i++) #define all(a) a.begin(), a.end() #define P pair<long long, long long> #define uni(e) e.erase(unique(e.begin(), e.end()), e.end()) #define double long double template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int INF = 1e10; int MOD = 1e9 + 7; template <class T> void out(T a) { cout << a << '\n'; } template <class T> void yesno(T b) { if (b) out("yes"); else out("no"); } template <class T> void YesNo(T b) { if (b) out("Yes"); else out("No"); } template <class T> void YESNO(T b) { if (b) out("YES"); else out("NO"); } template <class T> void noyes(T b) { if (b) out("no"); else out("yes"); } template <class T> void NoYes(T b) { if (b) out("No"); else out("Yes"); } template <class T> void NOYES(T b) { if (b) out("NO"); else out("YES"); } int keta(int a) { double b = a; b = log10(b); int c = b; return c + 1; } int gcd(int a, int b) { if (a % b == 0) return b; return gcd(b, a % b); } int lcm(int a, int b) { return a / gcd(a, b) * b; } bool sosuu(int a) { bool b = 1; if (a <= 1) return 0; else { rep1(i, sqrt(a) - 1) { if (a % (i + 1) == 0) b = 0; } return b; } } signed main() { string a; if (a.size() == 2) cout << a << endl; else cout << a[2] << a[1] << a[0] << endl; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define rep2(i, n) for (int i = 0; i <= n; i++) #define repr(i, a, n) for (int i = a; i < n; i++) #define all(a) a.begin(), a.end() #define P pair<long long, long long> #define uni(e) e.erase(unique(e.begin(), e.end()), e.end()) #define double long double template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } int INF = 1e10; int MOD = 1e9 + 7; template <class T> void out(T a) { cout << a << '\n'; } template <class T> void yesno(T b) { if (b) out("yes"); else out("no"); } template <class T> void YesNo(T b) { if (b) out("Yes"); else out("No"); } template <class T> void YESNO(T b) { if (b) out("YES"); else out("NO"); } template <class T> void noyes(T b) { if (b) out("no"); else out("yes"); } template <class T> void NoYes(T b) { if (b) out("No"); else out("Yes"); } template <class T> void NOYES(T b) { if (b) out("NO"); else out("YES"); } int keta(int a) { double b = a; b = log10(b); int c = b; return c + 1; } int gcd(int a, int b) { if (a % b == 0) return b; return gcd(b, a % b); } int lcm(int a, int b) { return a / gcd(a, b) * b; } bool sosuu(int a) { bool b = 1; if (a <= 1) return 0; else { rep1(i, sqrt(a) - 1) { if (a % (i + 1) == 0) b = 0; } return b; } } signed main() { string a; cin >> a; if (a.size() == 2) cout << a << endl; else cout << a[2] << a[1] << a[0] << endl; }
insert
91
91
91
92
-6
/usr/include/c++/12/bits/basic_string.h:1221: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator[](size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; reference = char&; size_type = long unsigned int]: Assertion '__pos <= size()' failed.
p03227
C++
Runtime Error
#include <bits/stdc++.h> #pragma GCC optimize("O3") #define REP(i, n) for (int i = 0; i < n; i++) #define REPP(i, n) for (int i = 1; i <= n; i++) #define ALL(obj) (obj).begin(), (obj).end() #define EPS (1e-9) #define INF (1e9) #define PI (acos(-1)) // const double PI = acos(-1); // const double EPS = 1e-15; // long long INF=(long long)1E17; #define i_7 (long long)(1e9 + 7) long mod(long a) { long long c = a % i_7; if (c >= 0) return c; return c + i_7; } using namespace std; bool prime_(int n) { if (n == 1) { return false; } else if (n == 2) { return true; } else { for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) { return false; } } return true; } } long long gcd_(long long a, long long b) { if (a < b) { swap(a, b); } if (a % b == 0) { return b; } else { return gcd_(b, a % b); } } long long lcm_(long long x, long long y) { return (x / gcd_(x, y)) * y; } int main() { string s; cin >> s; string ans = ""; int n = s.size(); if (n == 2) { cout << s << endl; } else { for (int i = n - 1; i >= 0; i++) { ans += s[i]; } cout << ans << endl; } return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("O3") #define REP(i, n) for (int i = 0; i < n; i++) #define REPP(i, n) for (int i = 1; i <= n; i++) #define ALL(obj) (obj).begin(), (obj).end() #define EPS (1e-9) #define INF (1e9) #define PI (acos(-1)) // const double PI = acos(-1); // const double EPS = 1e-15; // long long INF=(long long)1E17; #define i_7 (long long)(1e9 + 7) long mod(long a) { long long c = a % i_7; if (c >= 0) return c; return c + i_7; } using namespace std; bool prime_(int n) { if (n == 1) { return false; } else if (n == 2) { return true; } else { for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) { return false; } } return true; } } long long gcd_(long long a, long long b) { if (a < b) { swap(a, b); } if (a % b == 0) { return b; } else { return gcd_(b, a % b); } } long long lcm_(long long x, long long y) { return (x / gcd_(x, y)) * y; } int main() { string s; cin >> s; string ans = ""; int n = s.size(); if (n == 2) { cout << s << endl; } else { for (int i = n - 1; i >= 0; i--) { ans += s[i]; } cout << ans << endl; } return 0; }
replace
57
58
57
58
-11
p03227
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); freopen("input.txt", "r", stdin); string s; cin >> s; if (s.size() == 3) { reverse(s.begin(), s.end()); } cout << s << "\n"; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); // freopen("input.txt", "r", stdin); string s; cin >> s; if (s.size() == 3) { reverse(s.begin(), s.end()); } cout << s << "\n"; return 0; }
replace
6
7
6
7
0
p03227
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) int main() { string A; char B, C; if (A.size() == 2) { cout << A << endl; } else { B = A.at(0); C = A.at(2); A.at(0) = C; A.at(2) = B; cout << A << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) int main() { string A; cin >> A; char B, C; if (A.size() == 2) { cout << A << endl; } else { B = A.at(0); C = A.at(2); A.at(0) = C; A.at(2) = B; cout << A << endl; } }
insert
7
7
7
8
-6
terminate called after throwing an instance of 'std::out_of_range' what(): basic_string::at: __n (which is 0) >= this->size() (which is 0)
p03228
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define f(i, x, n) for (int i = x; i < (int)(n); ++i) #define mod 1000000007 #define speed \ ios::sync_with_stdio(0); \ cin.tie(0); int const N = 2 * 1e5 + 10; vector<int> v; vector<int> v1; int a[N], t[N], answer[N]; int main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); #endif speed ll a, b, k; cin >> a >> b >> k; f(i, 0, k) { if (i % 2 == 0) { if (a % 2 == 1) a--; b += a / 2; a /= 2; } else { if (b % 2 == 1) b--; a += b / 2; b /= 2; } } cout << a << " " << b << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define f(i, x, n) for (int i = x; i < (int)(n); ++i) #define mod 1000000007 #define speed \ ios::sync_with_stdio(0); \ cin.tie(0); int const N = 2 * 1e5 + 10; vector<int> v; vector<int> v1; int a[N], t[N], answer[N]; int main() { speed ll a, b, k; cin >> a >> b >> k; f(i, 0, k) { if (i % 2 == 0) { if (a % 2 == 1) a--; b += a / 2; a /= 2; } else { if (b % 2 == 1) b--; a += b / 2; b /= 2; } } cout << a << " " << b << endl; return 0; }
delete
13
16
13
13
0
p03229
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(void) { int n; cin >> n; vector<ll> v(n); rep(i, n) cin >> v[i]; sort(v.begin(), v.end()); /*小さい奴を真ん中にする場合*/ deque<ll> que1; rep(i, n) que1.push_back(v[i]); ll ans1 = 0; ll left = que1.front(); ll right = left; que1.pop_front(); int idx = 0; while (!que1.empty()) { if (que1.size() == 1) { ll a = que1.front(); ans1 += max(abs(left - a), abs(right - a)); que1.pop_front(); } else { ll a, b; if (idx % 2) { a = que1.front(); que1.pop_front(); b = que1.front(); que1.pop_front(); } else { a = que1.back(); que1.pop_back(); b = que1.back(); que1.pop_back(); } ll c = abs(a - left) + abs(b - right); ll d = abs(a - right) + abs(b - left); if (c > d) { left = a; right = b; ans1 += c; } else { left = b; right = a; ans1 += d; } } idx++; } deque<ll> que2; rep(i, n) que2.push_back(v[i]); ll ans2 = 0; ll left2 = que2.back(); ll right2 = left2; que2.pop_back(); int idx2 = 0; while (!que2.empty()) { if (que2.size() == 1) { ll a = que2.front(); ans2 += max(abs(left2 - a), abs(right2 - a)); que2.pop_front(); } else { ll a, b; if (idx2 % 2 == 0) { a = que2.front(); que2.pop_front(); b = que2.front(); que2.pop_front(); } else { a = que1.back(); que1.pop_back(); b = que1.back(); que1.pop_back(); } ll c = abs(a - left2) + abs(b - right2); ll d = abs(a - right2) + abs(b - left2); if (c > d) { left2 = a; right2 = b; ans2 += c; } else { left2 = b; right2 = a; ans2 += d; } } idx2++; } cout << max(ans1, ans2) << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(void) { int n; cin >> n; vector<ll> v(n); rep(i, n) cin >> v[i]; sort(v.begin(), v.end()); /*小さい奴を真ん中にする場合*/ deque<ll> que1; rep(i, n) que1.push_back(v[i]); ll ans1 = 0; ll left = que1.front(); ll right = left; que1.pop_front(); int idx = 0; while (!que1.empty()) { if (que1.size() == 1) { ll a = que1.front(); ans1 += max(abs(left - a), abs(right - a)); que1.pop_front(); } else { ll a, b; if (idx % 2) { a = que1.front(); que1.pop_front(); b = que1.front(); que1.pop_front(); } else { a = que1.back(); que1.pop_back(); b = que1.back(); que1.pop_back(); } ll c = abs(a - left) + abs(b - right); ll d = abs(a - right) + abs(b - left); if (c > d) { left = a; right = b; ans1 += c; } else { left = b; right = a; ans1 += d; } } idx++; } deque<ll> que2; rep(i, n) que2.push_back(v[i]); ll ans2 = 0; ll left2 = que2.back(); ll right2 = left2; que2.pop_back(); int idx2 = 0; while (!que2.empty()) { if (que2.size() == 1) { ll a = que2.front(); ans2 += max(abs(left2 - a), abs(right2 - a)); que2.pop_front(); } else { ll a, b; if (idx2 % 2 == 0) { a = que2.front(); que2.pop_front(); b = que2.front(); que2.pop_front(); } else { a = que2.back(); que2.pop_back(); b = que2.back(); que2.pop_back(); } ll c = abs(a - left2) + abs(b - right2); ll d = abs(a - right2) + abs(b - left2); if (c > d) { left2 = a; right2 = b; ans2 += c; } else { left2 = b; right2 = a; ans2 += d; } } idx2++; } cout << max(ans1, ans2) << endl; return 0; }
replace
71
75
71
75
0
p03229
C++
Runtime Error
#include <algorithm> #include <fstream> #include <iostream> #include <limits.h> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> #define rep(i, n) for (int i = 0; (i) < (n); ++(i)) #define int long long using namespace std; signed main(void) { int n, mone = 0, mtwo = 0; cin.tie(0); ios::sync_with_stdio(false); cin >> n; vector<int> aligns(n); rep(i, n) { cin >> aligns[i]; } sort(aligns.begin(), aligns.end()); if (aligns.size() == 2) { return aligns[1] - aligns[0]; } rep(i, n) { mone += aligns[n - 1 - i] - aligns[i]; mtwo += aligns[n - 1 - i] - aligns[i]; if (n - 1 - i - i == 2) { mone += aligns[n - 1] - aligns[i + 1]; mtwo += aligns[i + 1] - aligns[0]; break; } else if (n - 1 - i - i == 3) { mone += aligns[n - 2 - i] - aligns[i]; mtwo += aligns[n - 1 - i] - aligns[i + 1]; mone += aligns[n - 1] - aligns[i + 1]; mtwo += aligns[i + 2] - aligns[0]; break; } else { mone += aligns[n - 2 - i] - aligns[i]; mtwo += aligns[n - 1 - i] - aligns[i + 1]; } } cout << max(mone, mtwo) << endl; return 0; }
#include <algorithm> #include <fstream> #include <iostream> #include <limits.h> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <stack> #include <stdio.h> #include <string> #include <vector> #define rep(i, n) for (int i = 0; (i) < (n); ++(i)) #define int long long using namespace std; signed main(void) { int n, mone = 0, mtwo = 0; cin.tie(0); ios::sync_with_stdio(false); cin >> n; vector<int> aligns(n); rep(i, n) { cin >> aligns[i]; } sort(aligns.begin(), aligns.end()); if (aligns.size() == 2) { cout << aligns[1] - aligns[0] << endl; return 0; } rep(i, n) { mone += aligns[n - 1 - i] - aligns[i]; mtwo += aligns[n - 1 - i] - aligns[i]; if (n - 1 - i - i == 2) { mone += aligns[n - 1] - aligns[i + 1]; mtwo += aligns[i + 1] - aligns[0]; break; } else if (n - 1 - i - i == 3) { mone += aligns[n - 2 - i] - aligns[i]; mtwo += aligns[n - 1 - i] - aligns[i + 1]; mone += aligns[n - 1] - aligns[i + 1]; mtwo += aligns[i + 2] - aligns[0]; break; } else { mone += aligns[n - 2 - i] - aligns[i]; mtwo += aligns[n - 1 - i] - aligns[i + 1]; } } cout << max(mone, mtwo) << endl; return 0; }
replace
26
27
26
28
0
p03229
C++
Runtime Error
#include <algorithm> #include <cmath> #include <deque> #include <functional> #include <iostream> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; ll ABS(ll a, ll b) { if (a - b >= 0) return a - b; else return b - a; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; ll ans = 0; deque<ll> dq(n); deque<ll> dq2(n); for (int i = 0; i < n; i++) { cin >> dq[i]; dq2[i] = dq[i]; } sort(dq.begin(), dq.end()); sort(dq2.begin(), dq.end()); deque<ll> a; deque<ll> b; a.push_back(dq[0]); dq.pop_front(); while (!dq.empty()) { a.push_front(dq.back()); // 가장큰거 dq.pop_back(); if (dq.empty()) break; a.push_back(dq.back()); dq.pop_back(); if (dq.empty()) break; a.push_front(dq.front()); dq.pop_front(); if (dq.empty()) break; a.push_back(dq.front()); dq.pop_front(); if (dq.empty()) break; } int t = a.size(); for (int i = 1; i < t; i++) ans += ABS(a[i], a[i - 1]); b.push_back(dq2[dq2.size() - 1]); dq2.pop_back(); while (!dq2.empty()) { b.push_front(dq2.front()); dq2.pop_front(); if (dq2.empty()) break; b.push_back(dq2.front()); dq2.pop_front(); if (dq2.empty()) break; b.push_front(dq2.back()); dq2.pop_back(); if (dq2.empty()) break; b.push_back(dq2.back()); dq2.pop_back(); if (dq2.empty()) break; } int p = b.size(); ll ans2 = 0; for (int i = 1; i < p; i++) ans2 += ABS(b[i], b[i - 1]); cout << max(ans, ans2); }
#include <algorithm> #include <cmath> #include <deque> #include <functional> #include <iostream> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; ll ABS(ll a, ll b) { if (a - b >= 0) return a - b; else return b - a; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; ll ans = 0; deque<ll> dq(n); deque<ll> dq2(n); for (int i = 0; i < n; i++) { cin >> dq[i]; dq2[i] = dq[i]; } sort(dq.begin(), dq.end()); sort(dq2.begin(), dq2.end()); deque<ll> a; deque<ll> b; a.push_back(dq[0]); dq.pop_front(); while (!dq.empty()) { a.push_front(dq.back()); // 가장큰거 dq.pop_back(); if (dq.empty()) break; a.push_back(dq.back()); dq.pop_back(); if (dq.empty()) break; a.push_front(dq.front()); dq.pop_front(); if (dq.empty()) break; a.push_back(dq.front()); dq.pop_front(); if (dq.empty()) break; } int t = a.size(); for (int i = 1; i < t; i++) ans += ABS(a[i], a[i - 1]); b.push_back(dq2[dq2.size() - 1]); dq2.pop_back(); while (!dq2.empty()) { b.push_front(dq2.front()); dq2.pop_front(); if (dq2.empty()) break; b.push_back(dq2.front()); dq2.pop_front(); if (dq2.empty()) break; b.push_front(dq2.back()); dq2.pop_back(); if (dq2.empty()) break; b.push_back(dq2.back()); dq2.pop_back(); if (dq2.empty()) break; } int p = b.size(); ll ans2 = 0; for (int i = 1; i < p; i++) ans2 += ABS(b[i], b[i - 1]); cout << max(ans, ans2); }
replace
34
35
34
35
-11
p03229
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <chrono> #include <deque> #include <iostream> #include <map> #include <vector> #define vint vector<int> #define vint2 vector<vint> #define vchar vector<char> #define vchar2 vector<vchar> #define vchar3 vector<vchar2> #define pr pair<int, int> #define vpr vector<pr> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) typedef long long int ll; using namespace std; // CHAR_BIT ビット フィールドではない最小変数のビット数。 8 // SCHAR_MIN signed char 型変数の最小値。 –128 // SCHAR_MAX signed char 型変数の最大値。 127 // UCHAR_MAX unsigned char 型変数の最大値。 255 (0xff) // CHAR_MIN char 型変数の最小値。 - 128、 / J オプション使用時は 0 // CHAR_MAX char 型変数の最大値。 127、 / J オプション使用時は 255 // MB_LEN_MAX 多文字定数の最大バイト数。 5 // SHRT_MIN short 型変数の最小値。 –32768 // SHRT_MAX short 型変数の最大値。 32767 // USHRT_MAX unsigned short 型変数の最大値。 65535 (0xffff) // INT_MIN int 型変数の最小値。 –2147483647 – 1 // INT_MAX int 型変数の最大値。 2147483647 // UINT_MAX unsigned int 型変数の最大値。 4294967295 (0xffffffff) // LONG_MIN long 型変数の最小値。 –2147483647 – 1 // LONG_MAX long 型変数の最大値。 2147483647 // ULONG_MAX unsigned long 型変数の最大値。 4294967295 (0xffffffff) int main() { int n; cin >> n; vint a = vint(n); REP(i, n) { cin >> a[i]; } sort(a.begin(), a.end()); cerr << "-------" << endl; REP(i, n) { cerr << a[i] << endl; } int s = 0, e = n - 2; int sv = a[n - 1]; int ev = a[n - 1]; long long int ret = 0; int cnt = 0; while (s <= e) { int sv_s = abs(sv - a[s]); // 0 int mi = 0; int m = sv_s; // cerr << "m"<<mi<<"\t"<<m << endl; int ev_s = abs(ev - a[s]); // 1 if (ev_s > m) { mi = 1; m = ev_s; } int sv_e = abs(sv - a[e]); // 2 if (sv_e > m) { mi = 2; m = sv_e; } int ev_e = abs(ev - a[e]); // 3 if (ev_e > m) { mi = 3; m = ev_e; } cerr << "m\t" << m << endl; ret += m; if (mi < 2) { if (mi % 2 == 0) { sv = a[s]; } else { ev = a[s]; } s++; } else { if (mi % 2 == 0) { sv = a[e]; } else { ev = a[e]; } e--; } cerr << "sv\t" << sv << "ev\t" << ev << endl; } // ret += a[s]; cout << ret << endl; while (true) { } return 0; }
#include <algorithm> #include <bitset> #include <chrono> #include <deque> #include <iostream> #include <map> #include <vector> #define vint vector<int> #define vint2 vector<vint> #define vchar vector<char> #define vchar2 vector<vchar> #define vchar3 vector<vchar2> #define pr pair<int, int> #define vpr vector<pr> #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) typedef long long int ll; using namespace std; // CHAR_BIT ビット フィールドではない最小変数のビット数。 8 // SCHAR_MIN signed char 型変数の最小値。 –128 // SCHAR_MAX signed char 型変数の最大値。 127 // UCHAR_MAX unsigned char 型変数の最大値。 255 (0xff) // CHAR_MIN char 型変数の最小値。 - 128、 / J オプション使用時は 0 // CHAR_MAX char 型変数の最大値。 127、 / J オプション使用時は 255 // MB_LEN_MAX 多文字定数の最大バイト数。 5 // SHRT_MIN short 型変数の最小値。 –32768 // SHRT_MAX short 型変数の最大値。 32767 // USHRT_MAX unsigned short 型変数の最大値。 65535 (0xffff) // INT_MIN int 型変数の最小値。 –2147483647 – 1 // INT_MAX int 型変数の最大値。 2147483647 // UINT_MAX unsigned int 型変数の最大値。 4294967295 (0xffffffff) // LONG_MIN long 型変数の最小値。 –2147483647 – 1 // LONG_MAX long 型変数の最大値。 2147483647 // ULONG_MAX unsigned long 型変数の最大値。 4294967295 (0xffffffff) int main() { int n; cin >> n; vint a = vint(n); REP(i, n) { cin >> a[i]; } sort(a.begin(), a.end()); cerr << "-------" << endl; REP(i, n) { cerr << a[i] << endl; } int s = 0, e = n - 2; int sv = a[n - 1]; int ev = a[n - 1]; long long int ret = 0; int cnt = 0; while (s <= e) { int sv_s = abs(sv - a[s]); // 0 int mi = 0; int m = sv_s; // cerr << "m"<<mi<<"\t"<<m << endl; int ev_s = abs(ev - a[s]); // 1 if (ev_s > m) { mi = 1; m = ev_s; } int sv_e = abs(sv - a[e]); // 2 if (sv_e > m) { mi = 2; m = sv_e; } int ev_e = abs(ev - a[e]); // 3 if (ev_e > m) { mi = 3; m = ev_e; } cerr << "m\t" << m << endl; ret += m; if (mi < 2) { if (mi % 2 == 0) { sv = a[s]; } else { ev = a[s]; } s++; } else { if (mi % 2 == 0) { sv = a[e]; } else { ev = a[e]; } e--; } cerr << "sv\t" << sv << "ev\t" << ev << endl; } // ret += a[s]; cout << ret << endl; // while (true) {} return 0; }
replace
91
93
91
92
TLE
p03229
C++
Runtime Error
#include <bits/stdc++.h> typedef long long ll; const int maxn = 10003; int n, a[maxn], b[maxn]; ll ans; int read() { char ch = getchar(); int num = 0; bool fl = 0; for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = 1; for (; isdigit(ch); ch = getchar()) num = (num << 1) + (num << 3) + ch - 48; if (fl) num = -num; return num; } int main() { n = read(); for (int i = 1; i <= n; i++) a[i] = read(); std::sort(a + 1, a + n + 1); b[1] = a[(n + 1) / 2]; int l = 1, r = n, cnt = 1; for (int i = 1, f = 0; i < n; i++) { if (f) b[++cnt] = a[r--]; else b[++cnt] = a[l++]; f = 1 - f; } ans = 0; for (int i = 2; i <= n; i++) ans += abs(1ll * b[i] - b[i - 1]); l = 1, r = n, cnt = 1; for (int i = 1, f = 1; i < n; i++) { if (f) b[++cnt] = a[r--]; else b[++cnt] = a[l++]; f = 1 - f; } ll s = 0; for (int i = 2; i <= n; i++) s += abs(1ll * b[i] - b[i - 1]); printf("%lld\n", std::max(ans, s)); return 0; }
#include <bits/stdc++.h> typedef long long ll; const int maxn = 100003; int n, a[maxn], b[maxn]; ll ans; int read() { char ch = getchar(); int num = 0; bool fl = 0; for (; !isdigit(ch); ch = getchar()) if (ch == '-') fl = 1; for (; isdigit(ch); ch = getchar()) num = (num << 1) + (num << 3) + ch - 48; if (fl) num = -num; return num; } int main() { n = read(); for (int i = 1; i <= n; i++) a[i] = read(); std::sort(a + 1, a + n + 1); b[1] = a[(n + 1) / 2]; int l = 1, r = n, cnt = 1; for (int i = 1, f = 0; i < n; i++) { if (f) b[++cnt] = a[r--]; else b[++cnt] = a[l++]; f = 1 - f; } ans = 0; for (int i = 2; i <= n; i++) ans += abs(1ll * b[i] - b[i - 1]); l = 1, r = n, cnt = 1; for (int i = 1, f = 1; i < n; i++) { if (f) b[++cnt] = a[r--]; else b[++cnt] = a[l++]; f = 1 - f; } ll s = 0; for (int i = 2; i <= n; i++) s += abs(1ll * b[i] - b[i - 1]); printf("%lld\n", std::max(ans, s)); return 0; }
replace
2
3
2
3
0
p03229
C++
Runtime Error
#include <bits/stdc++.h> #include <stdio.h> using namespace std; #define REP(i, a, b) for (int i = (a), _end_ = (b); i < _end_; ++i) #define debug(...) fprintf(stderr, __VA_ARGS__) #define X first #define Y second #define mp make_pair #define eb emplace_back #define SZ(x) (int((x).size())) #define ALL(x) (x).begin(), (x).end() template <typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } typedef long long LL; typedef long double LD; typedef pair<int, int> pii; typedef unsigned long long uLL; template <typename T> inline void Read(T &x) { char c = getchar(); bool f = false; for (x = 0; !isdigit(c); c = getchar()) { if (c == '-') { f = true; } } for (; isdigit(c); c = getchar()) { x = x * 10 + c - '0'; } if (f) { x = -x; } } const int MAX_N = 305; const int MAX_M = 1e5 + 5; const int INF = 0x3f3f3f3f; int n, a[MAX_N]; int main() { #ifdef ANONYM freopen("in", "r", stdin); freopen("out", "w", stdout); #endif Read(n); for (int i = 0; i < n; i++) Read(a[i]); sort(a, a + n); if (n % 2 == 0) { LL lsum = 0; for (int i = 0; i < n / 2 - 1; i++) lsum += 2 * a[i]; lsum += a[n / 2 - 1]; LL rsum = 0; for (int i = n / 2 + 1; i < n; i++) rsum += 2 * a[i]; rsum += a[n / 2]; printf("%lld\n", rsum - lsum); } else { LL lsum1 = 0, rsum1 = 0; for (int i = 0; i < n / 2 - 1; i++) lsum1 += 2 * a[i]; lsum1 += a[n / 2 - 1]; for (int i = n / 2 + 1; i < n; i++) rsum1 += 2 * a[i]; lsum1 += a[n / 2]; LL lsum2 = 0, rsum2 = 0; for (int i = 0; i < n / 2; i++) lsum2 += 2 * a[i]; rsum2 += a[n / 2]; for (int i = n / 2 + 2; i < n; i++) rsum2 += 2 * a[i]; rsum2 += a[n / 2 + 1]; printf("%lld\n", max(rsum1 - lsum1, rsum2 - lsum2)); } return 0; }
#include <bits/stdc++.h> #include <stdio.h> using namespace std; #define REP(i, a, b) for (int i = (a), _end_ = (b); i < _end_; ++i) #define debug(...) fprintf(stderr, __VA_ARGS__) #define X first #define Y second #define mp make_pair #define eb emplace_back #define SZ(x) (int((x).size())) #define ALL(x) (x).begin(), (x).end() template <typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } typedef long long LL; typedef long double LD; typedef pair<int, int> pii; typedef unsigned long long uLL; template <typename T> inline void Read(T &x) { char c = getchar(); bool f = false; for (x = 0; !isdigit(c); c = getchar()) { if (c == '-') { f = true; } } for (; isdigit(c); c = getchar()) { x = x * 10 + c - '0'; } if (f) { x = -x; } } const int MAX_N = 1e5 + 5; const int INF = 0x3f3f3f3f; int n, a[MAX_N]; int main() { #ifdef ANONYM freopen("in", "r", stdin); freopen("out", "w", stdout); #endif Read(n); for (int i = 0; i < n; i++) Read(a[i]); sort(a, a + n); if (n % 2 == 0) { LL lsum = 0; for (int i = 0; i < n / 2 - 1; i++) lsum += 2 * a[i]; lsum += a[n / 2 - 1]; LL rsum = 0; for (int i = n / 2 + 1; i < n; i++) rsum += 2 * a[i]; rsum += a[n / 2]; printf("%lld\n", rsum - lsum); } else { LL lsum1 = 0, rsum1 = 0; for (int i = 0; i < n / 2 - 1; i++) lsum1 += 2 * a[i]; lsum1 += a[n / 2 - 1]; for (int i = n / 2 + 1; i < n; i++) rsum1 += 2 * a[i]; lsum1 += a[n / 2]; LL lsum2 = 0, rsum2 = 0; for (int i = 0; i < n / 2; i++) lsum2 += 2 * a[i]; rsum2 += a[n / 2]; for (int i = n / 2 + 2; i < n; i++) rsum2 += 2 * a[i]; rsum2 += a[n / 2 + 1]; printf("%lld\n", max(rsum1 - lsum1, rsum2 - lsum2)); } return 0; }
replace
40
42
40
41
0
p03229
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { ifstream cin("tst.in"); int n; cin >> n; long long x; vector<long long> a; for (int i = 1; i <= n; i++) { cin >> x; a.push_back(x); } sort(a.begin(), a.end()); int l = a[a.size() - 1]; // left int r = l; // right int i = 0, j = a.size() - 2; long long sum = 0; while (i < j) { int li = abs(l - a[i]), ri = abs(r - a[i]); int lj = abs(l - a[j]), rj = abs(r - a[j]); if (li > ri || lj > rj) { // left side if (li > lj) { sum += li; l = a[i++]; } else { sum += lj; l = a[j--]; } } else { if (ri > rj) { sum += ri; r = a[i++]; } else { sum += rj; r = a[j--]; } } // cout<<l<<"---"<<r<<"------"<<i<<"---"<<j<<"----------"<<sum<<endl; } sum += max(abs(l - a[i]), abs(r - a[i])); cout << sum << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { // ifstream cin("tst.in"); int n; cin >> n; long long x; vector<long long> a; for (int i = 1; i <= n; i++) { cin >> x; a.push_back(x); } sort(a.begin(), a.end()); int l = a[a.size() - 1]; // left int r = l; // right int i = 0, j = a.size() - 2; long long sum = 0; while (i < j) { int li = abs(l - a[i]), ri = abs(r - a[i]); int lj = abs(l - a[j]), rj = abs(r - a[j]); if (li > ri || lj > rj) { // left side if (li > lj) { sum += li; l = a[i++]; } else { sum += lj; l = a[j--]; } } else { if (ri > rj) { sum += ri; r = a[i++]; } else { sum += rj; r = a[j--]; } } // cout<<l<<"---"<<r<<"------"<<i<<"---"<<j<<"----------"<<sum<<endl; } sum += max(abs(l - a[i]), abs(r - a[i])); cout << sum << endl; return 0; }
replace
5
6
5
6
-11
p03229
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, P> IP; typedef vector<ll> V; typedef vector<V> V2; typedef vector<vector<P>> G; void g_dir(G &graph, ll a, ll b, ll w = 1) { graph[a].push_back(P(b, w)); } void g_undir(G &graph, ll a, ll b, ll w = 1) { g_dir(graph, a, b, w); g_dir(graph, b, a, w); } #define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++) #define rep1(i, n) for (ll(i) = 1; (i) <= (n); (i)++) #define rrep(i, n) for (ll(i) = (n)-1; (i) >= 0; (i)--) #define rrep1(i, n) for (ll(i) = (n); (i) >= 1; (i)--) template <class T> void chmax(T &a, const T &b) { if (a < b) { a = b; } } template <class T> void chmin(T &a, const T &b) { if (a > b) { a = b; } } const ll INF = 1145141919810893; const ll MOD = 1000000007; const ll NUM = 101010; int main() { ll N; cin >> N; V v(N); rep(i, N) cin >> v[i]; sort(v.begin(), v.end(), greater<ll>()); if (N % 2) { return 1; } else { ll ans = 0; for (ll i = 0; i < N / 2; i++) { ans += v[i]; if (i + 1 < N / 2) ans += v[i]; } for (ll i = N / 2; i < N; i++) { ans -= v[i]; if (i > N / 2) ans -= v[i]; } cout << ans << endl; } return 0; }
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef pair<ll, ll> P; typedef pair<ll, P> IP; typedef vector<ll> V; typedef vector<V> V2; typedef vector<vector<P>> G; void g_dir(G &graph, ll a, ll b, ll w = 1) { graph[a].push_back(P(b, w)); } void g_undir(G &graph, ll a, ll b, ll w = 1) { g_dir(graph, a, b, w); g_dir(graph, b, a, w); } #define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++) #define rep1(i, n) for (ll(i) = 1; (i) <= (n); (i)++) #define rrep(i, n) for (ll(i) = (n)-1; (i) >= 0; (i)--) #define rrep1(i, n) for (ll(i) = (n); (i) >= 1; (i)--) template <class T> void chmax(T &a, const T &b) { if (a < b) { a = b; } } template <class T> void chmin(T &a, const T &b) { if (a > b) { a = b; } } const ll INF = 1145141919810893; const ll MOD = 1000000007; const ll NUM = 101010; int main() { ll N; cin >> N; V v(N); rep(i, N) cin >> v[i]; sort(v.begin(), v.end(), greater<ll>()); if (N % 2) { ll ans = 0; rep(i, N / 2) ans += v[i] * 2; for (ll i = N / 2, j = 0; i < N; i++, j++) { ans -= v[i]; if (j >= 2) ans -= v[i]; } ll ans2 = 0; for (ll i = N / 2, j = 0; i >= 0; i--, j++) { ans2 += v[i]; if (j >= 2) ans2 += v[i]; } for (ll i = (N + 1) / 2; i < N; i++) { ans2 -= v[i] * 2; } cout << max(ans, ans2) << endl; } else { ll ans = 0; for (ll i = 0; i < N / 2; i++) { ans += v[i]; if (i + 1 < N / 2) ans += v[i]; } for (ll i = N / 2; i < N; i++) { ans -= v[i]; if (i > N / 2) ans -= v[i]; } cout << ans << endl; } return 0; }
replace
39
40
39
56
1
p03230
Python
Runtime Error
n = int(input()) for i in range(n**0.5 + 1): if 2 * n == i**2 - i: k = i break elif 2 * n < i**2 - i: print("No") exit() k = int(k) print("Yes") print(k) num, ans = 1, [[] for _ in range(k)] for i in range(k): for j in range(i + 1, k): ans[i].append(num) ans[j].append(num) num += 1 print(k - 1, *ans[i])
n = int(input()) for i in range(10**5): if 2 * n == i**2 - i: k = i break elif 2 * n < i**2 - i: print("No") exit() k = int(k) print("Yes") print(k) num, ans = 1, [[] for _ in range(k)] for i in range(k): for j in range(i + 1, k): ans[i].append(num) ans[j].append(num) num += 1 print(k - 1, *ans[i])
replace
2
3
2
3
TypeError: 'float' object cannot be interpreted as an integer
Traceback (most recent call last): File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03230/Python/s851921325.py", line 3, in <module> for i in range(n ** 0.5 + 1): TypeError: 'float' object cannot be interpreted as an integer
p03230
Python
Runtime Error
def main(): from collections import deque from decimal import Decimal, getcontext getcontext().prec = 1000 N = int(input()) # {1,...,N}*2を分割 # k個の集合があって # 各集合は他のk-1個の集合に対し共通要素を1個ずつ合わせてk-1個の要素をもつ sq = Decimal(N * 8 + 1).sqrt() cond = sq % 2 == 1 # 奇数か if not cond: print("No") return k = int((1 + sq) // 2) # Decimalのままだとrangeの引数に使えない print("Yes") print(k) deqs = [] it = iter(range(1, N + 1)) for _ in range(k): print(k - 1, end=" ") t = [] for deq in deqs: x = deq.popleft() t.append(x) u = [] for _ in range(k - 1 - len(t)): x = next(it) u.append(x) print(*t, *u) deqs.append(deque(u)) if __name__ == "__main__": main()
def main(): from collections import deque from decimal import Decimal, getcontext getcontext().prec = 1000 N = int(input()) # {1,...,N}*2を分割 # k個の集合があって # 各集合は他のk-1個の集合に対し共通要素を1個ずつ合わせてk-1個の要素をもつ sq = Decimal(N * 8 + 1).sqrt() cond = sq % 2 == 1 # 奇数か if not cond: print("No") return k = int((1 + sq) // 2) # Decimalのままだとrangeの引数に使えない print("Yes") print(k) deqs = [] it = iter(range(1, N + 1)) for _ in range(k): print(k - 1, end=" ") t = [] for deq in deqs: x = deq.popleft() t.append(x) u = [] for _ in range(k - 1 - len(t)): x = next(it) u.append(x) t.extend(u) print(*t) # *t,*uがRE deqs.append(deque(u)) if __name__ == "__main__": main()
replace
34
35
34
36
0
p03230
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // #define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = mod * mod; const int INF_N = 1e+9; typedef pair<int, int> P; #define stop \ char nyaa; \ cin >> nyaa; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) #define all(v) (v).begin(), (v).end() typedef pair<ll, ll> LP; typedef long double ld; typedef pair<ld, ld> LDP; const ld eps = 1e-12; const ld pi = acos(-1.0); // typedef vector<vector<ll>> mat; typedef vector<int> vec; // 繰り返し二乗法 ll mod_pow(ll a, ll n, ll m) { ll res = 1; while (n) { if (n & 1) res = res * a % m; a = a * a % m; n >>= 1; } return res; } struct modint { ll n; modint() : n(0) { ; } modint(ll m) : n(m) { if (n >= mod) n %= mod; else if (n < 0) n = (n % mod + mod) % mod; } operator int() { return n; } }; bool operator==(modint a, modint b) { return a.n == b.n; } modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod) a.n -= mod; return a; } modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0) a.n += mod; return a; } modint operator*=(modint &a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; } modint operator+(modint a, modint b) { return a += b; } modint operator-(modint a, modint b) { return a -= b; } modint operator*(modint a, modint b) { return a *= b; } modint operator^(modint a, int n) { if (n == 0) return modint(1); modint res = (a * a) ^ (n / 2); if (n % 2) res = res * a; return res; } // 逆元(Eucledean algorithm) ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p); } modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); } const int max_n = 1 << 18; modint fact[max_n], factinv[max_n]; void init_f() { fact[0] = modint(1); for (int i = 0; i < max_n - 1; i++) { fact[i + 1] = fact[i] * modint(i + 1); } factinv[max_n - 1] = modint(1) / fact[max_n - 1]; for (int i = max_n - 2; i >= 0; i--) { factinv[i] = factinv[i + 1] * modint(i + 1); } } modint comb(int a, int b) { if (a < 0 || b < 0 || a < b) return 0; return fact[a] * factinv[b] * factinv[a - b]; } using mP = pair<modint, modint>; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; ll N; vector<vec> dfs(int k) { if (k == 3) { vector<vec> v = {{1, 2}, {2, 3}, {3, 1}}; return v; } auto v = dfs(k - 1); int tmp = k * (k - 1) / 2; vec tmpv; rep(i, k - 1) { v[i].push_back(tmp - i); tmpv.push_back(tmp - i); } v.push_back(tmpv); return v; } void solve() { cin >> N; ll k = 0; rep(i, 1000) { if (i * (i - 1) == 2 * N) k = i; } if (k == 0) { cout << "No" << endl; return; } // vector<vec> v(k); // rep(i, 3){ // rep(j, k-1){ // v[i].push_back((k-2)*i+1); // } // } auto res = dfs(k); cout << "Yes" << endl; cout << k << endl; rep(i, k) { cout << k - 1 << " "; rep(j, k - 1) { cout << res[i][j]; if (j != k - 2) cout << " "; else cout << endl; } } } signed main() { ios::sync_with_stdio(false); cin.tie(0); // cout << fixed << setprecision(10); // init_f(); // init(); // int t; cin >> t; rep(i, t)solve(); solve(); // stop return 0; }
#include <bits/stdc++.h> using namespace std; // #define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = mod * mod; const int INF_N = 1e+9; typedef pair<int, int> P; #define stop \ char nyaa; \ cin >> nyaa; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) #define all(v) (v).begin(), (v).end() typedef pair<ll, ll> LP; typedef long double ld; typedef pair<ld, ld> LDP; const ld eps = 1e-12; const ld pi = acos(-1.0); // typedef vector<vector<ll>> mat; typedef vector<int> vec; // 繰り返し二乗法 ll mod_pow(ll a, ll n, ll m) { ll res = 1; while (n) { if (n & 1) res = res * a % m; a = a * a % m; n >>= 1; } return res; } struct modint { ll n; modint() : n(0) { ; } modint(ll m) : n(m) { if (n >= mod) n %= mod; else if (n < 0) n = (n % mod + mod) % mod; } operator int() { return n; } }; bool operator==(modint a, modint b) { return a.n == b.n; } modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod) a.n -= mod; return a; } modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0) a.n += mod; return a; } modint operator*=(modint &a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; } modint operator+(modint a, modint b) { return a += b; } modint operator-(modint a, modint b) { return a -= b; } modint operator*(modint a, modint b) { return a *= b; } modint operator^(modint a, int n) { if (n == 0) return modint(1); modint res = (a * a) ^ (n / 2); if (n % 2) res = res * a; return res; } // 逆元(Eucledean algorithm) ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p); } modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); } const int max_n = 1 << 18; modint fact[max_n], factinv[max_n]; void init_f() { fact[0] = modint(1); for (int i = 0; i < max_n - 1; i++) { fact[i + 1] = fact[i] * modint(i + 1); } factinv[max_n - 1] = modint(1) / fact[max_n - 1]; for (int i = max_n - 2; i >= 0; i--) { factinv[i] = factinv[i + 1] * modint(i + 1); } } modint comb(int a, int b) { if (a < 0 || b < 0 || a < b) return 0; return fact[a] * factinv[b] * factinv[a - b]; } using mP = pair<modint, modint>; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; ll N; vector<vec> dfs(int k) { if (k == 3) { vector<vec> v = {{1, 2}, {2, 3}, {3, 1}}; return v; } auto v = dfs(k - 1); int tmp = k * (k - 1) / 2; vec tmpv; rep(i, k - 1) { v[i].push_back(tmp - i); tmpv.push_back(tmp - i); } v.push_back(tmpv); return v; } void solve() { cin >> N; if (N == 1) { cout << "Yes" << endl; cout << 2 << endl; cout << 1 << " " << 1 << endl; cout << 1 << " " << 1 << endl; return; } ll k = 0; rep(i, 1000) { if (i * (i - 1) == 2 * N) k = i; } if (k == 0) { cout << "No" << endl; return; } // vector<vec> v(k); // rep(i, 3){ // rep(j, k-1){ // v[i].push_back((k-2)*i+1); // } // } auto res = dfs(k); cout << "Yes" << endl; cout << k << endl; rep(i, k) { cout << k - 1 << " "; rep(j, k - 1) { cout << res[i][j]; if (j != k - 2) cout << " "; else cout << endl; } } } signed main() { ios::sync_with_stdio(false); cin.tie(0); // cout << fixed << setprecision(10); // init_f(); // init(); // int t; cin >> t; rep(i, t)solve(); solve(); // stop return 0; }
insert
127
127
127
134
0
p03230
Python
Runtime Error
def solve(n): k = 1 while k * (k + 1) < 2 * n: k += 1 if k * (k + 1) != 2 * n: return False, [] ans = [[] for _ in range(1000)] add_num = 1 ans[1].append(add_num) ans[0].append(add_num) for i in range(2, k + 1): for j in range(i): add_num += 1 ans[i].append(add_num) ans[i - j - 1].append(add_num) return True, ans, k def main(): n = int(input()) res, ans, k = solve(n) if res: print("Yes") print(k + 1) for a in ans: if a: print(len(a), " ".join(map(str, a))) else: break else: print("No") if __name__ == "__main__": main()
def solve(n): k = 1 while k * (k + 1) < 2 * n: k += 1 if k * (k + 1) != 2 * n: return False, [], -1 ans = [[] for _ in range(1000)] add_num = 1 ans[1].append(add_num) ans[0].append(add_num) for i in range(2, k + 1): for j in range(i): add_num += 1 ans[i].append(add_num) ans[i - j - 1].append(add_num) return True, ans, k def main(): n = int(input()) res, ans, k = solve(n) if res: print("Yes") print(k + 1) for a in ans: if a: print(len(a), " ".join(map(str, a))) else: break else: print("No") if __name__ == "__main__": main()
replace
5
6
5
6
0
p03230
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> ii; typedef tuple<ll, ll, ll> iii; typedef vector<ll> vi; typedef vector<ii> vii; typedef vector<iii> viii; typedef vector<vi> vvi; typedef vector<vii> vvii; #define REP(i, n) for (ll i = 0; i < n; ++i) #define REPR(i, n) for (ll i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (ll i = m; i < n; ++i) #define FORR(i, m, n) for (ll i = n - 1; i >= m; --i) #define FORE(x, xs) for (const auto &x : xs) #define FORI(i, v) for (auto i = v.begin(); i != v.end(); i++) #define ALL(v) v.begin(), v.end() #define CHMIN(x, y) x = min(x, y) #define CHMAX(x, y) x = max(x, y) #define YES(b) cout << ((b) ? "YES" : "NO") << endl #define Yes(b) cout << ((b) ? "Yes" : "No") << endl #define DOUBLE(d) cout << fixed << setprecision(15) << (d) << endl int N; void build(int k) { cout << k << endl; vvi ans(N); int x = 1; REP(i, k) FOR(j, i + 1, k) { ans[i].push_back(x); ans[j].push_back(x); x++; } REP(i, k) { cout << k - 1; FORE(x, ans[i]) cout << " " << x; cout << endl; } } void solve() { REP(k, N + 10) { if (k * (k - 1) / 2 == N) { cout << "Yes" << endl; build(k); return; } else if (k * (k - 1) / 2 > N) { cout << "No" << endl; return; } } } int main() { cin >> N; solve(); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll, ll> ii; typedef tuple<ll, ll, ll> iii; typedef vector<ll> vi; typedef vector<ii> vii; typedef vector<iii> viii; typedef vector<vi> vvi; typedef vector<vii> vvii; #define REP(i, n) for (ll i = 0; i < n; ++i) #define REPR(i, n) for (ll i = n - 1; i >= 0; --i) #define FOR(i, m, n) for (ll i = m; i < n; ++i) #define FORR(i, m, n) for (ll i = n - 1; i >= m; --i) #define FORE(x, xs) for (const auto &x : xs) #define FORI(i, v) for (auto i = v.begin(); i != v.end(); i++) #define ALL(v) v.begin(), v.end() #define CHMIN(x, y) x = min(x, y) #define CHMAX(x, y) x = max(x, y) #define YES(b) cout << ((b) ? "YES" : "NO") << endl #define Yes(b) cout << ((b) ? "Yes" : "No") << endl #define DOUBLE(d) cout << fixed << setprecision(15) << (d) << endl int N; void build(int k) { cout << k << endl; vvi ans(k); int x = 1; REP(i, k) FOR(j, i + 1, k) { ans[i].push_back(x); ans[j].push_back(x); x++; } REP(i, k) { cout << k - 1; FORE(x, ans[i]) cout << " " << x; cout << endl; } } void solve() { REP(k, N + 10) { if (k * (k - 1) / 2 == N) { cout << "Yes" << endl; build(k); return; } else if (k * (k - 1) / 2 > N) { cout << "No" << endl; return; } } } int main() { cin >> N; solve(); }
replace
29
30
29
30
0
p03230
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int k = 2; while (k * (k - 1) / 2 < n) k++; if (k * (k - 1) / 2 != n) { cout << "No" << endl; return 0; } int a[400][400]; int b[400]; for (int i = 1; i <= k; i++) b[i] = 0; int x = 1; for (int i = 1; i <= k; i++) { for (int j = i + 1; j <= k; j++) { a[i][b[i]] = x; b[i]++; a[j][b[j]] = x; b[j]++; x++; } } cout << "Yes" << endl; cout << k << endl; for (int i = 1; i <= k; i++) { cout << k - 1 << " "; for (int j = 0; j < k - 1; j++) { cout << a[i][j]; if (j == k - 2) cout << endl; else cout << " "; } } }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int k = 2; while (k * (k - 1) / 2 < n) k++; if (k * (k - 1) / 2 != n) { cout << "No" << endl; return 0; } int a[500][500]; int b[500]; for (int i = 1; i <= k; i++) b[i] = 0; int x = 1; for (int i = 1; i <= k; i++) { for (int j = i + 1; j <= k; j++) { a[i][b[i]] = x; b[i]++; a[j][b[j]] = x; b[j]++; x++; } } cout << "Yes" << endl; cout << k << endl; for (int i = 1; i <= k; i++) { cout << k - 1 << " "; for (int j = 0; j < k - 1; j++) { cout << a[i][j]; if (j == k - 2) cout << endl; else cout << " "; } } }
replace
15
17
15
17
0
p03230
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define vll vector<ll> #define all(a) (a).begin(), (a).end() #define lol 1000000007 #define rep(i, a, b) for (int i = a; i < b; i++) #define SIZE 1000005 #define debug(x) cerr << #x << " = " << x << endl; #define F first #define S second #define endl '\n' #define deci(n) cout << fixed << setprecision(n); const double pi = acos(-1.0); using namespace std; void MOD(ll &x) { if (x >= lol) x -= lol; if (x < 0) x += lol; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } void solve() { int n; cin >> n; int k; rep(i, 1, n + 1) { int num = i * (i - 1); num /= 2; if (num == n) { k = i; break; } else if (num > n) { cout << "No"; return; } } vi ans[k]; int curr = 1; rep(i, 1, k + 1) { rep(j, i + 1, k + 1) { ans[i - 1].pb(curr); ans[j - 1].pb(curr++); } } cout << "Yes" << endl; cout << k << endl; rep(i, 0, k) { cout << k - 1 << " "; rep(j, 0, k - 1) cout << ans[i][j] << " "; cout << endl; } } // Remove debugs!! int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif int t = 1; // cin>>t; int i=1; while (t--) { // cout<<"Case #"<<i++<<": "; solve(); // cout<<endl; } return 0; }
#include <bits/stdc++.h> #define ll long long #define pb push_back #define mp make_pair #define pii pair<int, int> #define vi vector<int> #define vll vector<ll> #define all(a) (a).begin(), (a).end() #define lol 1000000007 #define rep(i, a, b) for (int i = a; i < b; i++) #define SIZE 1000005 #define debug(x) cerr << #x << " = " << x << endl; #define F first #define S second #define endl '\n' #define deci(n) cout << fixed << setprecision(n); const double pi = acos(-1.0); using namespace std; void MOD(ll &x) { if (x >= lol) x -= lol; if (x < 0) x += lol; } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } void solve() { int n; cin >> n; int k; rep(i, 1, n + 2) { int num = i * (i - 1); num /= 2; if (num == n) { k = i; break; } else if (num > n) { cout << "No"; return; } } vi ans[k]; int curr = 1; rep(i, 1, k + 1) { rep(j, i + 1, k + 1) { ans[i - 1].pb(curr); ans[j - 1].pb(curr++); } } cout << "Yes" << endl; cout << k << endl; rep(i, 0, k) { cout << k - 1 << " "; rep(j, 0, k - 1) cout << ans[i][j] << " "; cout << endl; } } // Remove debugs!! int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); // #ifndef ONLINE_JUDGE // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); // #endif int t = 1; // cin>>t; int i=1; while (t--) { // cout<<"Case #"<<i++<<": "; solve(); // cout<<endl; } return 0; }
replace
34
35
34
35
0
p03230
C++
Runtime Error
// #includes {{{ #include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define RREP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define LET(x, a) __typeof(a) x(a) // #define IFOR(i,it,c) // for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i) #define ALL(c) (c).begin(), (c).end() #define MP make_pair #define EXIST(e, s) ((s).find(e) != (s).end()) #define RESET(a) memset((a), 0, sizeof(a)) #define SET(a) memset((a), -1, sizeof(a)) #define PB push_back #define DEC(it, command) __typeof(command) it = command // debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; #define debug_v(x) \ cerr << #x << " = ["; \ REP(__ind, (x).size()) { cerr << (x)[__ind] << ", "; } \ cerr << "] (L" << __LINE__ << ")" << endl; #define whole(f, x, ...) \ ([&](decltype((x)) whole) { \ return (f)(begin(whole), end(whole), ##__VA_ARGS__); \ })(x) typedef long long Int; typedef unsigned long long uInt; typedef long double rn; template <class T> T inf() { return numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : (numeric_limits<T>::max() / 2); } typedef pair<int, int> pii; /* #ifdef MYDEBUG #include"debug.h" #include"print.h" #endif */ // }}} //{{{ io FILE *file_in = stdin, *file_out = stdout; #define fin normal_in #define fout normal_out // const char fname[]=""; // FILE *fin=fopen(fname,"r"),*fout=fopen(fname,"w"); #ifdef __MINGW32__ #define LLD "%I64d" #define LLU "%I64u" #else #define LLD "%lld" #define LLU "%llu" #endif struct NORMAL_IN { bool cnt; NORMAL_IN() : cnt(true) {} operator int() const { return cnt; } #define endl "\n" NORMAL_IN &operator>>(int &n) { cnt = fscanf(file_in, "%d", &n) != EOF; return *this; } NORMAL_IN &operator>>(unsigned int &n) { cnt = fscanf(file_in, "%u", &n) != EOF; return *this; } NORMAL_IN &operator>>(long long &n) { cnt = fscanf(file_in, LLD, &n) != EOF; return *this; } NORMAL_IN &operator>>(unsigned long long &n) { cnt = fscanf(file_in, LLU, &n) != EOF; return *this; } NORMAL_IN &operator>>(double &n) { cnt = fscanf(file_in, "%lf", &n) != EOF; return *this; } NORMAL_IN &operator>>(long double &n) { cnt = fscanf(file_in, "%Lf", &n) != EOF; return *this; } NORMAL_IN &operator>>(char *c) { cnt = fscanf(file_in, "%s", c) != EOF; return *this; } NORMAL_IN &operator>>(string &s) { s.clear(); for (bool r = false;;) { const char c = getchar(); if (c == EOF) { cnt = false; break; } const int t = isspace(c); if (!r and !t) r = true; if (r) { if (!t) s.push_back(c); else break; } } return *this; } template <class T> NORMAL_IN &operator>>(vector<T> &v) { int v_size = v.size(); REP(i, v_size) { *this >> v[i]; } return *this; } } normal_in; struct NORMAL_OUT { NORMAL_OUT &operator<<(const int &n) { fprintf(file_out, "%d", n); return *this; } NORMAL_OUT &operator<<(const unsigned int &n) { fprintf(file_out, "%u", n); return *this; } NORMAL_OUT &operator<<(const long long &n) { fprintf(file_out, LLD, n); return *this; } NORMAL_OUT &operator<<(const unsigned long long &n) { fprintf(file_out, LLU, n); return *this; } NORMAL_OUT &operator<<(const double &n) { fprintf(file_out, "%lf", n); return *this; } NORMAL_OUT &operator<<(const long double &n) { fprintf(file_out, "%Lf", n); return *this; } NORMAL_OUT &operator<<(const char c[]) { fprintf(file_out, "%s", c); return *this; } NORMAL_OUT &operator<<(const string &s) { fprintf(file_out, "%s", s.c_str()); return *this; } } normal_out; struct ERR_OUT { template <class T> ERR_OUT &operator<<(const T &a) { cerr << "\x1b[7m" << a << "\x1b[m"; return *this; } } ferr; //}}} Int N; void solve() { Int k; for (k = 1;; k++) { Int N2 = k * (k - 1) / 2; if (N2 == N) break; else if (N2 > N) { fout << "No" << endl; return; } } fout << "Yes" << endl; fout << k << endl; vector<vector<int>> v(k); int t = 1; REP(i, N) for (int j = i + 1; j < N; j++) { v[i].push_back(t); v[j].push_back(t); t++; } REP(i, v.size()) { fout << (int)v[i].size() << " "; REP(j, v[i].size()) { fout << v[i][j] << " "; } fout << endl; } } //{{{ main function int main() { fin >> N; solve(); return 0; } //}}}
// #includes {{{ #include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); ++i) #define RREP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define LET(x, a) __typeof(a) x(a) // #define IFOR(i,it,c) // for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i) #define ALL(c) (c).begin(), (c).end() #define MP make_pair #define EXIST(e, s) ((s).find(e) != (s).end()) #define RESET(a) memset((a), 0, sizeof(a)) #define SET(a) memset((a), -1, sizeof(a)) #define PB push_back #define DEC(it, command) __typeof(command) it = command // debug #define dump(x) cerr << #x << " = " << (x) << endl; #define debug(x) \ cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \ << " " << __FILE__ << endl; #define debug_v(x) \ cerr << #x << " = ["; \ REP(__ind, (x).size()) { cerr << (x)[__ind] << ", "; } \ cerr << "] (L" << __LINE__ << ")" << endl; #define whole(f, x, ...) \ ([&](decltype((x)) whole) { \ return (f)(begin(whole), end(whole), ##__VA_ARGS__); \ })(x) typedef long long Int; typedef unsigned long long uInt; typedef long double rn; template <class T> T inf() { return numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : (numeric_limits<T>::max() / 2); } typedef pair<int, int> pii; /* #ifdef MYDEBUG #include"debug.h" #include"print.h" #endif */ // }}} //{{{ io FILE *file_in = stdin, *file_out = stdout; #define fin normal_in #define fout normal_out // const char fname[]=""; // FILE *fin=fopen(fname,"r"),*fout=fopen(fname,"w"); #ifdef __MINGW32__ #define LLD "%I64d" #define LLU "%I64u" #else #define LLD "%lld" #define LLU "%llu" #endif struct NORMAL_IN { bool cnt; NORMAL_IN() : cnt(true) {} operator int() const { return cnt; } #define endl "\n" NORMAL_IN &operator>>(int &n) { cnt = fscanf(file_in, "%d", &n) != EOF; return *this; } NORMAL_IN &operator>>(unsigned int &n) { cnt = fscanf(file_in, "%u", &n) != EOF; return *this; } NORMAL_IN &operator>>(long long &n) { cnt = fscanf(file_in, LLD, &n) != EOF; return *this; } NORMAL_IN &operator>>(unsigned long long &n) { cnt = fscanf(file_in, LLU, &n) != EOF; return *this; } NORMAL_IN &operator>>(double &n) { cnt = fscanf(file_in, "%lf", &n) != EOF; return *this; } NORMAL_IN &operator>>(long double &n) { cnt = fscanf(file_in, "%Lf", &n) != EOF; return *this; } NORMAL_IN &operator>>(char *c) { cnt = fscanf(file_in, "%s", c) != EOF; return *this; } NORMAL_IN &operator>>(string &s) { s.clear(); for (bool r = false;;) { const char c = getchar(); if (c == EOF) { cnt = false; break; } const int t = isspace(c); if (!r and !t) r = true; if (r) { if (!t) s.push_back(c); else break; } } return *this; } template <class T> NORMAL_IN &operator>>(vector<T> &v) { int v_size = v.size(); REP(i, v_size) { *this >> v[i]; } return *this; } } normal_in; struct NORMAL_OUT { NORMAL_OUT &operator<<(const int &n) { fprintf(file_out, "%d", n); return *this; } NORMAL_OUT &operator<<(const unsigned int &n) { fprintf(file_out, "%u", n); return *this; } NORMAL_OUT &operator<<(const long long &n) { fprintf(file_out, LLD, n); return *this; } NORMAL_OUT &operator<<(const unsigned long long &n) { fprintf(file_out, LLU, n); return *this; } NORMAL_OUT &operator<<(const double &n) { fprintf(file_out, "%lf", n); return *this; } NORMAL_OUT &operator<<(const long double &n) { fprintf(file_out, "%Lf", n); return *this; } NORMAL_OUT &operator<<(const char c[]) { fprintf(file_out, "%s", c); return *this; } NORMAL_OUT &operator<<(const string &s) { fprintf(file_out, "%s", s.c_str()); return *this; } } normal_out; struct ERR_OUT { template <class T> ERR_OUT &operator<<(const T &a) { cerr << "\x1b[7m" << a << "\x1b[m"; return *this; } } ferr; //}}} Int N; void solve() { Int k; for (k = 1;; k++) { Int N2 = k * (k - 1) / 2; if (N2 == N) break; else if (N2 > N) { fout << "No" << endl; return; } } fout << "Yes" << endl; fout << k << endl; vector<vector<int>> v(k); int t = 1; REP(i, k) for (int j = i + 1; j < k; j++) { v[i].push_back(t); v[j].push_back(t); t++; } REP(i, v.size()) { fout << (int)v[i].size() << " "; REP(j, v[i].size()) { fout << v[i][j] << " "; } fout << endl; } } //{{{ main function int main() { fin >> N; solve(); return 0; } //}}}
replace
187
188
187
188
0
p03230
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <vector> using namespace std; int N; vector<int> s[200]; int main() { int k; while (cin >> N) { k = 1; while ((k * k - k) < 2 * N) k++; if ((k * k - k) == 2 * N) { for (int i = 0; i < k; i++) s[i].clear(); cout << "Yes" << endl; cout << k << endl; int num = 1; for (int i = 0; i < k; i++) { for (int j = i + 1; j < k; j++) { s[i].push_back(num); s[j].push_back(num); num++; } } int l = s[0].size(); for (int i = 0; i < k; i++) { cout << k - 1; for (int j = 0; j < l; j++) cout << ' ' << s[i][j]; cout << endl; } } else { cout << "No" << endl; } } return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #include <vector> using namespace std; int N; vector<int> s[1000]; int main() { int k; while (cin >> N) { k = 1; while ((k * k - k) < 2 * N) k++; if ((k * k - k) == 2 * N) { for (int i = 0; i < k; i++) s[i].clear(); cout << "Yes" << endl; cout << k << endl; int num = 1; for (int i = 0; i < k; i++) { for (int j = i + 1; j < k; j++) { s[i].push_back(num); s[j].push_back(num); num++; } } int l = s[0].size(); for (int i = 0; i < k; i++) { cout << k - 1; for (int j = 0; j < l; j++) cout << ' ' << s[i][j]; cout << endl; } } else { cout << "No" << endl; } } return 0; }
replace
8
9
8
9
0
p03230
C++
Runtime Error
/* Author:zeke pass System Test! GET AC!! */ #include <algorithm> #include <cassert> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using ll = long long; using ld = long double; using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var)) #define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var)) #define Mp(a, b) make_pair((a), (b)) #define F first #define S second #define Icin(s) \ ll(s); \ cin >> (s); #define Scin(s) \ ll(s); \ cin >> (s); 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; } typedef pair<ll, ll> P; typedef vector<ll> V; typedef vector<V> VV; typedef vector<P> VP; ll MOD = 1e9 + 7; ll INF = 1e18; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; ll m = n * 2; bool h = false; ll res; rep3(i, 1, sqrt(m)) { if (m % i == 0) { if (abs(m / i - i) == 1) { h = true; res = i; break; } } } if (!h) { cout << "No" << endl; return 0; } cout << "Yes" << endl; ll temp = 0; VV Res(n + 1, V(n)); cout << res + 1 << endl; rep(i, res + 1) { rep(j, res) { if (i - (j + 1) >= 0) { Res[i][j] = Res[i - (j + 1)][i - 1]; } else { temp++; Res[i][j] = temp; } } } rep(i, res + 1) { cout << res << " "; rep(j, res) { cout << Res[i][j] << " "; } cout << endl; } }
/* Author:zeke pass System Test! GET AC!! */ #include <algorithm> #include <cassert> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using ll = long long; using ld = long double; using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() #define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var)) #define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var)) #define Mp(a, b) make_pair((a), (b)) #define F first #define S second #define Icin(s) \ ll(s); \ cin >> (s); #define Scin(s) \ ll(s); \ cin >> (s); 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; } typedef pair<ll, ll> P; typedef vector<ll> V; typedef vector<V> VV; typedef vector<P> VP; ll MOD = 1e9 + 7; ll INF = 1e18; int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; ll m = n * 2; bool h = false; ll res; rep3(i, 1, sqrt(m)) { if (m % i == 0) { if (abs(m / i - i) == 1) { h = true; res = i; break; } } } if (!h) { cout << "No" << endl; return 0; } cout << "Yes" << endl; ll temp = 0; VV Res(res + 1, V(res)); cout << res + 1 << endl; rep(i, res + 1) { rep(j, res) { if (i - (j + 1) >= 0) { Res[i][j] = Res[i - (j + 1)][i - 1]; } else { temp++; Res[i][j] = temp; } } } rep(i, res + 1) { cout << res << " "; rep(j, res) { cout << Res[i][j] << " "; } cout << endl; } }
replace
79
80
79
80
0
p03230
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define reps(i, A, n) for (int(i) = (A); (i) < (n); (i)++) #define pb emplace_back using LL = long long; const LL MOD = 1e9 + 7; int N; int K; vector<int> S[114514]; int main() { scanf("%d", &N); reps(k, 1, N + 1) { if (k * (k - 1) > 2 * N) { puts("No"); return 0; } if (k * (k - 1) == 2 * N) { K = k; break; } } int cnt = 0; rep(i, K) { reps(j, i + 1, K) { ++cnt; S[i].pb(cnt); S[j].pb(cnt); } } assert(cnt == N); printf("Yes\n%d\n", K); rep(i, K) { printf("%d", (int)S[i].size()); for (int v : S[i]) { printf(" %d", v); } puts(""); } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int(i) = 0; (i) < (n); (i)++) #define reps(i, A, n) for (int(i) = (A); (i) < (n); (i)++) #define pb emplace_back using LL = long long; const LL MOD = 1e9 + 7; int N; int K; vector<int> S[114514]; int main() { scanf("%d", &N); reps(k, 1, N + 11) { if (k * (k - 1) > 2 * N) { puts("No"); return 0; } if (k * (k - 1) == 2 * N) { K = k; break; } } int cnt = 0; rep(i, K) { reps(j, i + 1, K) { ++cnt; S[i].pb(cnt); S[j].pb(cnt); } } assert(cnt == N); printf("Yes\n%d\n", K); rep(i, K) { printf("%d", (int)S[i].size()); for (int v : S[i]) { printf(" %d", v); } puts(""); } }
replace
16
17
16
17
0
p03230
C++
Runtime Error
#include <bits/stdc++.h> #include <stdio.h> using namespace std; #define REP(i, a, b) for (int i = (a), _end_ = (b); i < _end_; ++i) #define debug(...) fprintf(stderr, __VA_ARGS__) #define X first #define Y second #define mp make_pair #define eb emplace_back #define SZ(x) (int((x).size())) #define ALL(x) (x).begin(), (x).end() template <typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } typedef long long LL; typedef long double LD; typedef pair<int, int> pii; typedef unsigned long long uLL; template <typename T> inline void Read(T &x) { char c = getchar(); bool f = false; for (x = 0; !isdigit(c); c = getchar()) { if (c == '-') { f = true; } } for (; isdigit(c); c = getchar()) { x = x * 10 + c - '0'; } if (f) { x = -x; } } const int MAX_N = 1e5 + 5; const int INF = 0x3f3f3f3f; int G[500][500]; int main() { #ifdef ANONYM freopen("in", "r", stdin); freopen("out", "w", stdout); #endif int n; Read(n); set<int> s; for (int i = 1; i < 500; i++) s.insert(i * (i - 1) / 2); if (n == 1) { puts("Yes"); printf("2\n"); printf("1 1\n"); printf("1 1\n"); } else if (s.find(n) != s.end()) { puts("Yes"); int k = int(sqrt(n * (n - 1))) + 1; printf("%d\n", k); int cnt = 0; for (int i = 1; i <= k; i++) { for (int j = 1; j <= k; j++) { if (i != j && !G[i][j] && !G[j][i]) { G[i][j] = G[j][i] = ++cnt; } } } for (int i = 1; i <= k; i++) { printf("%d", k - 1); for (int j = 1; j <= k; j++) { if (i != j) printf(" %d", G[i][j]); } puts(""); } } else puts("No"); return 0; }
#include <bits/stdc++.h> #include <stdio.h> using namespace std; #define REP(i, a, b) for (int i = (a), _end_ = (b); i < _end_; ++i) #define debug(...) fprintf(stderr, __VA_ARGS__) #define X first #define Y second #define mp make_pair #define eb emplace_back #define SZ(x) (int((x).size())) #define ALL(x) (x).begin(), (x).end() template <typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } typedef long long LL; typedef long double LD; typedef pair<int, int> pii; typedef unsigned long long uLL; template <typename T> inline void Read(T &x) { char c = getchar(); bool f = false; for (x = 0; !isdigit(c); c = getchar()) { if (c == '-') { f = true; } } for (; isdigit(c); c = getchar()) { x = x * 10 + c - '0'; } if (f) { x = -x; } } const int MAX_N = 1e5 + 5; const int INF = 0x3f3f3f3f; int G[500][500]; int main() { #ifdef ANONYM freopen("in", "r", stdin); freopen("out", "w", stdout); #endif int n; Read(n); set<int> s; for (int i = 1; i < 500; i++) s.insert(i * (i - 1) / 2); if (n == 1) { puts("Yes"); printf("2\n"); printf("1 1\n"); printf("1 1\n"); } else if (s.find(n) != s.end()) { puts("Yes"); int k = int(sqrt(n * 2)) + 1; printf("%d\n", k); int cnt = 0; for (int i = 1; i <= k; i++) { for (int j = 1; j <= k; j++) { if (i != j && !G[i][j] && !G[j][i]) { G[i][j] = G[j][i] = ++cnt; } } } for (int i = 1; i <= k; i++) { printf("%d", k - 1); for (int j = 1; j <= k; j++) { if (i != j) printf(" %d", G[i][j]); } puts(""); } } else puts("No"); return 0; }
replace
63
64
63
64
0
p03230
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; int A = 1; while (A * (A - 1) / 2 < N) ++A; if (A * (A - 1) / 2 > N) { cout << "No" << endl; } else { cout << "Yes" << endl; vector<vector<int>> G(N); int cnt = 0; for (int i = 0; i < A; ++i) { for (int j = 0; j < i; ++j) { ++cnt; G[i].push_back(cnt); G[j].push_back(cnt); } } cout << A << endl; for (int i = 0; i < A; ++i) { cout << G[i].size(); for (int j : G[i]) { cout << ' ' << j; } cout << endl; } } return 0; }
#include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; int A = 1; while (A * (A - 1) / 2 < N) ++A; if (A * (A - 1) / 2 > N) { cout << "No" << endl; } else { cout << "Yes" << endl; vector<vector<int>> G(A); int cnt = 0; for (int i = 0; i < A; ++i) { for (int j = 0; j < i; ++j) { ++cnt; G[i].push_back(cnt); G[j].push_back(cnt); } } cout << A << endl; for (int i = 0; i < A; ++i) { cout << G[i].size(); for (int j : G[i]) { cout << ' ' << j; } cout << endl; } } return 0; }
replace
13
14
13
14
0
p03230
C++
Runtime Error
#include <algorithm> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; using ll = long long; using ld = long double; int main() { int N; cin >> N; if (N == 1) { cout << "Yes" << endl; cout << 2 << endl; cout << "1 1" << endl; cout << "1 1" << endl; return 0; } int x = 0; int k = 0; vector<int> X; for (int i = 1; i < N; ++i) { x += i; X.push_back(x); if (x == N) { k = i; break; } if (x > N) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; cout << k + 1 << endl; vector<vector<int>> R; for (int i = 0; i < k + 1; ++i) { vector<int> v; R.push_back(v); } R[0].push_back(1); R[1].push_back(1); for (int i = 0; i < X.size() - 1; ++i) { int x = X[i]; int x2 = X[i + 1]; for (int j = x + 1; j <= x2; ++j) { R[j - (x + 1)].push_back(j); R[2 + i].push_back(j); } } for (int i = 0; i < k + 1; ++i) { cout << k; for (int j = 0; j < k; ++j) { cout << " " << R[i][j]; } cout << endl; } return 0; }
#include <algorithm> #include <iostream> #include <map> #include <string> #include <vector> using namespace std; using ll = long long; using ld = long double; int main() { int N; cin >> N; if (N == 1) { cout << "Yes" << endl; cout << 2 << endl; cout << "1 1" << endl; cout << "1 1" << endl; return 0; } int x = 0; int k = 0; vector<int> X; for (int i = 1; i <= N; ++i) { x += i; X.push_back(x); if (x == N) { k = i; break; } if (x > N) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; cout << k + 1 << endl; vector<vector<int>> R; for (int i = 0; i < k + 1; ++i) { vector<int> v; R.push_back(v); } R[0].push_back(1); R[1].push_back(1); for (int i = 0; i < X.size() - 1; ++i) { int x = X[i]; int x2 = X[i + 1]; for (int j = x + 1; j <= x2; ++j) { R[j - (x + 1)].push_back(j); R[2 + i].push_back(j); } } for (int i = 0; i < k + 1; ++i) { cout << k; for (int j = 0; j < k; ++j) { cout << " " << R[i][j]; } cout << endl; } return 0; }
replace
25
26
25
26
0
p03230
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ll long long #define ld long double int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; } // 最大公約数 ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } // 最小公倍数 using Graph = vector<vector<ll>>; ll inf = 300000000000000000; const double PI = 3.14159265358979323846; const int MAX = 510000; const ll MOD = 1000000007; int main() { int n; cin >> n; int u = 1; while (u * (u - 1) / 2 < n) { u++; } if (u * (u - 1) / 2 != n) { cout << "No" << endl; return 0; } Graph ans(u); int l = 0, r = 1; rep(i, n) { ans.at(l).push_back(i + 1); ans.at(r).push_back(i + 1); if (r != n - 1) r++; else { l++; r = l + 1; } } cout << "Yes" << endl; cout << u << endl; rep(i, u) { cout << u - 1 << " "; rep(j, u - 2) cout << ans.at(i).at(j) << " "; cout << ans.at(i).at(u - 2) << endl; } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ll long long #define ld long double int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; } // 最大公約数 ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } // 最小公倍数 using Graph = vector<vector<ll>>; ll inf = 300000000000000000; const double PI = 3.14159265358979323846; const int MAX = 510000; const ll MOD = 1000000007; int main() { int n; cin >> n; int u = 1; while (u * (u - 1) / 2 < n) { u++; } if (u * (u - 1) / 2 != n) { cout << "No" << endl; return 0; } Graph ans(u); int l = 0, r = 1; rep(i, n) { ans.at(l).push_back(i + 1); ans.at(r).push_back(i + 1); if (r != u - 1) r++; else { l++; r = l + 1; } } cout << "Yes" << endl; cout << u << endl; rep(i, u) { cout << u - 1 << " "; rep(j, u - 2) cout << ans.at(i).at(j) << " "; cout << ans.at(i).at(u - 2) << endl; } }
replace
28
29
28
29
0
p03230
C++
Runtime Error
#include <algorithm> #include <bitset> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; typedef long double ld; const ll INF = 1e+14; typedef pair<int, int> P; #define stop \ char nyaa; \ cin >> nyaa; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; #define fr first #define sc second #define all(c) c.begin(), c.end() #define pb push_back void Yes() { cout << "Yes" << endl; exit(0); } void No() { cout << "No" << endl; exit(0); } int main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; int n = 2 * N, k = -1; for (int i = 1; i * i <= n; i++) { if (n % i == 0) { if (i + 1 == n / i) { k = i + 1; } } } if (k == -1) No(); cout << "Yes" << endl; cout << k << endl; vector<int> S[400]; int u = 0, d = 1; rep1(i, N) { S[u].pb(i); S[d].pb(i); d++; if (d == k) { u++; d = u + 1; } } rep(i, k) { cout << k - 1 << " "; rep(j, k - 1) { cout << S[i][j] << " "; } cout << endl; } return 0; }
#include <algorithm> #include <bitset> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; typedef long double ld; const ll INF = 1e+14; typedef pair<int, int> P; #define stop \ char nyaa; \ cin >> nyaa; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) typedef complex<ld> Point; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ld, ld> LDP; typedef pair<ll, ll> LP; #define fr first #define sc second #define all(c) c.begin(), c.end() #define pb push_back void Yes() { cout << "Yes" << endl; exit(0); } void No() { cout << "No" << endl; exit(0); } int main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; int n = 2 * N, k = -1; for (int i = 1; i * i <= n; i++) { if (n % i == 0) { if (i + 1 == n / i) { k = i + 1; } } } if (k == -1) No(); cout << "Yes" << endl; cout << k << endl; vector<int> S[1000]; int u = 0, d = 1; rep1(i, N) { S[u].pb(i); S[d].pb(i); d++; if (d == k) { u++; d = u + 1; } } rep(i, k) { cout << k - 1 << " "; rep(j, k - 1) { cout << S[i][j] << " "; } cout << endl; } return 0; }
replace
72
73
72
73
0