結果
問題 |
No.2894 Monotonic Intervals
|
ユーザー |
|
提出日時 | 2024-09-20 21:35:26 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 18 ms / 2,000 ms |
コード長 | 827 bytes |
コンパイル時間 | 5,600 ms |
コンパイル使用メモリ | 309,008 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-20 21:35:39 |
合計ジャッジ時間 | 5,625 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 |
ソースコード
#include <atcoder/all> #include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, s, t) for (ll i = s; i < (ll)(t); i++) template<typename T> bool chmin(T &x, T y) { return x > y ? (x = y, true) : false; } template<typename T> bool chmax(T &x, T y) { return x < y ? (x = y, true) : false; } struct io_setup { io_setup() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cout << fixed << setprecision(15); } } io_setup; int main(){ int n; cin>>n; string s; cin>>s; vector<ll> dp(3,0); dp.at(1)=1; rep(i,0,n){ auto ndp=dp; if(s.at(i)=='<'){ chmax(ndp.at(2),max(dp.at(0)+1,dp.at(1))); chmax(ndp.at(1),dp.at(0)+1); }else{ chmax(ndp.at(0),max(dp.at(1),dp.at(2)+1)); chmax(ndp.at(1),dp.at(2)+1); } swap(ndp,dp); } cout<<*max_element(dp.begin(),dp.end())<<"\n"; }