提出 #26596785
ソースコード 拡げる
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define FORV(i,a,b) for (uint i = a; i < b; i++)
#define FORN(i,a,b) for (int i = a; i <= b; i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define maxInt INT_MAX
#define maxll LLONG_MAX
double DP[200003][2];
bool res[200003];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vi as;
as.pb(1);
FOR(i,0,n){
int k;
cin >> k;
as.push_back(k);
}
DP[0][0] = 1.;
DP[0][1] = 0.;
FOR(i,1,n+1){
DP[i][0] = max(DP[i-1][0], DP[i-1][1] / double(as[i]));
DP[i][1] = max(DP[i-1][1], DP[i-1][0] * double(as[i]));
if (DP[i][0] > 1e100) {
DP[i][0] /= 1e90;
DP[i][1] /= 1e90;
}
}
// FOR(i,0,n+1){
// cout << DP[i][0] << " " << DP[i][1] << endl;
// }
bool gold = true;
for(int i=n-1; i >= 0; i--){
if (gold){
double oldDP = DP[i][0];
if (DP[i][0] > 1e50 * DP[i+1][0]) oldDP /= 1e90;
if (DP[i+1][0] > oldDP){
res[i] = true;
gold = false;
}
}
else {
double oldDP = DP[i][1];
if (DP[i][1] > 1e50 * DP[i+1][1]) oldDP /= 1e90;
if (DP[i+1][1] > DP[i][1]){
res[i] = true;
gold = true;
}
}
}
FOR(i,0,n){
cout << res[i] << " ";
} cout << endl;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | A - Gold and Silver |
| ユーザ | a4n0n4 |
| 言語 | C++ (GCC 9.2.1) |
| 得点 | 400 |
| コード長 | 1735 Byte |
| 結果 | AC |
| 実行時間 | 42 ms |
| メモリ | 7440 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 400 / 400 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt |
| All | 00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00-sample-001.txt | AC | 11 ms | 3524 KiB |
| 00-sample-002.txt | AC | 2 ms | 3604 KiB |
| 00-sample-003.txt | AC | 2 ms | 3500 KiB |
| 01-001.txt | AC | 2 ms | 3540 KiB |
| 01-002.txt | AC | 4 ms | 3760 KiB |
| 01-003.txt | AC | 27 ms | 4812 KiB |
| 01-004.txt | AC | 38 ms | 7172 KiB |
| 01-005.txt | AC | 25 ms | 5172 KiB |
| 01-006.txt | AC | 37 ms | 6800 KiB |
| 01-007.txt | AC | 42 ms | 7244 KiB |
| 01-008.txt | AC | 41 ms | 7208 KiB |
| 01-009.txt | AC | 42 ms | 7352 KiB |
| 01-010.txt | AC | 39 ms | 7440 KiB |
| 01-011.txt | AC | 41 ms | 7412 KiB |
| 01-012.txt | AC | 41 ms | 7364 KiB |
| 01-013.txt | AC | 38 ms | 7352 KiB |
| 01-014.txt | AC | 41 ms | 7436 KiB |
| 01-015.txt | AC | 41 ms | 7320 KiB |