結果
| 問題 |
No.1633 Sorting Integers (Multiple of 2^K)
|
| コンテスト | |
| ユーザー |
chocorusk
|
| 提出日時 | 2021-07-30 22:52:04 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,112 bytes |
| コンパイル時間 | 3,747 ms |
| コンパイル使用メモリ | 187,660 KB |
| 最終ジャッジ日時 | 2025-01-23 12:34:37 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 TLE * 10 |
ソースコード
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
int n; ll k;
int c[10];
int n1,n2;
const ll mask=(1ll<<44)-1;
map<ll, vector<ll>> mp;
//map<pair<int, ll>, int> mp;
int ans;
void dfs(ll v, ll r, int t){
if(t==n1){
mp[v].push_back(r);
return;
}
ll r1=(r*10+1)&mask;
for(int i=1; i<=9; i++){
ll d=((v>>((i-1)<<2))&15);
if(c[i]>d){
v+=(1ll<<((i-1)<<2));
dfs(v, r1, t+1);
v-=(1ll<<((i-1)<<2));
}
r1++;
if(r1>=k) r1-=k;
}
}
using lll=__int128_t;
ll q;
ll c0;
void dfs2(ll v, ll r, int t){
if(t==n2){
ll x=(k-((lll)q*r&mask));
if(x>=k) x-=k;
ll w=c0-v;
auto itr=mp.find(w);
if(itr!=mp.end()){
for(auto y:itr->second){
ans=max(ans, __builtin_ffsll(x^y));
}
}
return;
}
ll r1=(r*10+1)&mask;
for(int i=1; i<=9; i++){
ll d=((v>>((i-1)<<2))&15);
if(c[i]>d){
v+=(1ll<<((i-1)<<2));
dfs2(v, r1, t+1);
v-=(1ll<<((i-1)<<2));
}
r1++;
if(r1>=k) r1-=k;
}
}
int main()
{
cin>>n;
k=(1ll<<44);
for(int i=1; i<=9; i++){
cin>>c[i];
c0^=((ll)c[i]<<((i-1)*4));
}
n1=min(8, n);
dfs(0, 0, 0);
if(n1==n){
for(auto x:mp[c0]){
ans=max(ans, __builtin_ffsll(x));
}
cout<<ans-1<<endl;
return 0;
}
n2=n-n1;
q=1;
for(int i=0; i<n1; i++) q=q*10%k;
dfs2(0, 0, 0);
cout<<ans-1<<endl;
return 0;
}
chocorusk