結果
問題 | No.187 中華風 (Hard) |
ユーザー | anta |
提出日時 | 2015-04-21 04:06:51 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,403 bytes |
コンパイル時間 | 796 ms |
コンパイル使用メモリ | 87,080 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-04 19:00:25 |
合計ジャッジ時間 | 1,567 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 6 ms
5,376 KB |
testcase_03 | AC | 7 ms
5,376 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 1 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 1 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 1 ms
5,376 KB |
testcase_20 | WA | - |
testcase_21 | AC | 1 ms
5,376 KB |
testcase_22 | WA | - |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:182:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 182 | scanf("%d", &N); | ~~~~~^~~~~~~~~~ main.cpp:187:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 187 | scanf("%d%d", &X, &Y); | ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#include <string> #include <vector> #include <algorithm> #include <numeric> #include <set> #include <map> #include <queue> #include <iostream> #include <sstream> #include <cstdio> #include <cmath> #include <ctime> #include <cstring> #include <cctype> #include <cassert> #include <limits> #include <functional> #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) #define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) #if defined(_MSC_VER) || __cplusplus > 199711L #define aut(r,v) auto r = (v) #else #define aut(r,v) __typeof(v) r = (v) #endif #define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it) #define all(o) (o).begin(), (o).end() #define pb(x) push_back(x) #define mp(x,y) make_pair((x),(y)) #define mset(m,v) memset(m,v,sizeof(m)) #define INF 0x3f3f3f3f #define INFL 0x3f3f3f3f3f3f3f3fLL using namespace std; typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii; typedef long long ll; template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; } template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; } inline void fasterLLDivMod(unsigned long long x, unsigned y, unsigned &out_d, unsigned &out_m) { unsigned xh = (unsigned)(x >> 32), xl = (unsigned)x, d, m; #ifdef __GNUC__ asm ( "divl %4; \n\t" : "=a" (d), "=d" (m) : "d" (xh), "a" (xl), "r" (y) ); #else __asm { mov edx, dword ptr [xh]; mov eax, dword ptr [xl]; div dword ptr [y]; mov dword ptr [d], eax; mov dword ptr [m], edx; }; #endif out_d = d; out_m = m; } typedef unsigned int u32; typedef unsigned long long u64; u32 rem_1(const u32 *x, int n, u32 y) { u32 rem = 0, dummy; for(int i = n - 1; i >= 0; -- i) { u64 a = (u64)rem << 32 | x[i]; fasterLLDivMod(a, y, dummy, rem); } return rem; } u32 add(const u32 *x, const u32 *y, int n, u32 *z) { u32 carry = 0; for(int i = 0; i < n; ++ i) { u32 a = x[i], b = y[i]; u64 c = (u64)a + b + carry; z[i] = (u32)c; carry = (u32)(c >> 32); } return carry; } u32 add_1(const u32 *x, int n, u32 y, u32 *z) { u32 carry = y; for(int i = 0; i < n; ++ i) { u64 c = (u64)x[i] + carry; z[i] = (u32)c; carry = (u32)(c >> 32); } return y; } u32 add(const u32 *x, int xn, const u32 *y, int yn, u32 *z) { assert(xn >= yn); u32 carry = add(x, y, yn, z); return add_1(x + yn, xn - yn, carry, z + yn); } u32 mul_1(const u32 *x, int n, u32 y, u32 *z) { u32 carry = 0; for(int i = 0; i < n; ++ i) { u32 a = x[i]; u64 c = (u64)a * y + carry; z[i] = (u32)c; carry = (u32)(c >> 32); } return carry; } struct Int { vector<u32> v; Int() { } Int(u32 x) { if(x != 0) v.assign(1, x); } int size() const { return v.size(); } u32 *data() { return v.empty() ? NULL : &v[0]; } const u32 *data() const { return v.empty() ? NULL : &v[0]; } void resize(int n) { v.resize(n); } Int &normalize() { while(!v.empty() && v.back() == 0) v.pop_back(); return *this; } u32 operator%(u32 y) const { return rem_1(data(), size(), y); } Int &mulAssign(const Int &x, u32 y) { int sz = x.size(); resize(sz + 1); v[sz] = mul_1(x.data(), sz, y, data()); return normalize(); } Int &operator+=(const Int &that) { if(size() >= that.size()) { int sz = size(); resize(sz + 1); v[sz] = add(data(), sz, that.data(), that.size(), data()); }else { int sz = that.size(); resize(sz + 1); v[sz] = add(data(), that.data(), sz, data()); } return normalize(); } void swap(Int &that) { v.swap(that.v); } }; int exgcd(int a, int b, int &g) { int u = 1, v = 0; while(b) { int t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } g = a; return u; } bool crt(Int &a1, Int &n1, int a2, int n2, Int &tmp) { assert(0 <= a2 && a2 < n2); int b = n1 % n2, t, g; t = exgcd(b, n2, g); int n2_g = n2 / g; int d1 = a1 % n2; if((a2 - d1) % g != 0) return false; int d = (a2 - d1) / g; int h = (long long)d * t % n2_g; if(h < 0) h += n2_g; tmp.mulAssign(n1, h); tmp += a1; a1.swap(tmp); n1.mulAssign(n1, n2_g); return true; } int main() { int N; scanf("%d", &N); Int a, n = 1U, tmp; bool ok = true, zero = true; rep(i, N) { int X, Y; scanf("%d%d", &X, &Y); zero &= Y == 0; ok = ok && crt(a, n, X, Y, tmp); } if(!ok) { puts("-1"); }else { if(zero) a += n; int ans = a % 1000000007; printf("%d\n", ans); } return 0; }