結果
問題 | No.1290 Addition and Subtraction Operation |
ユーザー | pazzle1230 |
提出日時 | 2020-11-13 23:10:59 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 4,447 bytes |
コンパイル時間 | 2,502 ms |
コンパイル使用メモリ | 207,932 KB |
実行使用メモリ | 6,940 KB |
最終ジャッジ日時 | 2024-07-22 22:03:48 |
合計ジャッジ時間 | 7,215 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | TLE | - |
testcase_04 | -- | - |
testcase_05 | -- | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
testcase_36 | -- | - |
testcase_37 | -- | - |
testcase_38 | -- | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
testcase_48 | -- | - |
testcase_49 | -- | - |
testcase_50 | -- | - |
testcase_51 | -- | - |
testcase_52 | -- | - |
testcase_53 | -- | - |
testcase_54 | -- | - |
testcase_55 | -- | - |
testcase_56 | -- | - |
testcase_57 | -- | - |
testcase_58 | -- | - |
testcase_59 | -- | - |
testcase_60 | -- | - |
testcase_61 | -- | - |
testcase_62 | -- | - |
testcase_63 | -- | - |
testcase_64 | -- | - |
testcase_65 | -- | - |
testcase_66 | -- | - |
testcase_67 | -- | - |
testcase_68 | -- | - |
testcase_69 | -- | - |
testcase_70 | -- | - |
testcase_71 | -- | - |
testcase_72 | -- | - |
testcase_73 | -- | - |
testcase_74 | -- | - |
testcase_75 | -- | - |
testcase_76 | -- | - |
testcase_77 | -- | - |
testcase_78 | -- | - |
testcase_79 | -- | - |
testcase_80 | -- | - |
testcase_81 | -- | - |
testcase_82 | -- | - |
testcase_83 | -- | - |
testcase_84 | -- | - |
testcase_85 | -- | - |
testcase_86 | -- | - |
ソースコード
#include <bits/stdc++.h> using namespace std; #define INF_LL (int64)1e18 #define INF (int32)1e9 #define REP(i, n) for(int64 i = 0;i < (n);i++) #define FOR(i, a, b) for(int64 i = (a);i < (b);i++) #define all(x) x.begin(),x.end() #define fs first #define sc second using int32 = int_fast32_t; using uint32 = uint_fast32_t; using int64 = int_fast64_t; using uint64 = uint_fast64_t; using PII = pair<int32, int32>; using PLL = pair<int64, int64>; const double eps = 1e-10; template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;} template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;} template<typename T> vector<T> make_v(size_t a){return vector<T>(a);} template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); } template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value!=0>::type fill_v(U &u,const V... v){u=U(v...);} template<typename T,typename U,typename... V> typename enable_if<is_same<T, U>::value==0>::type fill_v(U &u,const V... v){ for(auto &e:u) fill_v<T>(e,v...); } int64 N, X; vector<int64> A; using T = tuple<int, int64, int64>; map<PLL, int64> mp; int64 dfs(int i, int64 rem) { // cout << "call: " << i << " " << rem << endl; if (i == 0 && (N == 1 || abs(rem) < A[i+1])) { return 1; } if (mp.count({i, rem})) return mp[{i, rem}]; int64 res = 0; if (i == N-1 || rem < A[i+1]) { res += dfs(i - 1, rem % A[i]); if (rem % A[i] != 0 && (i == N-1 || rem + A[i] < A[i+1])) res += dfs(i - 1, A[i] - rem % A[i]); } return mp[{i, rem}] = res; } int main(void){ cin.tie(0); ios::sync_with_stdio(false); int64 N, M; cin >> N >> M; vector<int64> B(N+2, 0); REP(i, N) cin >> B[i+1]; vector<vector<int64>> L(N+2), R(N+2); vector<int> parity(M); REP(i, M) { int l, r; cin >> l >> r; r++; parity[i] = (r - l) % 2; L[l].push_back(i); R[r].push_back(i); } vector<map<int, double>> mat; vector<double> b; vector<set<int>> piv(M); FOR(i, 1, N+2) { if (L[i].size() == 0 && R[i].size() == 0 && B[i] * -1 != B[i-1]) { cout << i << " " << B[i] << " " << B[i-1] << endl; cout << "NO" << endl; return 0; } if (L[i].size() != 0 || R[i].size() != 0) { map<int, double> mp; REP(j, L[i].size()) { mp[L[i][j]] = 1; piv[L[i][j]].insert(mat.size()); } REP(j, R[i].size()) { mp[R[i][j]] = parity[R[i][j]] ? 1 : -1; piv[R[i][j]].insert(mat.size()); } mat.push_back(mp); b.push_back(B[i] * -1 - B[i - 1]); } } int rank = 0; auto swap_mat = [&](int r1, int r2) { swap(mat[r1], mat[r2]); swap(b[r1], b[r2]); for (auto &x : mat[r1]) { piv[x.first].erase(r2); piv[x.first].insert(r1); } for (auto &x : mat[r2]) { piv[x.first].erase(r1); piv[x.first].insert(r2); } }; auto add_mat = [&](int r2, int r1, double mul) { // mat[r2] += mat[r1] * mul for (auto &x : mat[r1]) { if (mat[r2][x.first] == 0) { piv[x.first].insert(r2); } mat[r2][x.first] += x.second * mul; if (mat[r2][x.first] == 0) { piv[x.first].erase(r2); mat[r2].erase(x.first); } } b[r2] += b[r1] * mul; }; // REP(i, mat.size()) { // for (auto &x : mat[i]) { // cout << "(" << x.first << " " << x.second << ") "; // } // cout << b[i] << endl; // } // cout << endl; REP(i, M) { if (piv[i].size() == 0) continue; bool will_do = 0; for (auto &x : piv[i]) { if (x < rank) continue; swap_mat(rank, x); will_do = 1; break; } if (!will_do) continue; // cout << rank << ": "; for (auto &x : piv[i]) { if (x <= rank) continue; // cout << x << " "; double mul = - mat[x][i] / mat[rank][i]; add_mat(x, rank, mul); } // cout << endl; // REP(i, mat.size()) { // for (auto &x : mat[i]) { // cout << "(" << x.first << " " << x.second << ") "; // } // cout << b[i] << endl; // } // cout << endl; rank++; } // REP(i, mat.size()) { // for (auto &x : mat[i]) { // cout << "(" << x.first << " " << x.second << ") "; // } // cout << b[i] << endl; // } REP(i, mat.size()) { bool ok = 1; for (auto &x : mat[i]) { if (abs(x.second) > eps) ok = 0; } if (ok && abs(b[i]) > eps) { cout << "NO" << endl; return 0; } } cout << "YES" << endl; }