General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
96775374 Practice:
xiahongyu
939F - 31 GNU C++11 Accepted 46 ms 7836 KB 2020-10-26 15:22:06 2020-10-26 15:22:06
 
 
→ Source
#include<bits/stdc++.h>
using namespace std;
const int M=4e5+5;
int f[M],g[M],n,m,st[M],ed[M];
int q[M],l,r;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1,x,y;i<=m;i++)scanf("%d%d",&st[i],&ed[i]);
	memset(g,0x3f,sizeof(g));
	g[0]=0;
	for(int i=1;i<=m;i++){
		for(int j=0;j<=n;j++)f[j]=g[j];
		l=r=0;int k=ed[i]-st[i];
		for(int j=0;j<=n;j++){
			while(l<r&&j-q[l+1]>k)++l;
			while(l<r&&f[q[r]]>=f[j])--r;
			q[++r]=j;
			if(l<r)g[j]=min(g[j],f[q[l+1]]+2);
		}
		l=r=0;
		for(int j=ed[i];j>=st[i];j--){
			while(l<r&&f[q[r]]>=f[j])--r;
			q[++r]=j;
		}
		for(int j=0;j<=n;j++){
			while(l<r&&q[l+1]>ed[i]-j)++l;
			if(st[i]-j>=0){
				while(l<r&&f[q[r]]>=f[st[i]-j])--r;
				q[++r]=st[i]-j;
			}
			if(l<r)g[j]=min(g[j],f[q[l+1]]+1);
		}
	}
	if(g[n]>1e9)puts("Hungry");
	else{puts("Full");printf("%d",g[n]);}
	return 0;
}
 
 
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details