Submission #260068

#TimeUsernameProblemLanguageResultExecution timeMemory
260068arnold518Vim (BOI13_vim)C++14
13.89 / 100
21 ms4480 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1000; int N; char A[MAXN+10]; int dp[MAXN+10][MAXN+10]; vector<int> V[20]; int solve(int now, int pos) { int &ret=dp[now][pos]; if(ret!=-1) return ret; ret=987654321; for(int i=0; i<10; i++) { if(i==4) continue; auto it=upper_bound(V[i].begin(), V[i].end(), now); if(it==V[i].end()) continue; ret=min(ret, solve(*it, pos)+2); } if(now>pos) { int p=now-pos+lower_bound(V[4].begin(), V[4].end(), now)-lower_bound(V[4].begin(), V[4].end(), pos); auto jt=upper_bound(V[4].begin(), V[4].end(), now); if(jt==V[4].end()) ret=min(ret, p); else { for(int i=0; i<10; i++) { if(i==4) continue; auto it=upper_bound(V[i].begin(), V[i].end(), pos); if(it==V[i].end()) continue; ret=min(ret, solve(*it, *jt)+p+2); } } } //printf("%d %d : %d\n", now, pos, ret); return ret; } int main() { scanf("%d", &N); scanf(" %s", A+1); for(int i=1; i<=N; i++) V[A[i]-'a'].push_back(i); if(V[4].empty()) return !printf("0\n"); memset(dp, -1, sizeof(dp)); printf("%d\n", solve(1, V[4].front())); }

Compilation message (stderr)

vim.cpp: In function 'int main()':
vim.cpp:50:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
vim.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf(" %s", A+1);
  ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...