Problem:
カードゲーム 2 (Card Game 2)
問題文
ビ太郎は
N
枚のカードを持っており，
i
枚目 (
1 ≦ i ≦ N
) のカードには整数
A
i
が書かれている．
これらの中から次の条件を満たすような
3
枚のカードを選びたい．
条件:
選んだカードに書かれている整数が
3
ずつ離れている．
厳密には，選んだカードに書かれている整数が，ある整数
x
を用いて
x, x+3, x+6
と表せる．
例えば，ビ太郎が
5
枚のカードを持っており，それぞれに
2, 4, 5, 7, 10
が書かれているとき，
4, 7, 10
が書かれているカードを選ぶと，条件を満たす．
ビ太郎が持っているカードの情報が与えられたとき，条件を満たすように
3
枚のカードを選ぶことができるかどうか判定するプログラムを作成せよ．
制約
3 ≦ N ≦ 200 000
．
1 ≦ A
i
≦ 200 000
(
1 ≦ i ≦ N
)．
入力される値はすべて整数である．
入力
入力は以下の形式で与えられる．
N
A
1
A
2
…
A
N
出力
条件を満たすように
3
枚のカードを選ぶことができる場合
Yes
を，そうでない場合
No
を出力せよ．
入出力例
入力例 1
3
2 5 8
出力例 1
Yes
2, 5, 8
が書かれているカードを選ぶと，条件を満たす．したがって，
Yes
を出力する．
入力例 2
4
1 4 6 4
出力例 2
No
条件を満たすようにカードを選ぶことはできない．したがって，
No
を出力する．
入力例 3
8
9 8 11 1 1 6 10 4
出力例 3
No
条件を満たすようにカードを選ぶことはできない．したがって，
No
を出力する．
入力例 4
20
2 15 4 30 6 8 11 27 14 3 16 26 19 2 23 21 18 13 28 6
出力例 4
Yes
15, 18, 21
が書かれているカードを選ぶと，条件を満たす．したがって，
Yes
を出力する．
情報オリンピック日本委員会
作 『第 23 回日本情報オリンピック (JOI 2023/2024) 二次予選競技課題』

Submitted solutions:

code_snippet: #include <iostream>
using namespace std;

