CodeForces - 417B (思维题)
2016-05-24 10:16
543 查看
Crash
Submit Status
Description
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.
Each participant is identified by some unique positive integer k, and each sent solution A is characterized by two numbers: x — the number of different solutions that are sent before the first solution identical to A, and k — the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same x.
It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with numberx(x > 0) of the participant with number k, then the testing system has a solution with number x - 1 of the same participant stored somewhere before.
During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.
Input
The first line of the input contains an integer n (1 ≤ n ≤ 105) — the number of solutions. Each of the following n lines contains two integers separated by space x and k (0 ≤ x ≤ 105; 1 ≤ k ≤ 105) — the number of previous unique solutions and the identifier of the participant.
Output
A single line of the output should contain «YES» if the data is in chronological order, and «NO» otherwise.
Sample Input
Input
Output
Input
Output
Input
Output
Source
RCC 2014 Warmup (Div. 2)
Time Limit: 1000MS | Memory Limit: 262144KB | 64bit IO Format: %I64d & %I64u |
Description
During the "Russian Code Cup" programming competition, the testing system stores all sent solutions for each participant. We know that many participants use random numbers in their programs and are often sent several solutions with the same source code to check.
Each participant is identified by some unique positive integer k, and each sent solution A is characterized by two numbers: x — the number of different solutions that are sent before the first solution identical to A, and k — the number of the participant, who is the author of the solution. Consequently, all identical solutions have the same x.
It is known that the data in the testing system are stored in the chronological order, that is, if the testing system has a solution with numberx(x > 0) of the participant with number k, then the testing system has a solution with number x - 1 of the same participant stored somewhere before.
During the competition the checking system crashed, but then the data of the submissions of all participants have been restored. Now the jury wants to verify that the recovered data is in chronological order. Help the jury to do so.
Input
The first line of the input contains an integer n (1 ≤ n ≤ 105) — the number of solutions. Each of the following n lines contains two integers separated by space x and k (0 ≤ x ≤ 105; 1 ≤ k ≤ 105) — the number of previous unique solutions and the identifier of the participant.
Output
A single line of the output should contain «YES» if the data is in chronological order, and «NO» otherwise.
Sample Input
Input
2 0 1 1 1
Output
YES
Input
4 0 1 1 2 1 1 0 2
Output
NO
Input
4 0 1 1 1 0 1 0 2
Output
YES
Source
RCC 2014 Warmup (Div. 2)
#include <iostream> #include <stdio.h> #include <stdlib.h> #include<string.h> #include<algorithm> #include<math.h> using namespace std; int a[100010]; int main() { int i,n,m,x,k; while(cin>>n) { int flag=0; memset(a,-1,sizeof(a)); for (i=0;i<n;i++) { cin>>x>>k; if (a[k]+1<x) flag=1; a[k]=max(a[k],x); } if (flag) cout<<"NO"<<endl; else cout<<"YES"<<endl; } return 0; }
相关文章推荐
- CodeForces - 417A(思维题)
- 属性访问函数
- CodeForces - 416A (判断大于小于等于 模拟题)
- 使用Redis保存Spring session(基于XML配置文件)
- session 、cookie、token的区别
- CodeForces - 407A
- CodeForces - 407B
- 模式识别(Pattern Recognition)学习笔记(十二)--SVM(广义):大间隔
- 83-Add Binary
- awk入门
- linux生成指定大小的文件
- 后台给GridView绑定数据时给每一行添加一个JS方法
- 网格弹簧质点系统模拟(Spring-Mass System by Fast Method)附源码
- CodeForces - 405C
- GridView相关问题解决
- CodeForces - 405A
- CodeForces - 404B(模拟题)
- CodeForces - 404A(模拟题)
- Codeforces 390A( 模拟题)
- Codeforces 389B(十字模拟)