結果

問題 No.1290 Addition and Subtraction Operation
ユーザー pazzle1230pazzle1230
提出日時 2020-11-13 23:03:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,365 bytes
コンパイル時間 2,561 ms
コンパイル使用メモリ 203,848 KB
実行使用メモリ 46,712 KB
最終ジャッジ日時 2023-09-30 04:01:27
合計ジャッジ時間 8,323 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 WA -
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,380 KB
testcase_16 WA -
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 WA -
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 WA -
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 1 ms
4,376 KB
testcase_35 WA -
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 1 ms
4,380 KB
testcase_41 WA -
testcase_42 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 r1, int r2, 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;

	  for (auto &x : piv[i]) {
	    if (x == rank) continue;

	    double mul = - mat[x][i] / mat[x][rank];
	    add_mat(x, rank, mul);
	  }
//    REP(i, mat.size()) {
//      for (auto &x : mat[i]) {
//        cout << "(" << x.first << " " << x.second << ") ";
//      }
//      cout << b[i] << endl;
//    }
//	  cout << endl;
	}
//	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;
}
0