Submission #2105827


Source Code Expand

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc080.contest.atcoder.jp/tasks/arc080_a>
問題文============================================================
 長さ N の数列 a=(a1,a2,…,aN) があります。 各 ai は正の整数です。
 
 すぬけ君の目標は、a の要素を自由に並べ替え、次の条件が成り立つようにすることです。
 
 各 1≤i≤N−1 について、ai と ai+1 の積は 4 の倍数である。
 すぬけ君が目標を達成できるか判定してください。

=================================================================

解説=============================================================

 まず、4の倍数の数値(4の倍数を v 、4の倍数でない値を x とする)が存在する時
 
 x v x v x v x v ... とおいていけば条件を満たす
 つまり、4の倍数である値の個数を V とすると 2*V 分カバーできる
 
 注意:
     x v x v x v ... x v x
 で数列が終了する時 2*V + 1 == N をカバーできる
 
 2*c で 数列全てをカバーできない時, 2の倍数をb とすると
 
 x v x v x v x v ... x v b b b b b b .... b
 
 とおいていけば条件を満たす
 
 よって上の注意ケースを除いて,2の倍数の個数とBとすると
 
 2*V + B >= N
 
 となっていれば条件を満たす

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    vector<ll> a(N);
    for(auto & in:a) cin >> in;
    ll four = 0, two = 0;
    for(int i = 0; i < N;i++){
        if(a[i]%4 == 0) four++;
        if(a[i]%2 == 0) two++;
    }
    two -= four;
    if(four*2 + 1 >= N){
        cout << "Yes" << endl;
        return 0;
    }
    if(four*2 + two >= N){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
	return 0;
}

Submission Info

Submission Time
Task C - 4-adjacent
User vjudge4
Language C++14 (GCC 5.4.1)
Score 400
Code Size 2028 Byte
Status AC
Exec Time 11 ms
Memory 1024 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 5
AC × 19
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 0_04.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt, 1_11.txt, 1_12.txt, 1_13.txt
Case Name Status Exec Time Memory
0_00.txt AC 1 ms 256 KB
0_01.txt AC 1 ms 256 KB
0_02.txt AC 1 ms 256 KB
0_03.txt AC 1 ms 256 KB
0_04.txt AC 1 ms 256 KB
1_00.txt AC 1 ms 256 KB
1_01.txt AC 1 ms 256 KB
1_02.txt AC 1 ms 256 KB
1_03.txt AC 1 ms 256 KB
1_04.txt AC 1 ms 256 KB
1_05.txt AC 1 ms 256 KB
1_06.txt AC 1 ms 256 KB
1_07.txt AC 11 ms 1024 KB
1_08.txt AC 11 ms 1024 KB
1_09.txt AC 11 ms 1024 KB
1_10.txt AC 11 ms 1024 KB
1_11.txt AC 11 ms 1024 KB
1_12.txt AC 11 ms 1024 KB
1_13.txt AC 11 ms 1024 KB