結果
| 問題 |
No.885 アマリクエリ
|
| ユーザー |
emthrm
|
| 提出日時 | 2019-09-13 22:19:16 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,504 bytes |
| コンパイル時間 | 1,254 ms |
| コンパイル使用メモリ | 122,564 KB |
| 最終ジャッジ日時 | 2025-01-07 17:51:43 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 TLE * 1 |
コンパイルメッセージ
In file included from /usr/include/c++/13/iostream:41,
from main.cpp:13:
In member function ‘std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]’,
inlined from ‘int main()’ at main.cpp:52:15:
/usr/include/c++/13/ostream:204:25: warning: ‘memo’ may be used uninitialized [-Wmaybe-uninitialized]
204 | { return _M_insert(__n); }
| ~~~~~~~~~^~~~~
main.cpp: In function ‘int main()’:
main.cpp:48:13: note: ‘memo’ was declared here
48 | long long memo;
| ^~~~
ソースコード
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
cin.tie(nullptr); ios::sync_with_stdio(false);
// freopen("input.txt", "r", stdin);
int n; cin >> n;
map<int, int> mp;
while (n--) {
int a; cin >> a;
++mp[a];
}
int q; cin >> q;
int mae = INF;
long long memo;
while (q--) {
int x; cin >> x;
if (x >= mae) {
cout << memo << '\n';
continue;
}
long long ans = 0;
map<int, int> nx;
for (auto pr : mp) {
long long val = pr.first % x;
ans += val * pr.second;
if (val > 0) nx[val] += pr.second;
}
cout << ans << '\n';
mae = x;
memo = ans;
swap(mp, nx);
}
return 0;
}
emthrm