結果
問題 | No.849 yuki国の分割統治 |
ユーザー | b312546656 |
提出日時 | 2019-07-05 21:55:46 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,932 bytes |
コンパイル時間 | 938 ms |
コンパイル使用メモリ | 84,224 KB |
実行使用メモリ | 11,840 KB |
最終ジャッジ日時 | 2024-10-06 21:33:40 |
合計ジャッジ時間 | 4,046 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
5,248 KB |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | RE | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 86 ms
8,228 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 3 ms
5,248 KB |
testcase_27 | AC | 3 ms
5,248 KB |
testcase_28 | WA | - |
testcase_29 | AC | 3 ms
5,248 KB |
ソースコード
#include<iostream> #include<algorithm> #include<vector> #include<string> #include<set> #include<queue> #include<stack> #include<bitset> using namespace std; int p = 1000000007; #define int long long #define vel vector<long long> #define vvel vector<vel> #define rep(i,n) for(long long i=0;i<n;i++) #define sor(v) sort(v.begin(),v.end()) #define mmax(a,b) a=max(a,b) #define mmin(a,b) a=min(a,b) #define mkp make_pair #define pin pair<int,int> #define V vector #define Endl endl #define veb vector<bool> #define sq(a) (a)*(a) #define rev(s) reverse(s.begin(),s.end()) #define end_program(s) cout << s <<endl;return 0 int kai_size = 120001; vel kai(kai_size, 1); vel ink(kai_size, 1); vel dist; int RE() { vel v(3, 2); return v.at(4); } int ru(int a, int r) { if (r == 0) { return 1; } int ans = ru(a, r / 2); ans *= ans; ans %= p; if (r % 2 == 1) { ans *= a; } return ans % p; } int inv(int a) { return ru(a, p - 2); } void make_kai() { rep(i, kai_size-1) { kai[i + 1] = (kai[i] * (i + 1)) % p; } rep(i, kai_size) { ink[i] = inv(kai[i]); } } int com(int n, int r) { int ans = kai[n] * ink[r]; ans %= p; ans *= ink[n - r]; ans %= p; return ans; } vel dis(int mid1, vvel &way) { int n = way.size(); vel dist(n, -1); dist[mid1] = 0; queue<int> q; q.push(mid1); while (!q.empty()) { int st = q.front(); q.pop(); rep(i, way[st].size()) { int to = way[st][i]; if (dist[to] == -1) { dist[to] = dist[st] + 1; q.push(to); } } } return dist; } pin most_far(int now, int n, vvel &way) { vel dist1 = dis(now, way); pin ans = mkp(-1, 0); rep(i, n) { if (dist1[i] > ans.first) { ans = mkp(dist1[i], i); } } return ans; } int gcd(int a, int b) { a = abs(a); b = abs(b); if (a < b) { swap(a, b); } if (b == 0) { return a; } return gcd(b, a%b); } int per(int a, int b) { int ans = a % b; if (ans < 0) { ans += b; } return ans; } V<pin> uni(V<pin> &v) { sor(v); V<pin> ans(1, v[0]); for (int i = 1; i < v.size(); i++) { if (v[i] != v[i-1]) { ans.push_back(v[i]); } } v = ans; return v; } signed main() { int a, b, c, d; cin >> a >> b >> c >> d; if (a*d - b * c == 0) { int gcd0 = gcd(a, c); a /= gcd0; b /= gcd0; if (a < 0) { a *= -1; b *= -1; } int n; cin >> n; V<pin> ans(n); if (a != 0) { rep(i, n) { int x, y; cin >> x >> y; int ex = per(x, a); int ey = y-((x - ex)/ a)*b; ans.push_back(mkp(ex, ey)); } } else { swap(a, b); rep(i, n) { int x, y; cin >> y >> x; int ex = per(x, a); int ey = y - ((x - ex) / a)*b; ans.push_back(mkp(ex, ey)); } } uni(ans); cout << ans.size() << Endl; } else { int det = a * d - b * c; det = abs(det); int n; cin >> n; V<pin> ans(n); rep(i, n) { int x, y; cin >> x >> y; int nx = d * x - c * y; nx = per(nx, det); int ny = a * y - b * x; ny = per(ny, det); ans.push_back(mkp(nx, ny)); } uni(ans); cout << ans.size() << Endl; } return 0; }