QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#666615#7943. LIS on Gridrlc202204WA 11ms3684kbC++141.2kb2024-10-22 19:21:212024-10-22 19:21:33

Judging History

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

  • [2024-10-22 19:21:33]
  • 评测
  • 测评结果:WA
  • 用时:11ms
  • 内存:3684kb
  • [2024-10-22 19:21:21]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 2e5 + 5;

int n, m;
int a[N] = {0}, b[N] = {0};

bool chk(int k) {
	long long ans = 0ll;
	for (int i = 1; i <= m; i++)
		ans += max(0, a[i] - k);
	return ans <= 1ll * k * (n - k); 
}

void slv() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++)
		scanf("%d", &a[i]);
	int l = -1, r = min(n, m);
	while (l + 1 < r) {
		int mid = (l + r) / 2;
		if (chk(mid))
			r = mid;
		else
			l = mid;
	} 
	for (int i = 1; i <= m; i++) 
		b[i] = max(0, a[i] - r);
	vector<vector<char> > ans(n + 1, vector<char>(m + 1, '.'));
	for (int i = 1; i <= r; i++) {
		int pos = n - r + i;
		for (int j = 1; j <= m; j++) {
			while (b[j] > 0 && pos > 1)
				ans[pos][j] = '#', b[j]--, pos--;
			ans[pos][j] = '#';
		}
	}
	for (int j = 1; j <= m; j++) {
		int tot = 0;
		for (int i = 1; i <= n; i++)
			if (tot == a[j])
				ans[i][j] = '.';
			else if (ans[i][j] == '#')
				tot++;
	}
	cout << r << endl;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++)
			cout << ans[i][j];
		cout << endl;
	}
}

int main() {
	int T;
	scanf("%d", &T);
	while (T--)
		slv();	
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3632kb

input:

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

output:

1
....
####
3
###
###
###
2
####
#...
###.
##..
2
..###
.####
####.
###..

result:

ok Correct (4 test cases)

Test #2:

score: -100
Wrong Answer
time: 11ms
memory: 3684kb

input:

5699
5 5
4 5 1 3 5
4 4
3 1 2 4
5 5
2 2 3 3 4
3 4
1 3 2 2
5 5
2 5 3 4 4
4 5
4 1 1 4 1
5 5
3 3 2 5 5
5 5
3 1 3 1 1
5 5
2 4 4 3 2
4 5
2 2 2 2 2
5 5
4 5 3 4 1
5 4
5 4 1 4
5 4
1 1 1 3
4 2
2 4
5 5
2 5 5 2 5
5 5
5 1 2 1 3
5 5
4 4 2 2 3
5 2
5 2
3 5
2 3 3 1 3
5 5
4 2 5 1 1
5 5
4 5 4 1 5
5 4
3 2 5 3
5 5
5 4 1...

output:

3
.####
##..#
##.##
##...
##.##
2
...#
####
#..#
#.##
2
....#
...##
..##.
###.#
#####
2
.###
##..
.###
3
.####
.#..#
##.##
####.
.####
2
#####
#..#.
#..#.
#..#.
3
...##
...##
#####
#####
##.##
1
..###
..#..
###..
#....
#....
2
..###
.##..
.#.##
####.
###..
2
.....
.....
#####
#####
3
.####
##.#.
###...

result:

wrong answer Wrong number of colored cells (test case 1)