제출 #1268474

#제출 시각아이디문제언어결과실행 시간메모리
1268474_rain_Vim (BOI13_vim)C++20
100 / 100
47 ms43460 KiB
#include<bits/stdc++.h> using namespace std; typedef long long LL; #define FOR(i,a,b) for(int i = (a) , _b = (b); i <= _b; ++i) #define BIT(mask , x) (((mask) >> (x)) & (1)) #define MASK(x) ((LL)(1) << (x)) #define sz(x) (int)(x).size() #define Time cerr << "\n Time lapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n"; template<class T1 , class T2> bool maximize(T1 &a , T2 b){ if (a < b) return a = b , true; else return false; } template<class T1 , class T2> bool minimize(T1 &a , T2 b){ if (a > b) return a = b , true; else return false; } template<class T> void compress(vector<T>&data){ sort(data.begin() , data.end()); data.resize(unique(data.begin() , data.end()) - data.begin()); } template<class T1 , class T2> T2 Find(const vector<T1>&data , T2 y){ return upper_bound(data.begin() , data.end() , y) - data.begin(); } const int N = (int) 7e4; const int MAXK = 10; int n , answer = 0; bool flag = false; string s; vector<int>v; bool must[N + 2] = {}; int f[N + 2][MAXK + 2]; int g[N + 2][MAXK + 2][MAXK + 2]; int main(){ ios::sync_with_stdio(false); cin.tie(0) ; cout.tie(0) ; #define name "main" if (fopen(name".inp","r")){ freopen(name".inp","r",stdin); freopen(name".out","w",stdout); } cin >> n; cin >> s; s = '#' + s; v.push_back(0); for(int i = 1; i <= n; ++i) { if (s[i] == 'e'){ answer += 2; flag = true; } else{ int c = (int)s[i] - 'a' - (s[i] < 'e' ? 0 : 1); v.push_back(c); must[sz(v) - 1] = flag; flag = false; } } // for(auto& x : v) cout << x << ' '; cout << '\n'; memset(f , 0x3f , sizeof f); memset(g , 0x3f ,sizeof g); f[0][v[1]] = 0; for(int i = 1; i < sz(v); ++i){ for(int c = 0; c < MAXK; ++c){ if (must[i] == false && v[i] != c) minimize(f[i][c] , f[i - 1][c]); minimize(f[i][c] , f[i - 1][v[i]] + 2); if (v[i] != c) minimize(f[i][c] , g[i - 1][v[i]][c]); minimize(f[i][c] , g[i - 1][v[i]][v[i]] + 2); for(int nxt_c = 0; nxt_c < MAXK; ++nxt_c){ minimize(g[i][c][nxt_c] , f[i - 1][v[i]] + 5); minimize(g[i][c][nxt_c] , g[i - 1][v[i]][v[i]] + 5); if (c != v[i]) minimize(g[i][c][nxt_c] , f[i - 1][c] + 3); if (v[i] != c && v[i] != nxt_c) { minimize(g[i][c][nxt_c] , g[i - 1][c][nxt_c] + 1); } if (v[i] != nxt_c) minimize(g[i][c][nxt_c] , g[i - 1][v[i]][nxt_c] + 3); if (v[i] != c) minimize(g[i][c][nxt_c] , g[i - 1][c][v[i]] + 3); } } } cout << f[sz(v) - 1][MAXK - 1] + answer - 2; return 0; }

컴파일 시 표준 에러 (stderr) 메시지

vim.cpp: In function 'int main()':
vim.cpp:45:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |                         freopen(name".inp","r",stdin);
      |                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
vim.cpp:46:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |                         freopen(name".out","w",stdout);
      |                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...