提出 #30471713
ソースコード 拡げる
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<int(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
ll N, K, tmp;
vector<ll> A, B;
vector<bool> a, b;
bool ans=false;
int dp(ll now, ll i, char w){
if(i==N){
ans=true;
return i;
}
if(w=='a'){
if(a[i]) return i;
else a[i]=true;
}else{
if(b[i]) return i;
else b[i]=true;
}
if(abs(now-A[i])<=K) dp(A[i], i+1, 'a');
if(abs(now-B[i])<=K) dp(B[i], i+1, 'b');
return i;
}
int main(void){
cin >> N >> K;
A.resize(N);
B.resize(N);
a.resize(N, false);
b.resize(N, false);
rep(i, N) cin >> A[i];
rep(i, N) cin >> B[i];
int res=dp(A[0], 1, 'a');
if(!ans && res==1) res=dp(B[0], 1, 'b');
if(ans) cout << "Yes" << endl;
else cout << "No" << endl;
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | C - Choose Elements |
| ユーザ | m_are |
| 言語 | C++ (GCC 9.2.1) |
| 得点 | 300 |
| コード長 | 984 Byte |
| 結果 | AC |
| 実行時間 | 121 ms |
| メモリ | 12708 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 300 / 300 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | example0.txt, example1.txt, example2.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, example0.txt, example1.txt, example2.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 000.txt | AC | 12 ms | 3556 KiB |
| 001.txt | AC | 2 ms | 3600 KiB |
| 002.txt | AC | 15 ms | 3608 KiB |
| 003.txt | AC | 1 ms | 3540 KiB |
| 004.txt | AC | 2 ms | 3536 KiB |
| 005.txt | AC | 2 ms | 3536 KiB |
| 006.txt | AC | 118 ms | 12328 KiB |
| 007.txt | AC | 114 ms | 9484 KiB |
| 008.txt | AC | 90 ms | 9936 KiB |
| 009.txt | AC | 87 ms | 7044 KiB |
| 010.txt | AC | 119 ms | 12656 KiB |
| 011.txt | AC | 115 ms | 8964 KiB |
| 012.txt | AC | 120 ms | 12580 KiB |
| 013.txt | AC | 115 ms | 8404 KiB |
| 014.txt | AC | 120 ms | 12708 KiB |
| 015.txt | AC | 121 ms | 11788 KiB |
| 016.txt | AC | 118 ms | 12664 KiB |
| 017.txt | AC | 114 ms | 8572 KiB |
| 018.txt | AC | 104 ms | 11404 KiB |
| 019.txt | AC | 75 ms | 7516 KiB |
| 020.txt | AC | 120 ms | 12660 KiB |
| 021.txt | AC | 116 ms | 6224 KiB |
| 022.txt | AC | 119 ms | 12656 KiB |
| 023.txt | AC | 111 ms | 6288 KiB |
| example0.txt | AC | 3 ms | 3464 KiB |
| example1.txt | AC | 2 ms | 3576 KiB |
| example2.txt | AC | 2 ms | 3468 KiB |