結果
問題 | No.2894 Monotonic Intervals |
ユーザー |
|
提出日時 | 2024-09-20 21:34:35 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 21 ms / 2,000 ms |
コード長 | 809 bytes |
コンパイル時間 | 15,759 ms |
コンパイル使用メモリ | 320,952 KB |
最終ジャッジ日時 | 2025-02-24 09:54:42 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
純コード判定しない問題か言語 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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<<ranges::max(dp)<<"\n"; }