結果
問題 |
No.576 E869120 and Rings
|
ユーザー |
![]() |
提出日時 | 2025-04-20 22:31:24 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,212 bytes |
コンパイル時間 | 3,990 ms |
コンパイル使用メモリ | 283,048 KB |
実行使用メモリ | 7,848 KB |
最終ジャッジ日時 | 2025-04-20 22:31:30 |
合計ジャッジ時間 | 5,276 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 3 |
other | WA * 27 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:50:24: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 50 | freopen(FILENAME ".in","r",stdin); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~ main.cpp:51:24: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 51 | freopen(FILENAME ".out","w",stdout); | ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> //#define int long long #define USE_FREOPEN //#define MUL_TEST #define FILENAME "sapphire" using namespace std; constexpr double eps = 1e-6; int n,k; string s; void solve() { cin >> n >> k >> s; s = s + s; auto chk = [&](double x) -> bool { vector<double> sa(2 * n + 1,0.0); for (int i = 0; i < 2 * n; i++) { sa[i + 1] = sa[i] + (s[i] == '1' ? 1.0 : 0.0) - x; } deque<int> q; for (int i = 1; i <= 2 * n; i++) { if (i >= k) { while (q.size() && sa[q.back()] >= sa[i - k]) q.pop_back(); q.push_back(i - k); } while (q.size() && q.front() < max(i - n,0)) q.pop_front(); if (i >= k) { if (q.size()) { if (sa[i] - sa[q.front()] >= -1e-9) return 1; } } } return 0; }; double l = 0.0,r = 1.0; for (int i = 1; i <= 100; i++) { double mid = (l + r) / 2.0; if (chk(mid)) l = mid; else r = mid; } cout << setprecision(15) << r << '\n'; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #ifdef USE_FREOPEN freopen(FILENAME ".in","r",stdin); freopen(FILENAME ".out","w",stdout); #endif int _ = 1; #ifdef MUL_TEST cin >> _; #endif while (_--) solve(); _^=_; return 0^_^0; }