/ Randle /

记录详情

Accepted


  
# 状态 耗时 内存占用
#1 Accepted 2ms 328.0 KiB
#2 Accepted 2ms 324.0 KiB
#3 Accepted 1ms 324.0 KiB
#4 Accepted 2ms 448.0 KiB
#5 Accepted 2ms 456.0 KiB
#6 Accepted 33ms 1.191 MiB
#7 Accepted 26ms 1.066 MiB
#8 Accepted 40ms 1.316 MiB
#9 Accepted 26ms 1.07 MiB
#10 Accepted 34ms 1.059 MiB

代码

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;

int f[1005], g[1005], cnt[1005], n;

int cmp(int i, int j) {
	if (cnt[i] == cnt[j]) return (i < j);
	return cnt[i] < cnt[j];	
}

int main() {
	string s[1005];
	vector<int> v;

//	freopen("relations.in", "r", stdin);
//	freopen("relations.out", "w", stdout);

	cin >> n;

	for(int i=0; i<n; i++) {
		cin >> s[i];
		v.push_back(i);
		cnt[i] = 0;

		for(int j=0; j<n; j++) {
			if (s[i][j] == '1') {
				cnt[i]++;
			}
		}
	}

	sort(v.begin(), v.end(), cmp);
	bool correct = true;

	for(int i=0; i<n-1; i++) {
		int x = v[i];
		int y = v[i+1];

		for(int j=0; j<n; j++) 
			if (s[x][j] > s[y][j]) {
				correct = false;
				break;		
			}

		if(!correct) break;	
	}

	for(int i=0; i<n; i++) f[i] = n - cnt[i];
	for(int i=0; i<n; i++) {
		for(int j=0; j<n; j++) {
			if (s[i][j] == '1') g[j] = max(g[j], f[i]);
		}
	}

	if (correct) {
		cout << "YES" << endl;
		for(int i=0; i<n; i++) cout << f[i] << " ";
		cout << endl;
		for(int i=0; i<n; i++) cout << g[i] << " ";
		cout << endl;	
	} else {
		cout << "NO" << endl;
	}


}

信息

递交者
类型
递交
题目
关系 T3
题目数据
下载
语言
C++
递交时间
2017-10-06 20:12:10
评测时间
2017-10-06 20:12:10
评测机
分数
100
总耗时
170ms
峰值内存
1.316 MiB