結果
問題 | No.187 中華風 (Hard) |
ユーザー | kopricky |
提出日時 | 2019-09-25 18:48:56 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 60 ms / 3,000 ms |
コード長 | 4,457 bytes |
コンパイル時間 | 1,822 ms |
コンパイル使用メモリ | 183,008 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-22 12:13:55 |
合計ジャッジ時間 | 3,738 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
6,812 KB |
testcase_01 | AC | 38 ms
6,940 KB |
testcase_02 | AC | 52 ms
6,944 KB |
testcase_03 | AC | 53 ms
6,944 KB |
testcase_04 | AC | 59 ms
6,944 KB |
testcase_05 | AC | 60 ms
6,944 KB |
testcase_06 | AC | 60 ms
6,940 KB |
testcase_07 | AC | 59 ms
6,940 KB |
testcase_08 | AC | 48 ms
6,940 KB |
testcase_09 | AC | 49 ms
6,944 KB |
testcase_10 | AC | 48 ms
6,940 KB |
testcase_11 | AC | 59 ms
6,940 KB |
testcase_12 | AC | 59 ms
6,944 KB |
testcase_13 | AC | 38 ms
6,940 KB |
testcase_14 | AC | 37 ms
6,940 KB |
testcase_15 | AC | 52 ms
6,940 KB |
testcase_16 | AC | 52 ms
6,944 KB |
testcase_17 | AC | 2 ms
6,940 KB |
testcase_18 | AC | 32 ms
6,940 KB |
testcase_19 | AC | 2 ms
6,940 KB |
testcase_20 | AC | 50 ms
6,944 KB |
testcase_21 | AC | 2 ms
6,944 KB |
testcase_22 | AC | 60 ms
6,944 KB |
testcase_23 | AC | 2 ms
6,940 KB |
testcase_24 | AC | 2 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> #define ll long long #define INF 1000000005 #define MOD 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)(n);++i) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i) #define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i) #define each(a,b) for(auto& (a): (b)) #define all(v) (v).begin(),(v).end() #define len(v) (int)(v).size() #define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end()) #define cmx(x,y) x=max(x,y) #define cmn(x,y) x=min(x,y) #define fi first #define se second #define pb push_back #define show(x) cout<<#x<<" = "<<(x)<<endl #define sar(a,n) {cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl;} #define int long long using namespace std; template<typename S,typename T>auto&operator<<(ostream&o,pair<S,T>p){return o<<"{"<<p.fi<<","<<p.se<<"}";} template<typename T>auto&operator<<(ostream&o,set<T>s){for(auto&e:s)o<<e<<" ";return o;} template<typename S,typename T,typename U> auto&operator<<(ostream&o,priority_queue<S,T,U>q){while(!q.empty())o<<q.top()<<" ",q.pop();return o;} template<typename K,typename T>auto&operator<<(ostream&o,map<K,T>&m){for(auto&e:m)o<<e<<" ";return o;} template<typename T>auto&operator<<(ostream&o,vector<T>v){for(auto&e:v)o<<e<<" ";return o;} void ashow(){cout<<endl;}template<typename T,typename...A>void ashow(T t,A...a){cout<<t<<" ";ashow(a...);} template<typename S,typename T,typename U> struct TRI{S fi;T se;U th;TRI(){}TRI(S f,T s,U t):fi(f),se(s),th(t){} bool operator<(const TRI&_)const{return(fi==_.fi)?((se==_.se)?(th<_.th):(se<_.se)):(fi<_.fi);}}; template<typename S,typename T,typename U> auto&operator<<(ostream&o,TRI<S,T,U>&t){return o<<"{"<<t.fi<<","<<t.se<<","<<t.th<<"}";} typedef pair<int, int> P; typedef pair<ll, ll> pll; typedef TRI<int, int, int> tri; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef vector<P> vp; typedef vector<double> vd; typedef vector<string> vs; const int MAX_N = 32005; template<typename T> T mod_add(const T a, const T b, const T mod){ return (a + b) % mod; } template<typename T> T mod_mul(const T a, const T b, const T mod){ return a * b % mod; } template<typename T> T mod_pow(T a, T b, const T mod){ T res = 1; while(b){ if(b & 1){ res = mod_mul(res, a, mod); } a = mod_mul(a, a, mod); b >>= 1; } return res; } template<typename T> T mod_inv(T a, T mod){ T u[] = {a, 1, 0}, v[] = {mod, 0, 1}, t; while(*v){ t = *u / *v; swap(u[0] -= t * v[0], v[0]), swap(u[1] -= t * v[1], v[1]), swap(u[2] -= t * v[2], v[2]); } u[1] %= mod; return (u[1] < 0) ? (u[1] + mod) : u[1]; } bool flag; template<typename T> T garner(const vector<T>& a, vector<T> p, const T mod){ const unsigned int sz = a.size(); vector<T> kp(sz + 1, 0), rmult(sz + 1, 1); p.push_back(mod); for(unsigned int i = 0; i < sz; ++i){ T x = mod_mul(a[i] - kp[i], mod_inv(rmult[i], p[i]), p[i]); x = (x < 0) ? (x + p[i]) : x; for(unsigned int j = i + 1; j < sz + 1; ++j){ kp[j] = mod_add(kp[j], rmult[j] * x, p[j]); rmult[j] = mod_mul(rmult[j], p[i], p[j]); } } if(flag) return rmult[sz]; return kp[sz]; } vector<int> prime; bool is_prime[MAX_N]; void sieve(int n){ for(int i=0;i<=n;i++){ is_prime[i] = true; } is_prime[0] = is_prime[1] = false; for(int i=2;i<=n;i++){ if(is_prime[i]){ prime.push_back(i); for(int j=2*i;j<=n;j+=i){ is_prime[j] = false; } } } } signed main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; sieve(32000); map<int, vp> mp; flag = true; rep(i,n){ int x, y; cin >> x >> y; if(x) flag = false; for(int p : prime){ if(y % p) continue; int mult = 1; do{ y /= p, mult *= p; }while(y % p == 0); mp[p].emplace_back(x % mult, mult); } if(y > 1) mp[y].emplace_back(x % y, y); } vl x, y; for(const auto& it : mp){ int a = 0, b = 0; for(const P& p : it.se){ if(a < p.se) a = p.se, b = p.fi; } for(const P& p : it.se){ if(p.fi != b % p.se){ cout << "-1\n"; return 0; } } x.pb(b), y.pb(a); } cout << garner(x, y, (long long)MOD) << "\n"; return 0; }