跳到正文

个人记录

CF656G You're a Professional 题解

cff_0102约 4 分钟
原文
文章信息与版本

文章信息

发布
2024年2月24日
收录
2025年12月12日
更新
2026年9月15日
篇幅
约 4 分钟
获赞
1

版本

  1. v1当前

如果你在洛谷提交本题,建议绑定个人账号。

这是一道愚人节题目,首先你需要完成这道题,然后根据评测机的要求修改你的代码(同时还要保证你仍然能 AC 这题)。

这道题比较简单,数据范围都小于等于 1010。可以开一个桶记录对于每个物品来说喜欢它的人数,最后遍历一遍,直接输出答案。

C++
#include<bits/stdc++.h>
using namespace std;
int a[542457];
int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	int f,i,t;cin>>f>>i>>t;
	for(int x=0;x<f;x++){
		for(int y=0;y<i;y++){
			char c;
			cin>>c;
			if(c=='Y')a[y]++;
		}
	}
	int s=0;
	for(int x=0;x<i;x++){
		if(a[x]>=t)s++;
	}
	cout<<s;
	return 0;
}

洛谷记录:https://www.luogu.com.cn/record/148233739。

CF 记录:https://codeforces.com/contest/656/submission/248050609。

可以看到,评测机返回了一个错误信息:

代码
Support of this language is discontinued, starting today. Please rewrite your project using something more modern.

所以我们要换一个语言提交这道题。

Python
a = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
f, i, t = map(int, input().strip().split())
for x in range(f):
	c = input()
	for y in range(i):
		if c[y] == 'Y':
			a[y] += 1
s = 0
for x in a:
	if x >= t:
		s += 1
print(s)

洛谷记录:https://www.luogu.com.cn/record/148235981。

CF 记录:https://codeforces.com/contest/656/submission/248052451。

可以看到,评测机返回了一个错误信息:

代码
So many characters... Can't your code be shorter? Please remove 21 more characters.

所以我们要尝试减少代码中的字符数量,且至少要减少 2121 个字符。

Python
a=[0]*10
f,i,t=map(int,input().strip().split())
while f:
	f-=1
	c=input()
	for y in range(i):
		if c[y]=='Y':
			a[y]+=1
s=0
for x in a:
	if x>=t:
		s+=1
print(s)

洛谷记录:https://www.luogu.com.cn/record/148237471。

CF 记录:https://codeforces.com/contest/656/submission/248053624。

此时评测机返回:

代码
So many characters... Can't your code be shorter? Please remove 5 more characters.

说明还要进一步减少字符数量。不难发现,洛谷提交时,会添加一行注释,表示提交的评测号码。直接在 CF 提交就没有这行注释。这样可以进一步减少字符数量。

CF 记录:https://codeforces.com/contest/656/submission/248054280。

评测机返回:

代码
Needs a finishing touch... Can you add a kitten?

所以要在代码中加上一个 kitten。

最终 AC 代码如下(经过我的努力,最后成功编写出了一份在洛谷上提交,也就是有第一行注释的情况下最后也能 AC 的 Python 代码):

Python
a=[0]*10
f,i,t=map(int,input().split())
while f:
	f-=1
	c=input()
	for y in range(i):
		if c[y]=='Y':
			a[y]+=1
s=0
for x in a:
	s+=(x>=t)
print(s)#kitten

洛谷记录:https://www.luogu.com.cn/record/148239460。

CF 记录:https://codeforces.com/contest/656/submission/248055382。

原文
存档评论10 条抓取于