• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Codeforce Round #219 Div2 A

A. Collecting Beats is Fun
time limit per test 1 second
memory limit per test 256 megabytes
 

Cucumber boy is fan of Kyubeat, a famous music game.

Kyubeat has 16 panels for playing arranged in 4 × 4 table. When a panel lights up, he has to press that panel.

Each panel has a timing to press (the preffered time when a player should press it), and Cucumber boy is able to press at most k panels in a time with his one hand. Cucumber boy is trying to press all panels in perfect timing, that is he wants to press each panel exactly in its preffered time. If he cannot press the panels with his two hands in perfect timing, his challenge to press all the panels in perfect timing will fail.

You are given one scene of Kyubeat's panel from the music Cucumber boy is trying. Tell him is he able to press all the panels in perfect timing.

Input

The first line contains a single integer k (1 ≤ k ≤ 5) — the number of panels Cucumber boy can press with his one hand.

Next 4 lines contain 4 characters each (digits from 1 to 9, or period) — table of panels. If a digit i was written on the panel, it means the boy has to press that panel in time i. If period was written on the panel, he doesn't have to press that panel.

Output

Output "YES" (without quotes), if he is able to press all the panels in perfect timing. If not, output "NO" (without quotes).

Sample test(s)
Input
1 
.135
1247
3468
5789
Output
YES
Input
5 
..1.
1111
..1.
..1.
Output
YES
Input
1 
....
12.1
.2..
.2..
Output
NO
Note

In the third sample boy cannot press all panels in perfect timing. He can press all the panels in timing in time 1, but he cannot press the panels in time 2 in timing with his two hands.

 1 #include <cstdio>
 2 #include <vector>
 3 #include <cmath>
 4 #include <queue>
 5 #include <cstring>
 6 #include <algorithm>
 7 using namespace std;
 8 #define INF 0x7fffffff
 9 #define mod 1000000007
10 #define ll long long
11 #define maxn 1005
12 int w, k, n, m, ans;
13 int dp[maxn][maxn];
14 int a[505000],vis[505000];
15 char s[1010][1010];
16 struct node{
17     int a, pos;
18 }t[505000];
19 int main(){
20     scanf("%d", &n);
21     for (int i = 0; i < 4; i++)scanf("%s", s[i]);
22     for (int i = 0; i < 4;i++)
23     for (int j = 0; j < 4;j++)
24     vis[s[i][j] - '0']++;
25     int flag = 1;
26     for (int i = 1; i <= 9; i++){
27         if (vis[i]>2 * n){ flag = 0; break; }
28     }
29     if (flag)printf("YES\n"); else printf("NO\n");
30     return 0;
31 }
View Code
posted @ 2013-12-14 00:04  HaibaraAi  阅读(154)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3