結果
問題 |
No.3166 [Cherry 7th Tune *] 桜の守人
|
ユーザー |
|
提出日時 | 2025-05-30 22:08:16 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 337 ms / 2,000 ms |
コード長 | 2,552 bytes |
コンパイル時間 | 4,002 ms |
コンパイル使用メモリ | 314,032 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-05-30 22:08:31 |
合計ジャッジ時間 | 12,421 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 26 |
ソースコード
#pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> using namespace std; using ll = long long; const ll mod = 1e9 + 7; const ll mod2 = 998244353; ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll pow(ll a, ll b) { ll ans = 1; while (b) { if (b & 1) ans *= a; b >>= 1; a *= a; } return ans; } ll pow(ll a, ll b, ll c) { ll ans = 1; while (b) { if (b & 1) ans = (ans * a) % c; b >>= 1; a = (a * a) % c; } return ans; } void check(bool b) { if (b) cout << "Yes\n"; else cout << "No\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t = 1; cin >> t; while (t--) { ll n;cin>>n; ll p;cin>>p; ll k;cin>>k; vector<ll>a(n); for (int i = 0; i < n; ++i) { cin>>a[i]; } ll l=1, r=p/2+p%2; while (l<r){ ll mid=(l+r)/2; deque<pair<ll,ll>>v; for (int i = 0; i < n; ++i) { ll l1=a[i]; ll r1=a[i]+mid-1; v.push_back({l1,1}); if (r1<p-1){ v.push_back({r1+1,-1}); } else { v.push_back({0,1}); v.push_back({r1-p+1,-1}); } } for (int i = 0; i < n; ++i) { if (a[i]==0){ v.push_back({p-mid,1}); continue; } v.push_back({a[i],-1}); ll l1=a[i]-mid; if (l1<0){ v.push_back({0,1}); v.push_back({p+l1,1}); } else { v.push_back({l1,1}); } } sort(v.begin(),v.end()); bool ok=true; ll cnt=0; while (!v.empty()){ auto x=v.front().first; while (!v.empty() && v.front().first==x){ cnt+=v.front().second; v.pop_front(); } if (cnt<k){ ok=false; break; } } if (ok){ r=mid; } else { l=mid+1; } } cout<<l<<'\n'; } return 0; }