結果
問題 | No.1502 Many Simple Additions |
ユーザー | milanis48663220 |
提出日時 | 2021-05-07 23:10:44 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,069 bytes |
コンパイル時間 | 1,175 ms |
コンパイル使用メモリ | 105,872 KB |
実行使用メモリ | 15,616 KB |
最終ジャッジ日時 | 2024-09-15 11:16:23 |
合計ジャッジ時間 | 3,598 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
5,760 KB |
testcase_01 | AC | 4 ms
5,760 KB |
testcase_02 | AC | 4 ms
5,888 KB |
testcase_03 | AC | 4 ms
5,760 KB |
testcase_04 | AC | 4 ms
5,888 KB |
testcase_05 | WA | - |
testcase_06 | AC | 4 ms
5,760 KB |
testcase_07 | WA | - |
testcase_08 | AC | 4 ms
5,888 KB |
testcase_09 | AC | 4 ms
5,760 KB |
testcase_10 | AC | 3 ms
5,888 KB |
testcase_11 | WA | - |
testcase_12 | AC | 4 ms
5,760 KB |
testcase_13 | AC | 4 ms
5,888 KB |
testcase_14 | AC | 4 ms
5,760 KB |
testcase_15 | AC | 4 ms
5,760 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 4 ms
5,760 KB |
testcase_25 | AC | 4 ms
5,760 KB |
testcase_26 | AC | 4 ms
5,760 KB |
testcase_27 | AC | 49 ms
12,416 KB |
testcase_28 | AC | 49 ms
12,928 KB |
testcase_29 | AC | 11 ms
7,424 KB |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | AC | 37 ms
9,344 KB |
testcase_37 | AC | 36 ms
9,344 KB |
testcase_38 | AC | 58 ms
12,168 KB |
testcase_39 | AC | 35 ms
9,344 KB |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | AC | 66 ms
13,568 KB |
testcase_43 | AC | 4 ms
5,888 KB |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <set> #include <map> #include <cassert> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << 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; } using namespace std; typedef long long ll; const ll MOD = 1000000007; class ModInt{ public: ll v; ModInt(ll _v = 0){ if(_v >= MOD) _v %= MOD; v = _v; } ModInt operator+(ll n){ return ModInt((v+n)%MOD); } ModInt operator-(ll n){ return ModInt((v-n+MOD)%MOD); } ModInt operator*(ll n){ if(n >= MOD) n %= MOD; return ModInt((v*n)%MOD); } ModInt operator/(ll n){ return ModInt((ModInt(n).inv()*v).v%MOD); } void operator+=(ll n){ v = (v+n)%MOD; } void operator-=(ll n){ v = (v-n+MOD)%MOD; } void operator*=(ll n){ v = (v*n+MOD)%MOD; } ModInt operator+(ModInt n){ return ModInt((v+n.v)%MOD); } ModInt operator-(ModInt n){ return ModInt((v-n.v+MOD)%MOD); } ModInt operator*(ModInt n){ return ModInt((v*n.v)%MOD); } ModInt operator/(ModInt n){ return ModInt((n.inv()*v).v%MOD); } void operator+=(ModInt n){ v = (v+n.v)%MOD; } void operator-=(ModInt n){ v = (v-n.v+MOD)%MOD; } void operator*=(ModInt n){ v = (v*n.v)%MOD; } void operator=(ModInt n){ v = n.v; } bool operator==(ModInt n){ return v == n.v; } bool operator!=(ModInt n){ return v != n.v; } void operator=(ll n){ v = n%MOD; } ModInt inv(){ if(v == 1) return ModInt(1); else return ModInt(MOD-ModInt(MOD%v).inv().v*(MOD/v)%MOD); } }; ostream& operator<<(ostream& os, const ModInt& m){ os << m.v; return os; } istream & operator >> (istream &in, ModInt &m){ in >> m.v; return in; } ModInt pow(ModInt a, ll n) { assert(n >= 0); ModInt ans = 1; ModInt tmp = a; for (int i = 0; i <= 60; i++) { ll m = (ll)1 << i; if (m & n) { ans *= tmp; } tmp *= tmp; } return ans; } struct edge{ int to; ll cost; }; using mint = ModInt; vector<edge> g[100000]; ll a[100000], b[100000]; bool used[100000]; bool ng; vector<int> visited; set<ll> cand; void dfs(int v){ visited.push_back(v); used[v] = true; for(edge e : g[v]){ if(used[e.to]) { if(a[v] == a[e.to]){ // 2*a[v]*x+b[v]+b[e.to] = e.cost if((e.cost-(b[v]+b[e.to]))%2 != 0) ng = true; else{ cand.insert((e.cost-b[v]-b[e.to])/(2*a[v])); } }else{ if(b[v]+b[e.to] != e.cost) ng = true; } }else{ a[e.to] = -a[v]; b[e.to] = e.cost-b[v]; dfs(e.to); } } } const ll INF = 1e15; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; ll n, m, k; cin >> n >> m >> k; for(int i = 0; i < m; i++){ int x, y; ll z; cin >> x >> y >> z; x--; y--; g[x].push_back(edge{y, z}); g[y].push_back(edge{x, z}); } auto clear = [&](){ visited.clear(); ng = false; }; auto f = [&](ll x, int v){ return a[v]*x+b[v]; }; mint n_all = 1, n_ng = 1; for(int i = 0; i < n; i++){ if(used[i]) continue; clear(); a[i] = 1; b[i] = 0; dfs(i); if(ng || cand.size() >= 2){ cout << 0 << endl; return 0; }else{ if(cand.empty()){ ll x_min = -INF, x_max = INF; for(int v : visited){ ll s = a[v]*(1-b[v]); ll t = a[v]*(k-b[v]); chmax(x_min, min(s, t)); chmin(x_max, max(s, t)); } set<ll> just; // cout << x_min << ' ' << x_max << endl; if(x_max < x_min){ cout << 0 << endl; return -1; } for(int v : visited){ ll x = (k-b[v])/a[v]; if(x_min <= x && x <= x_max) just.insert(x); } n_all *= x_max-x_min+1; n_ng *= x_max-x_min+1-just.size(); }else{ ll x = *cand.begin(); for(int v : visited){ if(f(x, v) < 1 || f(x, v) > k){ cout << 0 << endl; return 0; } if(f(x, v) == k) n_ng = 0; } } } } cout << n_all-n_ng << endl; }