結果
問題 | No.1290 Addition and Subtraction Operation |
ユーザー | pazzle1230 |
提出日時 | 2020-11-13 23:14:28 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 4,615 bytes |
コンパイル時間 | 2,851 ms |
コンパイル使用メモリ | 211,700 KB |
実行使用メモリ | 43,636 KB |
最終ジャッジ日時 | 2024-07-22 22:11:28 |
合計ジャッジ時間 | 17,915 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | WA | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | WA | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | WA | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | WA | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | RE | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | RE | - |
testcase_31 | RE | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | RE | - |
testcase_37 | RE | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | RE | - |
testcase_41 | WA | - |
testcase_42 | RE | - |
testcase_43 | RE | - |
testcase_44 | RE | - |
testcase_45 | RE | - |
testcase_46 | RE | - |
testcase_47 | RE | - |
testcase_48 | RE | - |
testcase_49 | RE | - |
testcase_50 | RE | - |
testcase_51 | RE | - |
testcase_52 | RE | - |
testcase_53 | RE | - |
testcase_54 | RE | - |
testcase_55 | RE | - |
testcase_56 | RE | - |
testcase_57 | WA | - |
testcase_58 | WA | - |
testcase_59 | WA | - |
testcase_60 | WA | - |
testcase_61 | WA | - |
testcase_62 | WA | - |
testcase_63 | WA | - |
testcase_64 | WA | - |
testcase_65 | WA | - |
testcase_66 | WA | - |
testcase_67 | WA | - |
testcase_68 | WA | - |
testcase_69 | WA | - |
testcase_70 | WA | - |
testcase_71 | WA | - |
testcase_72 | WA | - |
testcase_73 | WA | - |
testcase_74 | WA | - |
testcase_75 | WA | - |
testcase_76 | WA | - |
testcase_77 | RE | - |
testcase_78 | RE | - |
testcase_79 | RE | - |
testcase_80 | RE | - |
testcase_81 | RE | - |
testcase_82 | WA | - |
testcase_83 | WA | - |
testcase_84 | WA | - |
testcase_85 | WA | - |
testcase_86 | WA | - |
ソースコード
#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; vector<int> ord(mat.size()); iota(all(ord), ord.size()); sort(all(ord), [&](int x, int y) { return mat[x].size() < mat[y].size(); }); for (int i = M-1; i >= 0; i--) { 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; }