ICPC Russia Just the Last Digit

J. Just the Last Digit
time limit per test2 seconds
memory limit per test512 megabytes
inputstandard input
outputstandard output
Jessie has recently started jogging and tracking the progress with a fitness band. There are n spectacular spots on a nearby hill. As running uphill is hard for an amateur jogger, Jessie is only going to run downhill. The spots have numbers from 1 to n, the higher the number is, the lower the spot is. Some pairs of spots are connected by trails, and for our purpose, we will only consider trails i→j going from a higher spot to a lower spot (i<j).

Jessie successfully finished some number of jogs, running through each possible sequence of spots, for which a trail between any two consecutive spots exists, exactly once. Now Jessie is planning to restore the map of all trails with the help of data collected by the fitness band. Unfortunately, the display on the band is small, and can only show the last digit of the number of jogs Jessie did between each pair of spots i and j where 1≤i<j≤n. Can you help Jessie restore the map of the hill given this data?

Input
The first line of the input contains an integer n — the number of spots on the hill (2≤n≤500). Next, n lines follow: the i-th line contains n characters ai,1,ai,2,…,ai,n. Character ai,j is the last digit of the number of different jogs made by Jessie starting at the i-th spot and ending at the j-th spot. For every i≥j, ai,j=0.

It is guaranteed that a solution always exists for the given input data.

Output
Print n lines, describing the map of the hill in the similar format: the i-th line should contain n characters, where j-th character is 1 if there is a trail from the i-th spot to the j-th spot, and 0 otherwise. For every i≥j, the j-th character in the i-th row must be 0.

Example
inputCopy
5
01113
00012
00001
00001
00000
outputCopy
01100
00011
00001
00001
00000


从后往前枚举每一个点。

比如当前看s到t的路径条数,那么只能通过s+1到t-1的所有点中转。如果最后和 g[s][t] 不相等,那么肯定s到t有直接的连线。


AC代码:

#pragma GCC optimize(2)
#include<bits/stdc++.h>
//#define int long long
using namespace std;
const int N=510;
int n,g[N][N],res[N][N];
char a[N][N];
signed main(){
	cin>>n;
	for(int i=1;i<=n;i++)	scanf("%s",a[i]+1);
	for(int i=1;i<=n;i++)	for(int j=1;j<=n;j++)	g[i][j]=a[i][j]-'0';
	for(int i=n-1;i>=1;i--){
		for(int j=i+1;j<=n;j++){
			int t=0;
			for(int k=i+1;k<j;k++)	t=(t+res[i][k]*g[k][j])%10;
			if(t!=a[i][j]-'0')	res[i][j]=1;
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)	cout<<res[i][j];puts("");
	}
	return 0;
}
全部评论

相关推荐

HR_丸山彩同学:你的项目描述里,系统设计讲了很多:MemCube是什么、三级存储架构怎么设计、四种遗忘策略分别是什么。这些面试的时候讲没问题,但简历上不需要这么细。 简历要突出的是影响力,不是实现细节。面试官看简历的时候想知道的是「这个项目有多大价值」,不是「这个项目具体怎么实现的」。实现细节是面试时候聊的 怎么改:技术细节可以精简为一句「采用三级存储架构+四种遗忘策略」,把省出来的篇幅用来写影响力。比如:项目有没有开源?有没有写成技术博客?有没有被别人使用过? 校园经历没有任何信息量,任何人都可以写这句话,写了等于没写。更关键的是,你投的是技术岗,校园活动经历本来就不是加分项。如果非要写,必须写出具体的数字和成果。如果你没有这些数字,那就老老实实删掉 「端到端耗时缩减30-40%」要给出确切数字和绝对值。从1000ms降到600ms是降了40%,从100ms降到60ms也是降了40%,但这两个含义完全不一样。其他也是,涉及到数据,准备好证据,口径统一,面试会问 「熟练」「熟悉」「了解」混在一起用,读起来很乱。而且「了解前端需求」最好改成「具备前后端协作经验」
点赞 评论 收藏
分享
01-22 14:36
门头沟学院 Java
不知道怎么取名字_:我就好奇,你是这家的hr还是?咋这都能搞到
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务