Problem:
Delete Files
You are using an operating system named "Jaguntu". Jaguntu provides "Filer", a file manager with a graphical user interface.
When you open a folder with Filer, the name list of files in the folder is displayed on a Filer window. Each filename is displayed within a rectangular region, and this region is called a filename region. Each filename region is aligned to the left side of the Filer window. The height of each filename region is 1, and the width of each filename region is the filename length. For example, when three files "acm.in1", "acm.c~", and "acm.c" are stored in this order in a folder, it looks like Fig. C-1 on the Filer window.
You can delete files by taking the following steps. First, you select a rectangular region with dragging a mouse. This region is called selection region. Next, you press the delete key on your keyboard. A file is deleted if and only if its filename region intersects with the selection region. After the deletion, Filer shifts each filename region to the upside on the Filer window not to leave any top margin on any remaining filename region. For example, if you select a region like Fig. C-2, then the two files "acm.in1" and "acm.c~" are deleted, and the remaining file "acm.c" is displayed on the top of the Filer window as Fig. C-3.
You are opening a folder storing $N$ files with Filer. Since you have almost run out of disk space, you want to delete unnecessary files in the folder. Your task is to write a program that calculates the minimum number of times to perform deletion operation described above.
Input
The input consists of a single test case. The test case is formatted as follows.
$N$
$D_1$ $L_1$
$D_2$ $L_2$
...
$D_N$ $L_N$
The first line contains one integer $N$ ($1 \leq N \leq 1,000$), which is the number of files in a folder. Each of the next $N$ lines contains a character $D_i$ and an integer $L_i$: $D_i$ indicates whether the $i$-th file should be deleted or not, and $L_i$ ($1 \leq L_i \leq 1,000$) is the filename length of the $i$-th file. If $D_i$ is 'y', the $i$-th file should be deleted. Otherwise, $D_i$ is always 'n', and you should not delete the $i$-th file.
Output
Output the minimum number of deletion operations to delete only all the unnecessary files.
Sample Input 1
3
y 7
y 6
n 5
Output for the Sample Input 1
1
Sample Input 2
3
y 7
n 6
y 5
Output for the Sample Input 2
2
Sample Input 3
6
y 4
n 5
y 4
y 6
n 3
y 6
Output for the Sample Input 3
2

Submitted solutions:

code_snippet: #include <iostream>
#include <vector>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

constexpr int INF = 1 << 30;

