結果
問題 | No.498 ワープクリスタル (給料日編) |
ユーザー |
![]() |
提出日時 | 2017-04-01 18:54:32 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 14 ms / 2,000 ms |
コード長 | 1,681 bytes |
コンパイル時間 | 674 ms |
コンパイル使用メモリ | 85,508 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-07 18:55:48 |
合計ジャッジ時間 | 1,574 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:62:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 62 | scanf("%d%d%d", &gx, &gy, &k); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:64:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 64 | for (int i = 0; i < k; i++) scanf("%d%d%d", &xs[i], &ys[i], &cns[i]); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 498.cc: No.498 ワープクリスタル (給料日編) - yukicoder */ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<string> #include<vector> #include<map> #include<set> #include<stack> #include<list> #include<queue> #include<deque> #include<algorithm> #include<numeric> #include<utility> #include<complex> #include<functional> using namespace std; /* constant */ const int MAX_K = 5; const int BN = 4; const int MAX_CN = (1 << BN) * MAX_K; typedef long long ll; const ll MOD = 1000000007; /* typedef */ /* global variables */ ll facts[MAX_CN + 1]; int xs[MAX_K], ys[MAX_K], cns[MAX_K], cs[MAX_K]; /* subroutines */ ll powmod(ll a, int b) { ll pm = 1; while (b > 0) { if (b & 1) pm = (pm * a) % MOD; a = (a * a) % MOD; b >>= 1; } return pm; } /* main */ int main() { facts[0] = 1; for (int i = 1; i <= MAX_CN; i++) facts[i] = (facts[i - 1] * i) % MOD; int gx, gy, k; scanf("%d%d%d", &gx, &gy, &k); for (int i = 0; i < k; i++) scanf("%d%d%d", &xs[i], &ys[i], &cns[i]); int maxbits = 1 << (BN * k); ll cnt = 0; for (int bits = 0; bits < maxbits; bits++) { int x = 0, y = 0, csum = 0; bool ok = true; for (int i = 0; i < k; i++) { cs[i] = (bits >> (i * BN)) & ((1 << BN) - 1); if (cs[i] > cns[i]) { ok = false; break; } x += xs[i] * cs[i], y += ys[i] * cs[i]; csum += cs[i]; } if (ok && x == gx && y == gy) { ll d = facts[csum]; for (int i = 0; i < k; i++) d = (d * powmod(facts[cs[i]], MOD - 2)) % MOD; cnt = (cnt + d) % MOD; } } printf("%lld\n", cnt); return 0; }