QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#571754#8943. Challenge Matrix MultiplicationyyyyxhWA 12ms61240kbC++141.6kb2024-09-18 07:58:202024-09-18 07:58:20

Judging History

你现在查看的是最新测评结果

  • [2024-09-18 07:58:20]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:61240kb
  • [2024-09-18 07:58:20]
  • 提交

answer

#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
int read(){
	char c=getchar();int x=0;
	while(c<48||c>57) c=getchar();
	do x=x*10+(c^48),c=getchar();
	while(c>=48&&c<=57);
	return x;
}
const int N=1000003,M=123,INF=0x3f3f3f3f;
typedef pair<int,int> pii;
int n,m,rk,cnt,num;
int ver[N+M];
vector<int> vec[N];
vector<pii> bel[N];
int od[N],id[N];
int stk[N+M],tp;
int f[M][M],s[M];bool vis[M];
int ans[N];
inline void chmn(int &x,int v){if(x>v) x=v;}
void dfs(int u){
	if(!vec[u].empty()){
		int x=vec[u].back();
		vec[u].pop_back();
		int v=ver[x];
		--od[u];--id[v];
		dfs(v);
		stk[++tp]=x;
	}
}
int main(){
	n=read();rk=m=read();
	for(int i=1;i<=m;++i){
		int u=read(),v=read();
		ver[i]=v;++od[u];++id[v];
		vec[u].emplace_back(i);
	}
	for(int u=1;u<=n;++u){
		while(od[u]>id[u]){
			tp=0;
			dfs(u);
			if(tp){
				++cnt;
				bel[u].emplace_back(cnt,++num);
				while(tp){
					int x=stk[tp--];
					bel[ver[x]].emplace_back(cnt,++num);
				}
			}
		}
	}
	for(int i=1;i<=cnt;++i)
		for(int j=1;j<=cnt;++j) f[i][j]=INF;
	for(int i=n;i;--i){
		if(bel[i].empty()) ans[i]=1;
		else{
			static int g[M];
			for(int j=1;j<=cnt;++j) g[j]=INF;
			for(auto [x,p]:bel[i])
				for(int j=1;j<=cnt;++j) chmn(g[j],f[x][j]);
			for(auto [x,p]:bel[i]){
				if(vis[x]) s[p]=s[p+1];
				else vis[x]=1;
				g[x]=p;
			}
			++s[bel[i].begin()->second];
			for(int j=1;j<=cnt;++j)
				if(g[j]!=INF) ans[i]+=s[g[j]];
			for(auto [x,p]:bel[i])
				for(int j=1;j<=cnt;++j) f[x][j]=g[j];
		}
	}
	for(int i=1;i<=n;++i) printf("%d ",ans[i]);
	putchar('\n');
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 59080kb

input:

4 6
1 3
2 3
2 4
1 2
1 3
1 3

output:

4 3 1 1 

result:

ok 4 number(s): "4 3 1 1"

Test #2:

score: 0
Accepted
time: 3ms
memory: 59080kb

input:

5 7
1 4
1 5
1 2
2 4
3 4
2 5
1 4

output:

4 3 2 1 1 

result:

ok 5 number(s): "4 3 2 1 1"

Test #3:

score: -100
Wrong Answer
time: 12ms
memory: 61240kb

input:

100 900
89 90
34 35
45 46
97 98
41 42
59 61
19 20
25 29
2 3
28 29
54 55
77 78
69 74
60 61
43 44
13 14
92 93
65 66
68 69
72 73
78 81
54 56
55 60
14 15
9 10
92 93
10 11
18 19
16 17
97 98
76 77
39 40
71 72
7 8
63 64
7 8
16 24
13 24
83 84
90 91
1 4
4 5
96 97
81 82
91 92
80 81
66 67
19 20
3 4
9 10
47 48
...

output:

1623 1624 1712 1768 1759 1759 1850 1851 1857 1955 1996 2047 2097 2177 2176 1714 2221 2221 2548 2547 2547 2547 2547 2547 2838 2883 2898 3020 3033 3033 2291 2341 2341 2342 2385 2451 2537 2800 2811 1924 1923 1922 1926 1925 1924 1923 1922 1921 2001 2095 1292 1292 1292 802 801 800 799 798 797 850 998 997...

result:

wrong answer 1st numbers differ - expected: '100', found: '1623'