結果
問題 |
No.576 E869120 and Rings
|
ユーザー |
|
提出日時 | 2025-04-28 17:32:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,547 bytes |
コンパイル時間 | 2,311 ms |
コンパイル使用メモリ | 198,772 KB |
実行使用メモリ | 7,848 KB |
最終ジャッジ日時 | 2025-04-28 17:32:30 |
合計ジャッジ時間 | 4,259 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 3 |
other | WA * 27 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:63:12: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 63 | freopen("sapphire.in", "r", stdin); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:64:12: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 64 | freopen("sapphire.out", "w", stdout); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define int long long const int N = 1e5 + 5; const int Mod = 1e9 + 7; const double eps = 1e-7; using namespace std; int n, k; int a[N]; double b[N], sum[N]; struct mq { deque<int> q; void push(int x) { while (!q.empty() && sum[x] - sum[q.back()] > eps) { q.pop_back(); } q.push_back(x); } int front() { return q.front(); } void pop(int x) { while (!q.empty() && q.front() < x) { q.pop_front(); } } }; bool check(double mid) { mq q; for (int i = 1; i <= n * 2; i++) { b[i] = a[i] - mid; sum[i] = sum[i - 1] + b[i]; } int i = 1; for (int j = i + k; j <= i + n; j++) { q.push(j); } if (sum[q.front()] - sum[i] > eps) { return true; } for (i = 2; i <= n; i++) { q.pop(i + k); q.push(i + n); if (sum[q.front()] - sum[i] > eps) { return true; } } return false; } signed main() { freopen("sapphire.in", "r", stdin); freopen("sapphire.out", "w", stdout); cin >> n >> k; for (int i = 1; i <= n; i++) { char c; cin >> c; a[i] = c - '0'; a[i + n] = a[i]; } double l = 0, r = 1 + eps, mid; while (l + eps < r) { mid = (l + r) / 2; if (check(mid)) { l = mid; } else { r = mid; } } cout << l; return 0; }