結果
問題 | No.321 (P,Q)-サンタと街の子供たち |
ユーザー | anta |
提出日時 | 2015-12-14 00:22:00 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 9 ms / 2,000 ms |
コード長 | 8,318 bytes |
コンパイル時間 | 753 ms |
コンパイル使用メモリ | 89,544 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-06 21:46:52 |
合計ジャッジ時間 | 2,314 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 1 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | AC | 1 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 1 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 1 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,944 KB |
testcase_12 | AC | 1 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,944 KB |
testcase_14 | AC | 7 ms
6,944 KB |
testcase_15 | AC | 9 ms
6,940 KB |
testcase_16 | AC | 4 ms
6,944 KB |
testcase_17 | AC | 1 ms
6,944 KB |
testcase_18 | AC | 6 ms
6,944 KB |
testcase_19 | AC | 6 ms
6,940 KB |
testcase_20 | AC | 9 ms
6,940 KB |
testcase_21 | AC | 6 ms
6,948 KB |
testcase_22 | AC | 3 ms
6,940 KB |
testcase_23 | AC | 8 ms
6,944 KB |
testcase_24 | AC | 3 ms
6,940 KB |
testcase_25 | AC | 6 ms
6,940 KB |
testcase_26 | AC | 8 ms
6,940 KB |
testcase_27 | AC | 7 ms
6,940 KB |
testcase_28 | AC | 7 ms
6,940 KB |
testcase_29 | AC | 8 ms
6,940 KB |
testcase_30 | AC | 1 ms
6,940 KB |
testcase_31 | AC | 2 ms
6,940 KB |
testcase_32 | AC | 5 ms
6,940 KB |
testcase_33 | AC | 5 ms
6,940 KB |
testcase_34 | AC | 4 ms
6,944 KB |
testcase_35 | AC | 7 ms
6,940 KB |
testcase_36 | AC | 2 ms
6,940 KB |
testcase_37 | AC | 6 ms
6,944 KB |
testcase_38 | AC | 5 ms
6,944 KB |
testcase_39 | AC | 2 ms
6,940 KB |
testcase_40 | AC | 8 ms
6,944 KB |
testcase_41 | AC | 3 ms
6,944 KB |
testcase_42 | AC | 7 ms
6,940 KB |
testcase_43 | AC | 5 ms
6,944 KB |
testcase_44 | AC | 6 ms
6,940 KB |
ソースコード
#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; } class FastInput { bool _end; public: FastInput() : _end(false) { } operator void*() { return _end ? 0 : (void*)this; } template<typename T> void read_unsigned(T *res) { T x = 0; for(char c = skip(); '0' <= c && c <= '9'; c = gc()) x = x * 10 + (c - '0'); *res = x; } template<typename T> void read_signed(T *res) { char c = skip(); bool sign = false; if(c == '-') sign = true, c = gc(); T x = 0; for(; '0' <= c && c <= '9'; c = gc()) x = x * 10 + (c - '0'); *res = !sign ? x : -x; } void read_c_string(char *str, int *len) { int n = 0; for(char c = skip(); !is_delim(c); c = gc()) str[n ++] = c; str[n] = 0; *len = n; } void read_string(std::string *str) { str->clear(); for(char c = skip(); !is_delim(c); c = gc()) *str += c; } void read_line(std::string *str) { str->clear(); for(char c = gc(); c != '\n'; c = gc()) *str += c; if(!str->empty() && (*str)[str->size() - 1] == '\r') str->resize(str->size() - 1); } void read_double(double *res) { std::string buf; read_string(&buf); sscanf(buf.c_str(), "%lf", res); } void read_char(char *res) { *res = skip(); } void read_string_buf(char *res, int n) { *res = skip(); } FastInput &operator()(char &res) { read_char(&res); return *this; } FastInput &operator()(int &res) { read_signed(&res); return *this; } FastInput &operator()(unsigned &res) { read_unsigned(&res); return *this; } FastInput &operator()(long long &res) { read_signed(&res); return *this; } FastInput &operator()(unsigned long long &res) { read_unsigned(&res); return *this; } FastInput &operator()(char *res) { int len; read_c_string(res, &len); return *this; } FastInput &operator()(std::string &res) { read_string(&res); return *this; } FastInput &operator()(double &res) { read_double(&res); return *this; } template<typename T1, typename T2> FastInput &operator()(T1 &res1, T2 &res2) { return operator()(res1)(res2); } template<typename T1, typename T2, typename T3> FastInput &operator()(T1 &res1, T2 &res2, T3 &res3) { return operator()(res1)(res2)(res3); } template<typename T> FastInput &a(T *a, int n) { for(int i = 0; i < n; ++ i) operator()(a[i]); return *this; } template<typename T> FastInput &operator()(vector<T> &v) { for(size_t i = 0; i < v.size(); ++ i) operator()(v[i]); return *this; } private: static char gc() { #if defined(__GNUC__) && !defined(__MINGW32__) return (char)getchar_unlocked(); #elif defined(_MSC_VER) return (char)_getchar_nolock(); #else return (char)getchar(); #endif } static bool is_delim(char c) { return c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == EOF; } char skip() { if(_end) return EOF; char c; for(c = gc(); c != -1 && is_delim(c); c = gc()) ; if(c == EOF) _end = true; return c; } } in; class FastOutput { public: template<typename T> void print_unsigned(T x) { char buf[24]; int n = 0; do buf[n ++] = x % 10, x /= 10; while(x != 0); while(n > 0) pc('0' + buf[-- n]); } template<typename T> void print_signed(T x) { char buf[24]; int n = 0; bool sign = false; if(x < 0) sign = true; //depends on the -x % y behaviour do buf[n ++] = x % 10, x /= 10; while(x != 0); if(!sign) { while(n > 0) pc('0' + buf[-- n]); } else { pc('-'); while(n > 0) pc('0' - buf[-- n]); } } void print_c_string(const char *str) { for(const char *p = str; *p; ++ p) pc(*p); } void print_string(const std::string &str) { print_c_string(str.c_str()); } void print_double(double x, int digits) { //|res| < 2^1024 ~ 10^308 char buf[512]; #ifdef _MSC_VER sprintf_s(buf, "%.*f", digits, x); #else sprintf(buf, "%.*f", digits, x); #endif print_c_string(buf); } void print_char(char x) { pc(x); } FastOutput &operator()(char x) { print_char(x); return *this; } FastOutput &operator()(int x) { print_signed(x); return *this; } FastOutput &operator()(unsigned x) { print_unsigned(x); return *this; } FastOutput &operator()(long long x) { print_signed(x); return *this; } FastOutput &operator()(unsigned long long x) { print_unsigned(x); return *this; } FastOutput &operator()(const char *str) { print_c_string(str); return *this; } FastOutput &operator()(const std::string &str) { print_string(str); return *this; } FastOutput &operator()(double x) { print_double(x, 10); return *this; } template<typename T1, typename T2> FastOutput &operator()(T1 x1, T2 x2) { return operator()(x1)(x2); } template<typename T1, typename T2, typename T3> FastOutput &operator()(T1 x1, T2 x2, T3 x3) { return operator()(x1)(x2)(x3); } template<typename T1, typename T2, typename T3, typename T4> FastOutput &operator()(T1 x1, T2 x2, T3 x3, T4 x4) { return operator()(x1)(x2)(x3)(x4); } private: static void pc(char c) { #if defined(__GNUC__) && !defined(__MINGW32__) putchar_unlocked(c); #elif defined(_MSC_VER) _putchar_nolock(c); #else putchar(c); #endif } } out; class FastOutputN { public: template<typename T1> FastOutputN &operator()(T1 x1) { out(x1)('\n'); return *this; } template<typename T1, typename T2> FastOutputN &operator()(T1 x1, T2 x2) { out(x1, x2)('\n'); return *this; } template<typename T1, typename T2, typename T3> FastOutputN &operator()(T1 x1, T2 x2, T3 x3) { out(x1, x2, x3)('\n'); return *this; } template<typename T1, typename T2, typename T3, typename T4> FastOutputN &operator()(T1 x1, T2 x2, T3 x3, T4 x4) { out(x1, x2, x3, x4)('\n'); return *this; } template<typename T> FastOutputN &a(const T *a, int n) { for(int i = 0; i < n; ++ i) { if(i != 0) out(' '); out(a[i]); } out('\n'); return *this; } template<typename T> FastOutputN &operator()(const vector<T> &v) { for(size_t i = 0; i < v.size(); ++ i) { if(i != 0) out(' '); out(v[i]); } out('\n'); return *this; } } outn; template<typename T>T gcd(T x, T y) { if(y == 0)return x; else return gcd(y, x%y); } unsigned inv2adic(unsigned x) { unsigned i = x, p; do { p = i * x; i *= 2U - p; }while(p != 1); return i; } int main() { int P; int Q; while(in(P, Q)) { P = abs(P), Q = abs(Q); int g = max(1, gcd(P, Q)); P /= g, Q /= g; int shift = 0; while((g & ((2U << shift)-1)) == 0) ++ shift; const unsigned mask = (1U << shift) - 1; const unsigned invg = inv2adic(g >> shift); const unsigned recipg = ~0U / (g >> shift); int N; in(N); int ans = 0; vector<pii> XY(N); rep(i, N) in(XY[i].first, XY[i].second); if(P == 0 && Q == 0) { rep(i, N) ans += XY[i] == mp(0, 0); } else if((P + Q) % 2 != 0) { rep(i, N) { int X = abs(XY[i].first), Y = abs(XY[i].second); bool ok = true; ok &= (X & mask) == 0; ok &= ((X >> shift) * invg) <= recipg; ok &= (Y & mask) == 0; ok &= ((Y >> shift) * invg) <= recipg; ans += ok; } } else { rep(i, N) { int X = abs(XY[i].first), Y = abs(XY[i].second); bool ok = true; ok &= (X & mask) == 0; ok &= ((X >> shift) * invg) <= recipg; ok &= (Y & mask) == 0; ok &= ((Y >> shift) * invg) <= recipg; ok &= (((X >> shift) + (Y >> shift)) & 1) == 0; ans += ok; } } outn(ans); } return 0; }