QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#456618 | #7677. Easy Diameter Problem | Crying | WA | 1803ms | 242200kb | C++14 | 3.1kb | 2024-06-28 09:30:43 | 2024-06-28 09:30:44 |
Judging History
answer
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; typedef array<int,3> tr;
const int MAXN = 1e5+10,MAXM = 55,M = 50,N = 99999,INF = 1e9,MAXL = 1.7e5+10,L = 1.7e5;
template<typename T>void tomin(T& x,T y){x = min(x,y);}
template<typename T>void tomax(T& x,T y){x = max(x,y);}
//
int f[MAXM][MAXN],g[MAXM][MAXN],mf[10][MAXL],mg[10][MAXL];
vector<tr> vf[MAXM],vg[MAXM];
void fac(int n,int* d){
for(int i=4;i>=0;i--)d[i] = n%10,n /= 10;
}
int a[10];
namespace T{
int T,L,R,ans;
void solve(){
cin>>T;
while(T--){
cin>>L>>R; ans = INF;
if(L==R){
cout<<"0\n";
continue;
}
for(int x=L;x<=R;x++){
fac(x,a); int cnt = 0; for(int i=0;i<5;i++)cnt += (a[i]>0); cnt++;
for(int y=cnt;y<=M;y++){
if(f[y-cnt][x] >= R && g[y-cnt][x] <= L){
tomin(ans,y); break;
}
}
}
cout<<ans<<"\n";
}
}
}
vector<int> t[MAXN][6];
void calc(int x){
for(int i=1;i<=N;i++){
vf[x].push_back({-f[x][i],g[x][i],i});
vg[x].push_back({g[x][i],f[x][i],i});
}
sort(vf[x].begin(),vf[x].end()); sort(vg[x].begin(),vg[x].end());
}
int main(){
//freopen("capella.in","r",stdin);
//freopen("capella.out","w",stdout);
for(int i=1;i<=N;i++){
fac(i,a);
for(int S=0;S<32;S++){ //选择S中的位置替换成?
int y = __builtin_popcount(S),res = 0;
for(int j=0;j<=4;j++){
if(S>>j&1)res = res * 11 + 10;
else res = res * 11 + a[j];
}
t[i][y].push_back(res);
}
}
for(int i=1;i<=N;i++)f[0][i] = i+1,g[0][i] = i-1;
calc(0);
for(int x=1;x<=M;x++){
for(int i=1;i<=6;i++)for(int j=0;j<=L;j++)mf[i][j] = -INF,mg[i][j] = INF;
for(int i=1;i<=N;i++)f[x][i] = i+1,g[x][i] = i-1;
{ //calc f
int cur[7] = {};
for(int i=1;i<=N;i++){
for(int y=1;y<=6 && y<=x;y++){
while(cur[y] < N && vg[x-y][cur[y]][0] <= i+1){
tr tmp = vg[x-y][cur[y]++];
int pos = tmp[2],val = tmp[1];
for(auto z : t[pos][y-1])tomax(mf[y][z],val);
}
for(auto z : t[i][y-1])tomax(f[x][i],mf[y][z]);
}
}
}
{ //calc g
int cur[7] = {};
for(int i=N;i>=1;i--){
for(int y=1;y<=6 && y<=x;y++){
while(cur[y] < N && -vf[x-y][cur[y]][0] >= i-1){
tr tmp = vf[x-y][cur[y]++];
int pos = tmp[2],val = tmp[1];
for(auto z : t[pos][y-1])tomin(mg[y][z],val);
}
for(auto z : t[i][y-1])tomin(g[x][i],mg[y][z]);
}
}
}
calc(x);
}
T::solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1803ms
memory: 242200kb
input:
3 1 2 3 2
output:
2 1000000000 1000000000
result:
wrong answer 1st numbers differ - expected: '4', found: '2'