Submission #363889

# Submission time Handle Problem Language Result Execution time Memory
363889 2021-02-07T12:52:35 Z ogibogi2004 Shell (info1cup18_shell) C++14
0 / 100
273 ms 30828 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN=1e6+6;
const ll mod=1e9+7;
int n,m,p;
vector<int>g[MAXN];
vector<int>t;
bool vis[MAXN];
void dfs(int u)
{
	vis[u]=1;
	for(auto v:g[u])
	{
		if(vis[v]==0)
		{
			dfs(v);
		}
	}
	t.push_back(u);
}
int a[MAXN];
int where[MAXN];
int w1[MAXN];
ll dp[MAXN];
int main()
{
	cin>>n>>m>>p;
	for(int i=1;i<=p;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
	}
	for(int i=1;i<=n;i++)
	{
		if(vis[i]==0)
		{
			dfs(i);
		}
	}
	reverse(t.begin(),t.end());
	for(int i=0;i<t.size();i++)where[t[i]]=i;
	for(int i=2;i<=p;i++)
	{
		if(where[i-1]>where[i])
		{
			cout<<"0\n";
			return 0;
		}
	}
	for(int j=where[a[1]]-1;j>=0;j--)w1[j]=where[a[1]];
	for(int i=2;i<=p;i++)
	{
		for(int j=where[a[i]]-1;j>=where[a[i-1]];j--)
		{
			w1[j]=where[a[i]];
		}
	}
	dp[t[0]]=1;
	for(int i=0;i<t.size();i++)
	{
		for(auto v:g[t[i]])
		{
			if(where[v]>w1[i])continue;
			dp[v]+=dp[t[i]];
			dp[v]%=mod;
		}
	}
	cout<<dp[a[p]]<<endl;
return 0;
}

Compilation message

shell.cpp: In function 'int main()':
shell.cpp:47:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |  for(int i=0;i<t.size();i++)where[t[i]]=i;
      |              ~^~~~~~~~~
shell.cpp:65:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |  for(int i=0;i<t.size();i++)
      |              ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23788 KB Output is correct
2 Incorrect 16 ms 23788 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23788 KB Output is correct
2 Incorrect 16 ms 23788 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 23916 KB Output is correct
2 Correct 273 ms 30828 KB Output is correct
3 Correct 262 ms 30828 KB Output is correct
4 Incorrect 265 ms 30828 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23788 KB Output is correct
2 Incorrect 16 ms 23788 KB Output isn't correct
3 Halted 0 ms 0 KB -