Submission #897439

# Submission time Handle Problem Language Result Execution time Memory
897439 2024-01-03T05:47:07 Z Faisal_Saqib Wombats (IOI13_wombats) C++17
39 / 100
20000 ms 203660 KB
#include "wombats.h"
#include <iostream>
#include <set>
using namespace std;
int h[5000][200];
int v[5000][200];
int dist[5000][200];
int dist_level[100][5000][100];
int n,m;
int ans=0;
bool Valid(int i,int j){
	return (0<=i and i<n and 0<=j and j<m);
}
void khatam(int st)
{
	set<pair<int,pair<int,int>>> sp;
	dist_level[st][0][st]=0;
	sp.insert({0,{0,st}});
	while(sp.size())
	{
		auto f=*begin(sp);
		sp.erase(begin(sp));
		if(Valid(f.second.first+1,f.second.second) and dist_level[st][f.second.first+1][f.second.second]>(f.first+v[f.second.first][f.second.second]))
		{
			sp.erase({dist_level[st][f.second.first+1][f.second.second],{f.second.first+1,f.second.second}});
			dist_level[st][f.second.first+1][f.second.second]=(f.first+v[f.second.first][f.second.second]);
			sp.insert({dist_level[st][f.second.first+1][f.second.second],{f.second.first+1,f.second.second}});
		}
		if(Valid(f.second.first,f.second.second+1) and dist_level[st][f.second.first][f.second.second+1]>(f.first+h[f.second.first][f.second.second]))
		{
			sp.erase({dist_level[st][f.second.first][f.second.second+1],{f.second.first,f.second.second+1}});
			dist_level[st][f.second.first][f.second.second+1]=(f.first+h[f.second.first][f.second.second]);
			sp.insert({dist_level[st][f.second.first][f.second.second+1],{f.second.first,f.second.second+1}});
		}
		if(Valid(f.second.first,f.second.second-1) and dist_level[st][f.second.first][f.second.second-1]>(f.first+h[f.second.first][f.second.second-1]))
		{
			sp.erase({dist_level[st][f.second.first][f.second.second-1],{f.second.first,f.second.second-1}});
			dist_level[st][f.second.first][f.second.second-1]=(f.first+h[f.second.first][f.second.second-1]);
			sp.insert({dist_level[st][f.second.first][f.second.second-1],{f.second.first,f.second.second-1}});
		}
	}
}
void init(int r, int c, int H[5000][200], int V[5000][200])
{
	n=r;
	m=c;
	for(int i=0;i<r;i++)
	{
		for(int j=0;j<(c-1);j++)
		{
			ans+=H[i][j];
			h[i][j]=H[i][j];
		}
	}
	for(int i=0;i<(r-1);i++)
	{
		for(int j=0;j<c;j++)
		{
			ans+=V[i][j];
			v[i][j]=V[i][j];
		}
	}
	if(m<=100)
	{
		for(int st=0;st<m;st++)
		{
			for(int i=0;i<n;i++)
				for(int j=0;j<m;j++)
					dist_level[st][i][j]=2e9;
			khatam(st);
		}
	}
}
void changeH(int p, int q, int w)
{
	ans-=h[p][q];
	ans+=w;
	h[p][q]=w;
	if(m<=100)
	{
		for(int st=0;st<m;st++)
		{
			for(int i=0;i<n;i++)
				for(int j=0;j<m;j++)
					dist_level[st][i][j]=2e9;
			khatam(st);
		}
	}
}
void changeV(int p, int q, int w)
{
	ans-=v[p][q];
	ans+=w;
	v[p][q]=w;
	if(m<=100)
	{
		for(int st=0;st<m;st++)
		{
			for(int i=0;i<n;i++)
				for(int j=0;j<m;j++)
					dist_level[st][i][j]=2e9;
			khatam(st);
		}
	}
}
int escape(int V1, int V2)
{
	if(m==1)
		return ans;
	else if(m<=100)
		return dist_level[V1][n-1][V2];
	for(int i=0;i<n;i++)
		for(int j=0;j<m;j++)
			dist[i][j]=2e9;
	set<pair<int,pair<int,int>>> sp;
	dist[0][V1]=0;
	sp.insert({0,{0,V1}});
	while(sp.size())
	{
		auto f=*begin(sp);
		if(f.second.first==(n-1) and f.second.second==V2)
			return f.first;
		sp.erase(begin(sp));
		if(Valid(f.second.first+1,f.second.second) and dist[f.second.first+1][f.second.second]>(f.first+v[f.second.first][f.second.second]))
		{
			sp.erase({dist[f.second.first+1][f.second.second],{f.second.first+1,f.second.second}});
			dist[f.second.first+1][f.second.second]=(f.first+v[f.second.first][f.second.second]);
			sp.insert({dist[f.second.first+1][f.second.second],{f.second.first+1,f.second.second}});
		}
		if(Valid(f.second.first,f.second.second+1) and dist[f.second.first][f.second.second+1]>(f.first+h[f.second.first][f.second.second]))
		{
			sp.erase({dist[f.second.first][f.second.second+1],{f.second.first,f.second.second+1}});
			dist[f.second.first][f.second.second+1]=(f.first+h[f.second.first][f.second.second]);
			sp.insert({dist[f.second.first][f.second.second+1],{f.second.first,f.second.second+1}});
		}
		if(Valid(f.second.first,f.second.second-1) and dist[f.second.first][f.second.second-1]>(f.first+h[f.second.first][f.second.second-1]))
		{
			sp.erase({dist[f.second.first][f.second.second-1],{f.second.first,f.second.second-1}});
			dist[f.second.first][f.second.second-1]=(f.first+h[f.second.first][f.second.second-1]);
			sp.insert({dist[f.second.first][f.second.second-1],{f.second.first,f.second.second-1}});
		}
	}
	return 0;
}

Compilation message

grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
   15 |  int res;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Correct 102 ms 12888 KB Output is correct
2 Correct 106 ms 12892 KB Output is correct
3 Correct 153 ms 14416 KB Output is correct
4 Correct 103 ms 12900 KB Output is correct
5 Correct 104 ms 12900 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4528 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 8 ms 45404 KB Output is correct
5 Correct 5 ms 45492 KB Output is correct
6 Correct 5 ms 45404 KB Output is correct
7 Correct 6 ms 45496 KB Output is correct
8 Correct 6 ms 43356 KB Output is correct
9 Correct 6 ms 45404 KB Output is correct
10 Correct 6 ms 43356 KB Output is correct
11 Correct 60 ms 46496 KB Output is correct
12 Correct 6 ms 45404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17985 ms 203652 KB Output is correct
2 Execution timed out 20037 ms 201596 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 614 ms 20568 KB Output is correct
2 Correct 633 ms 20732 KB Output is correct
3 Correct 620 ms 20824 KB Output is correct
4 Correct 642 ms 21584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17930 ms 203660 KB Output is correct
2 Execution timed out 20079 ms 201536 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17874 ms 203648 KB Output is correct
2 Execution timed out 20051 ms 201556 KB Time limit exceeded
3 Halted 0 ms 0 KB -