結果
問題 | No.990 N×Mマス計算(Kの倍数) |
ユーザー |
![]() |
提出日時 | 2020-09-24 19:24:47 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,843 bytes |
コンパイル時間 | 2,002 ms |
コンパイル使用メモリ | 128,500 KB |
最終ジャッジ日時 | 2025-01-14 20:04:43 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | RE * 2 |
other | RE * 19 |
コンパイルメッセージ
main.cpp: In function ‘void solve_add()’: main.cpp:29:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 29 | re(i, m) scanf("%lld", &b[i]), b[i]%=k; | ~~~~~^~~~~~~~~~~~~~~ main.cpp:30:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 30 | re(i, n) scanf("%lld", &a[i]), a[i]%=k; | ~~~~~^~~~~~~~~~~~~~~ main.cpp: In function ‘void solve_mul()’: main.cpp:53:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 53 | re(i, m) scanf("%lld", &b[i]); | ~~~~~^~~~~~~~~~~~~~~ main.cpp:54:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 54 | re(i, n) scanf("%lld", &a[i]); | ~~~~~^~~~~~~~~~~~~~~
ソースコード
#include <iostream> #include <string> #include <vector> #include <array> #include <queue> #include <deque> #include <algorithm> #include <set> #include <map> #include <bitset> #include <cmath> #include <functional> #include <cassert> #include <iomanip> #define vll vector<ll> #define vvvl vector<vvl> #define vvl vector<vector<ll>> #define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c)) #define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d))); #define re(c, b) for(ll c=0;c<b;c++) #define all(obj) (obj).begin(), (obj).end() typedef long long int ll; typedef long double ld; using namespace std; ll n, m, k; void solve_add(){ vll a(n), b(m); re(i, m) scanf("%lld", &b[i]), b[i]%=k; re(i, n) scanf("%lld", &a[i]), a[i]%=k; sort(all(a)); ll ans = 0; for(int i=0;i<m;i++){ ll target = (k - b[i])%k; ll l = upper_bound(all(a), target) - a.begin(); ll r = upper_bound(all(a), target+1) - a.begin(); ans += r - l; } std::cout << ans << '\n'; } ll gcd(ll a, ll b){ if(b<a) swap(a, b); ll r = a % b; if(r==0) return b; while(r!=0) r = a % b, a = b, b = r; return a; } void solve_mul(){ vll a(n), b(m); re(i, m) scanf("%lld", &b[i]); re(i, n) scanf("%lld", &a[i]); vll d;//kの約数 d.push_back(1); d.push_back(k); for(ll i=2;i*i<=k;i++){ if(k%i==0){ d.push_back(i); if(i*i!=k) d.push_back(k/i); } } vll cnt(d.size(), 0); for(int i=0;i<n;i++) for(int j=0;j<d.size();j++) if(a[i]%d[j]==0) cnt[j]++; map<ll, ll> mp; for(int i=0;i<d.size();i++){ mp.emplace(d[i], i); } ll ans = 0; for(int i=0;i<m;i++){ ll g = gcd(k, b[i]); ll need_idx = mp[k/g]; ans += cnt[need_idx]; } std::cout << ans << '\n'; } int main(){ std::cin >> n >> m >> k; char op;std::cin >> op; if(op=='+') solve_add(); //else solve_mul(); return 1; }