void solve() {
    int n;
    std::cin >> n;

    std::vector<bool> erase(n);
    std::vector<int> xs(n);
    for (int i = 0; i < n; ++i) {
        char c;
        std::cin >> c >> xs[i];
        erase[i] = (c == 'y');
    }

    auto dp = vec(n + 1, vec(n + 1, 0));
    for (int len = 0; len < n; ++len) {
        for (int l = 0; l + len < n; ++l) {
            int r = l + len;
            if (!erase[l]) {
                dp[l][r] = dp[l + 1][r];
                continue;
            }

            if (!erase[r]) {
                dp[l][r] = dp[l][r - 1];
                continue;
            }

            int ymin = INF, nmax = 0;
            for (int i = l; i <= r; ++i) {
                if (erase[i]) {
                    ymin = std::min(ymin, xs[i]);
                } else {
                    nmax = std::max(nmax, xs[i]);
                }
            }

            if (ymin > nmax) {
                dp[l][r] = 1;
                continue;
            }

            dp[l][r] = INF;
            for (int i = l; i + 1 <= r; ++i) {
                dp[l][r] = std::min(dp[l][r], dp[l][i] + dp[i + 1][r]);
            }
        }
    }

    std::cout << dp[0][n - 1] << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
accuracy: 0.05555555555555555
time_ms: 20
memory_kb: 4184
final_rank: 3

code_snippet: #include<bits/stdc++.h>
using namespace std;
const int maxx = 4e3+13;
struct ls{	
	int v,id;
}A[maxx];
bool my(ls a,ls b){return a.v<b.v;}
int h[maxx],flag[maxx];
int n,tot;
int dp[maxx][maxx];
int read(){int k;cin>>k;return k;}
int main(){	
	n=read();
	for(int i=1;i<=n;i++){
		char s;cin>>s;
		h[i]=read();
		if(s=='y')flag[i]=1;
		else flag[i] = 0;
	}	
	for(int i=0;i<maxx;i++)for(int j=0;j<maxx;j++)dp[i][j]=1<<30;
	int ans=0;
	int tot=2000;
	for(int i=1;i<=n;i++){	
		if(flag[i]==1){		
			int x = h[i];	
			for(int j=1;j<=x;j++)dp[i][j]=min(dp[i-1][j],ans+1);	
			for(int j=x+1;j<=tot;j++)dp[i][j]=min(dp[i][j],dp[i-1][j]+1);	
			ans=1<<30;
			for(int j=1;j<=tot;j++)ans=min(dp[i][j],ans);
		}	
		if(flag[i]==0){	
			int x = h[i];
			for(int j=1;j<=tot;j++){	
				if(j<=x)dp[i][j]=1<<30;
				else dp[i][j]=dp[i-1][j];
			}	
		}	
	}	
	cout<<ans<<endl;
	return 0;
}
accuracy: 0.05555555555555555
time_ms: 10
memory_kb: 66000
final_rank: 6

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1<<25
int main(){
  int n;
  cin>>n;
  char c[n+2];
  int l[n+2];
  for(int i=1;i<=n;i++) cin>>c[i]>>l[i];
  c[0]='n';l[0]=INF;
  c[n+1]='n';l[n+1]=INF;
  vector<int> no;
  for(int i=0;i<n+2;i++) if(c[i]=='n') no.push_back(i);
  int ans=0;
  bool used[n+2];
  memset(used,0,sizeof(used));
  for(int i=1;i<(int)no.size();i++){
    for(int j=0;j+i<(int)no.size();j++){
      //cout<<no[j]<<" "<<no[j+i]<<endl;
      bool ff=0;
      for(int k=no[j]+1;k<no[j+i];k++){
	if(c[k]=='y'&&!used[k]&&l[k]<=l[no[j]]&&l[k]<=l[no[j+i]]){
	  ff=1;
	  break;
	}
      }
      if(ff){
	//cout<<no[j]<<" "<<no[j+i]<<endl;
	ans++;
	for(int k=no[j]+1;k<no[j+i];k++) used[k]=1;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}
accuracy: 1
time_ms: 160
memory_kb: 3164
final_rank: 1

code_snippet: // This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int n,len[1111],ok[1111],mn[1111][1111];
map<int,int> tt[1111][1111];
char tmp[5];
int dfs(int l,int r,int up)
{
	if(l>r)return 0;
	if(tt[l][r].find(up)!=tt[l][r].end())return tt[l][r][up];
	int mx=0,tot=0,cnt=0;
	for(int i=l;i<=r;i++)
	{
		if(!ok[i])
		{
			if(mx==0||len[mx]<len[i])mx=i;
			if(cnt)
			{
				tot++;
				cnt=0;
			}
		}
		else if(ok[i]&&len[i]<=up)cnt++;
	}
	if(cnt)tot++;
	if(tot==0)return tt[l][r][up]=0;
	if(mx==0)return tt[l][r][up]=tot;
//	printf("%d %d %d tot= %d mx= %d\n",l,r,up,tot);
	return tt[l][r][up]=min(dfs(l,mx-1,len[mx])+dfs(mx+1,r,len[mx])+1,min(dfs(l,mx-1,up)+dfs(mx+1,r,up),tot));
}
int main()
{
	get1(n);
	for(int i=1;i<=n;i++)
	{
		scanf("%s%d",tmp,len+i);
		if(tmp[0]=='y')ok[i]=1;
	}
	printendl(dfs(1,n,inf));
	return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 61408
final_rank: 2

code_snippet: // This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int n,len[1111],ok[1111],mn[1111][1111];
map<int,int> tt[1111][1111];
char tmp[5];
int dfs(int l,int r,int up)
{
	if(l>r)return 0;
	if(tt[l][r].find(up)!=tt[l][r].end())return tt[l][r][up];
	int mx=0,tot=0,cnt=0;
	for(int i=l;i<=r;i++)
	{
		if(!ok[i]&&(mx==0||len[mx]<len[i]))
		{
			mx=i;
			if(cnt)
			{
				tot++;
				cnt=0;
			}
		}
		else if(ok[i]&&len[i]<=up)cnt++;
	}
	if(cnt)tot++;
	if(tot==0)return 0;
	if(mx==0)return tot;
//	printf("%d %d %d tot= %d mx= %d\n",l,r,up,tot);
	return min(dfs(l,mx-1,len[mx])+dfs(mx+1,r,len[mx])+1,min(dfs(l,mx-1,up)+dfs(mx+1,r,up),tot));
}
int main()
{
	get1(n);
	for(int i=1;i<=n;i++)
	{
		scanf("%s%d",tmp,len+i);
		if(tmp[0]=='y')ok[i]=1;
	}
	printendl(dfs(1,n,inf));
	return 0;
}
accuracy: 0.05555555555555555
time_ms: 20
memory_kb: 60956
final_rank: 4

code_snippet: // This amazing code is by Eric Sunli Chen.
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
template<typename T> void get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'; t=getchar());
	if(t=='-')neg=true,t=getchar();
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) get1(a),get1(b)
#define get3(a,b,c) get1(a),get2(b,c)
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

int n,len[1111],ok[1111],mn[1111][1111];
map<int,int> tt[1111][1111];
char tmp[5];
int dfs(int l,int r,int up)
{
//	printf("%d %d %d\n",l,r,up);
	if(l>r)return 0;
	if(tt[l][r].find(up)!=tt[l][r].end())return tt[l][r][up];
	int mx=0,tot=0,cnt=0;
	for(int i=l;i<=r;i++)
	{
		if(!ok[i]&&(mx==0||len[mx]<len[i]))
		{
			mx=i;
			if(cnt)
			{
				tot++;
				cnt=0;
			}
		}
		else if(ok[i]&&len[i]<=up)cnt++;
	}
	if(cnt)tot++;
	if(tot==0)return 0;
	if(mx==0)return cnt;
	return min(dfs(l,mx-1,len[mx])+dfs(mx+1,r,len[mx])+1,min(dfs(l,mx-1,up)+dfs(mx+1,r,up),tot));
}
int main()
{
	get1(n);
	for(int i=1;i<=n;i++)
	{
		scanf("%s%d",tmp,len+i);
		if(tmp[0]=='y')ok[i]=1;
	}
	printendl(dfs(1,n,inf));
	return 0;
}
accuracy: 0.05555555555555555
time_ms: 20
memory_kb: 60972
final_rank: 5