int main() {
	int n;
	bool a[200006] = {
		0
	};
	cin >> n;
	for (int i = 0; i < n; i++) {
	    int k;
		cin >> k;
		a[k] = true;
	}
	for (int i = 0; i < 200000; i++) {
		if (a[i] == true && a[i + 3] == true && a[i + 6] == true) {
			cout << "Yes" << endl;
			return 0;
		}


	}
	cout << "No" << endl;
	return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 3628
final_rank: 1

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main(){
    int N;
    cin >> N;
    int A[N];
    for(int i=0; i<N; i++){
        cin >> A[i];
    }

    bool C[200009];
    for(int i=0; i<200008; i++){
        C[i] = false;
    }
    for(int i=0; i<N; i++){
        C[A[i]] = true;
    }
    for(int i=0; i<N; i++){
        if(C[A[i]] == true && C[A[i] + 3] == true && C[A[i] + 6] == true){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}
accuracy: 1
time_ms: 30
memory_kb: 4300
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main(){
    int N;
    cin >> N;
    int A[N];
    for(int i=0; i<N; i++){
        cin >> A[i];
    }

    bool C[200009];
    for(int i=0; i<N; i++){
        C[i] = false;
    }
    for(int i=0; i<N; i++){
        C[A[i]] = true;
    }
    for(int i=0; i<N; i++){
        if(C[A[i]] == true && C[A[i] + 3] == true && C[A[i] + 6] == true){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}
accuracy: 0.5409836065573771
time_ms: 10
memory_kb: 4096
final_rank: 20

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main(){
    int N;
    cin >> N;
    int A[N];
    for(int i=0; i<N; i++){
        cin >> A[i];
    }

    bool C[200009];
    for(int i=0; i<N; i++){
        C[A[i]] = true;
    }
    for(int i=0; i<N; i++){
        if(C[A[i]] == true && C[A[i] + 3] == true && C[A[i] + 6] == true){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}
accuracy: 0.5409836065573771
time_ms: 10
memory_kb: 3916
final_rank: 19

code_snippet: #include<iostream>
using namespace std;
int main(void){
    int n,mx=0;
    cin>>n;
    int a[200000]={0};
    int mod0[200000]={0},mod1[200000]={0},mod2[200000]={0};
    for(int i=0;i<n;i++){
        cin>>a[i];
        mx=max(mx,a[i]);
        if(a[i]%3==1){
            mod1[a[i]]++;
        }
        else if(a[i]%3==2){
            mod2[a[i]]++;
        }
        else{
            mod0[a[i]]++;
        }
    }
    for(int i=0;i<mx-5;i++){
        int k=i;
        if(k%3==0){
            if(mod0[i]>0 and mod0[i+3]>0 and mod0[i+6]>0){
                cout<<"Yes"<<endl;
                return 0;
            }
            
        }
        else if(k%3==1){
            if(mod1[i]>0 and mod1[i+3]>0 and mod1[i+6]>0){
                cout<<"Yes"<<endl;
                return 0;
            }
            
        }
        else{
            if(mod2[i]>0 and mod2[i+3]>0 and mod2[i+6]>0){
                cout<<"Yes"<<endl;
                return 0;
            }
            
    }
    }
    cout<<"No"<<endl;
}
accuracy: 1
time_ms: 20
memory_kb: 6560
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;

vector<bool> cnt(200000, false);

int main(){
    int N;
    cin >> N;
    vector<int> card(N);
    for(auto& i : card){
        cin >> i;
        cnt[i - 1] = true;
    }
    sort(card.begin(), card.end());
    bool flg = false;
    for(int i = 0; i < N - 2; i++){
        if(card[i] <= 199994 && cnt[card[i] + 2] && cnt[card[i] + 5]){
            flg = true;
            break;
        }
    }
    if(flg) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4096
final_rank: 2

code_snippet: #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<ll>
// vv(n, vector<Type>(m, d));
#define vvi vector<vector<ll>>
#define pqmin priority_queue<ll, vector<ll>, greater<ll>>
#define rep(a, b, c) for (ll a = b; a < c; a++)
#define repre(a, b, c) for (ll a = b; a != c; a--)
#define PI 3.14159265359
int main(){
    ll n;
    cin>>n;
    ll a;
    set<ll>s;
    rep(i,0,n){
        cin>>a;
        s.insert(a);
    }
    rep(i,0,199995){
        if(s.find(i)!=s.end()&&s.find(i+3)!=s.end()&&s.find(i+6)!=s.end()){
            cout<<"Yes"<<"\n";
            return 0;
        }
    }
    cout<<"No"<<"\n";
}
accuracy: 1
time_ms: 50
memory_kb: 9960
final_rank: 10

code_snippet: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstdint>
#include <iomanip>
#include <bit>
#include <queue>
#include <stack>
#include <random>
//#include <atcoder/all>

using namespace std;

//using mint = atcoder::modint998244353 ;

void ansYesNo(bool ans, string yes = "Yes", string no = "No")
{
    if (ans)
    {
        cout << yes << endl;
    }
    else
    {
        cout << no << endl;
    }
}

int d[4][2] = {{1,0},{0,1},{-1,0},{0,-1}} ;

template<class T> void outVectorSameLine(vector<T> v){
    for (int i = 0; i < v.size()-1; i++)
    {
        cout << v.at(i) << " " ;
    }
    cout << v.at(v.size()-1) << endl ;
    return ;
}

struct Pos{
    int x ;
    int y ;
};

int main(){
    int n ;
    cin >> n ;
    int max = 200000 ;
    vector<int> b(max + 1,0) ;
    for (int i = 0; i < n; i++)
    {
        int a ;
        cin >> a ;
        b.at(a) ++ ;
    }
    
    bool ans = false ;
    for (int i = 0; i <= max-6 ; i++)
    {
        ans = (b.at(i) > 0 && b.at(i+3) > 0 && b.at(i+6) > 0) ;
        if (ans)
        {
            break ;
        }
        
    }
    ansYesNo(ans) ;
}
accuracy: 1
time_ms: 20
memory_kb: 4096
final_rank: 2

code_snippet: #include<iostream>
using namespace std;

int main(){
    int N, a, i;
    int A[200001];
    int check = 0, max = 0;
    cin >> N;
    for(i = 0; i <= 200001; i++) A[i] = 0;
    for(i = 0; i < N; i++){
        cin >> a;
        A[a] = 1; 
        if(a > max) max = a;
    }

    for(i = 1; i <= 200000; i++){
        if(A[i] == 1 and A[i+3] == 1 and A[i+6] == 1){
            check = 1;
            break;
        }
    }
    if(check == 1) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 4204
final_rank: 4

code_snippet: #include<iostream>
using namespace std;

int main(){
    int N, a, i;
    int A[200001];
    int check = 0, max = 0;
    cin >> N;
    for(i = 0; i < N; i++){
        cin >> a;
        A[a] = 1; 
        if(a > max) max = a;
    }

    for(i = 1; i <= 200000; i++){
        if(A[i] == 1 and A[i+3] == 1 and A[i+6] == 1){
            check = 1;
            break;
        }
    }
    if(check == 1) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}
accuracy: 0.639344262295082
time_ms: 10
memory_kb: 4084
final_rank: 18

code_snippet: #include<iostream>
using namespace std;

int main(){
    int N, a, i;
    int A[200001];
    int check = 0, max = 0;
    cin >> N;
    for(i = 0; i < N; i++){
        cin >> a;
        A[a] = 1; 
        if(a > max) max = a;
    }

    for(i = 1; i <= max - 6; i++){
        if(A[i] == 1 and A[i+3] == 1 and A[i+6] == 1){
            check = 1;
            break;
        }
    }
    if(check == 1) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}
accuracy: 0.7540983606557377
time_ms: 30
memory_kb: 4212
final_rank: 17

code_snippet: #include<iostream>
using namespace std;

int main(){
    int N, a, i;
    int A[200001];
    int check = 0, max = 0;
    cin >> N;
    for(i = 0; i < N; i++){
        cin >> a;
        A[a] = 1; 
        if(a > max) max = a;
    }

    for(i = 1; i <= max; i++){
        if(A[i] == 1 and A[i+3] == 1 and A[i+6] == 1){
            check = 1;
            break;
        }
    }
    if(check == 1) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}
accuracy: 0.7540983606557377
time_ms: 30
memory_kb: 4196
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    vector<int> A(n);
    for(auto&& x:A)cin>>x;
    sort(A.begin(),A.end());
    vector<int> B(0);
    for(int i=0;i<n;i++){
        if(i==0)B.push_back(A[0]);
        else if(A[i-1]!=A[i])B.push_back(A[i]);
    }
    for(uint64_t i=0;i<B.size();i++){
        for(uint8_t j=1;j<B.size()&&j<4;j++){
            if(B[i+j]==B[i]+3){
                for(uint8_t k=1;k<B.size()&&k<4;k++){
                    if(B[i+j+k]==B[i+j]+3){
                        cout<<"Yes"<<endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout<<"No"<<endl;
}
accuracy: 1
time_ms: 30
memory_kb: 4516
final_rank: 7

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    vector<int> A(n);
    for(auto&& x:A)cin>>x;
    sort(A.begin(),A.end());
    vector<int> B(0);
    for(int i=0;i<n;i++){
        if(i==0)B.push_back(A[0]);
        else if(A[i-1]!=A[i])B.push_back(A[i]);
    }
    for(uint64_t i=0;i<B.size();i++){
        for(uint64_t j=0;j<B.size()||j<3;j++){
            if(B[i+j]==B[i]+3){
                for(uint64_t k=0;k<B.size()||k<3;k++){
                    if(B[i+j+k]==B[i+j]+3){
                        cout<<"Yes"<<endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout<<"No"<<endl;
}
accuracy: 0.8524590163934426
time_ms: 180
memory_kb: 4684
final_rank: 15

code_snippet: #include<bits/stdc++.h>
#define endl "\n"
#define ll long long
#define IMAX INT_MAX
#define IMIN INT_MIN
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define efor(i,n) for(int i=0;(n);i++)
using namespace std;
void Yn(bool b, const std::string& yes = "Yes", const std::string& no = "No") {
    std::cout << (b ? yes : no) << '\n';
}

int main () {
    int n;
    cin >> n;
    set <int> A;
    vector <int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
        A.insert(a[i]);
    }
    bool ans=0;
    for(int i=0;i<n;i++){
        if(A.count(a[i]+3)&&A.count(a[i]+6)){
            ans=1;
            break;
        }
    }
    Yn(ans);
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 10116
final_rank: 12

code_snippet: #include <bits/stdc++.h>
#define endl "\n"
using namespace std;

int main(){
    int n;
    cin >> n;
    vector < int > a(n);
    map < int, bool > m;

    for ( int i = 0; i < n; i++ ) {
        cin >> a[i];
        m[a[i]] = true;
    }

    for ( int i = 0; i < n; i++ ) {
        int x = a[i];
        if ( m[x + 3] && m[x + 6] ) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 11952
final_rank: 14

code_snippet: //AC 25..
#include <bits/stdc++.h>

#define endl "\n"
#define sline cout << endl
#define ll long long
#define ull unsigned long long
#define fi int i =
#define fj int j =

using namespace std;

void yesno ( bool Yn ) {
    if (Yn == true) {
        cout << "Yes" << endl;
    }
    else if (Yn == false) {
        cout << "No" << endl;
    }
}

int main() {
    int N;
    cin >> N;
    vector <int> A(N);
    set <int> s;
    for (fi 0; i < N; i++) {
        cin >> A[i];
        s.insert(A[i]);
    }

    for (fi 0; i < N; i++) {
        if (s.count(A[i] + 3) && s.count(A[i] + 6)) {
            yesno(true);
            return 0;
        }
    }

    yesno(false);

return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 10212
final_rank: 13

code_snippet: #include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    unordered_set<int> s(A.begin(), A.end());

    for (int a : A) {
        if (s.count(a + 3) && s.count(a + 6)) {
            cout << "Yes\n";
            return 0;
        }
    }

    cout << "No\n";
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 9656
final_rank: 9

code_snippet: #include <iostream>
using namespace std;
int main(){
    int a[250000]={0};
    int n;
    cin>>n;
    
    for(int i=0; i<n; i++){
        int A;
        cin>>A;
        a[A]++;
    }
    
    for(int i=1; i<=200000-6; i++){
        if(a[i]!=0 && a[i+3]!=0 && a[i+6]!=0){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
    

}
accuracy: 1
time_ms: 30
memory_kb: 4416
final_rank: 6

code_snippet: #include <iostream>
#include <vector>
#include <algorithm>
#include<string>
#include<stack>
#include<set>
using namespace std;

int main() {
    int N;
    string a = "No";
    string d = "D";
    cin >> N;
    vector<int>A(N);
    for (int i = 0; i < N; i++) { cin >> A[i]; }
    set<int> S(A.begin(), A.end());
    vector<int>B(S.begin(), S.end());
    for (int i = 0; i < S.size()-1; i++) {
        string d = "D";
        string p = "D";
        int J = 0;
        int it = B[i];
        for (int j = i + 1; j < i + 4; j++) {
            if (j == S.size()) {
                break;
            }
            if (it + 3 == B[j]) {
                d = "Z";
                J = j;
                break;
            }
        
        } 
        
        it = B[J];
        for (int j = J + 1; j < J + 4; j++) {
            if (j >= S.size()) {
                break;
            }
            if (it + 3 == B[j]) {
                p = "Z";
                break;
            }
        }
        if (d == "Z" and p == "Z") {
            a = "Yes";
            break;
        }
    }
    cout << a << endl;
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 10588
final_rank: 11