結果
| 問題 |
No.74 貯金箱の退屈
|
| コンテスト | |
| ユーザー |
IL_msta
|
| 提出日時 | 2015-07-27 18:21:33 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,385 bytes |
| コンパイル時間 | 920 ms |
| コンパイル使用メモリ | 97,984 KB |
| 実行使用メモリ | 15,392 KB |
| 最終ジャッジ日時 | 2024-07-16 04:13:14 |
| 合計ジャッジ時間 | 7,419 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | TLE * 1 -- * 29 |
ソースコード
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <cmath>
#include <string>
//#include <array>
#include <list>
#include <queue>
#include <vector>
#include <complex>
#include <set>
#include <map>
/////////
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define PII pair<int,int>
/////////
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
/////////
using namespace::std;
/////////
vector< pair<ULL,ULL> > v;
int main(void){
std::cin.tie(0);
std::ios::sync_with_stdio(false);
std::cout << std::fixed;//
cout << setprecision(16);//
int N;
cin>>N;
int D[100];
bool W[100];
int ww;
rep(i,N)cin>>D[i];
rep(i,N){
cin>>ww;
W[i] = ww?true:false;
}
int tr,tl;
ULL L,R;
pair<ULL,ULL> Start,Goal;
v.reserve(N);
rep(i,N){
L = 0;
R = 0;
tr = (i+D[i])%N;
tl = (N+i+(-D[i])%N)%N;
if(tr>64){
L |= (ULL)1<<(tr%64);
}else{
R |= (ULL)1<<(tr%64);
}
if(tl>64){
L |= (ULL)1<<(tl%64);
}else{
R |= (ULL)1<<(tl%64);
}
v.push_back( pair<ULL,ULL>(L,R) );
}
for(int i=0; i<64 && i<N;++i){
Start.second |= (ULL)W[i]<<i;
Goal.second |= (ULL)1<<i;
}
for(int i=0; i<64 && (i+64)<N;++i){
Start.first |= (ULL)W[i+64]<<i;
Goal.first |= (ULL)1<<i;
}
set<pair<ULL,ULL>> AllSet[2],prevSet[2],nextSet[2];
AllSet[0].insert(Start);
if( binary_search(AllSet[0].begin(),AllSet[0].end(),Goal) ){
P("Yes");
return 0;
}
AllSet[1].insert(Goal);
prevSet[0].insert(Start);
prevSet[1].insert(Goal);
set<pair<ULL,ULL>>::iterator itr;
vector<pair<ULL,ULL>>::iterator itrX;
pair<ULL,ULL> temp;
int endCount = 0;
for(;;){
endCount = 0;
rep(turn,2){
for( itr = prevSet[turn].begin();itr != prevSet[turn].end(); ++itr ){
for(itrX = v.begin(); itrX != v.end(); ++itrX){
temp = pair<ULL,ULL>(itr->second ^ itrX->second,itr->first ^ itrX->first);
if( binary_search( AllSet[(turn+1)%2].begin(),AllSet[(turn+1)%2].end(),temp) ){
P("Yes");
return 0;
}
if( AllSet[turn].insert(temp).second ){
nextSet[turn].insert(temp);
}
}
}
prevSet[turn] = nextSet[turn];
nextSet[turn].clear();
if(prevSet[turn].size() == 0){
++endCount;
}
}
if( endCount == 2){
break;
}
}
P("No");
return 0;
}
IL_msta