QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#391525 | #3791. Interesting Calculator | ucup-team1251 | 100 ✓ | 339ms | 15184kb | C++20 | 2.1kb | 2024-04-16 17:00:33 | 2024-04-16 17:00:34 |
Judging History
answer
#include<bits/stdc++.h>
#define lowbit(x) (x&(-x))
#define rep(x,a,b) for(int x=a;x<=b;x++)
#define pre(x,a,b) for(int x=a;x>=b;x--)
#define endl "\n"
#define pb push_back
#define ll long long
#define int long long
#define pii pair<ll,ll>
#define psi pair<string, ll>
#define de cout<<1;
#define mem(a,x) memset(a,x,sizeof a)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
const int mod1=998244353;
const int mod2=1e9+7;
const int INF=1e18;
const int N = 1e6 + 60;
int number;
int n, m,idd;
int mp[5][15];
ll dis[N],book[N];
struct node
{
ll num;
ll w;
ll step;
bool operator< (const node &a)const
{
if(w==a.w)return a.step<step;
return a.w<w;
}
};
void bfs()
{
priority_queue<node>q;
q.push({n,0,0});
rep(i,0,m)book[i]=0,dis[i]=INF;
dis[n]=0;
while(!q.empty())
{
node A=q.top();
q.pop();
//cout << A.num<<endl;
if(book[A.num])continue;
book[A.num]=1;
if(A.num==m)
{
cout <<"Case "<<idd<<": "<<A.w <<' '<<A.step<<endl;
return;
}
rep(i,1,3)
{
rep(j,0,9)
{
int ww=A.w+mp[i][j];
int nnum;
if(i==1)
{
nnum=A.num*10+j;
}else if(i==2)
{
nnum=A.num+j;
}else
{
nnum=A.num*j;
}
//cout << nnum <<endl;
if(nnum<=m && !book[nnum] && dis[nnum]>ww)
{
//cout << nnum<<endl;
dis[nnum]=ww;
q.push({nnum,ww,A.step+1});
}
}
}
}
}
void solve()
{
while(cin >> n >> m)
{
idd++;
rep(i,1,3)
{
rep(j,0,9)
{
cin >> mp[i][j];
}
}
bfs();
}
}
signed main()
{
IOS;
int _;
//scanf("%d", &_);
_ = 1;
while(_ -- )
{
number++;
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 339ms
memory: 15184kb
input:
12 256 100 100 100 1 100 100 100 100 100 100 6 5 4 3 2 1 2 3 4 5 100 100 10 100 100 100 100 100 100 100 12 256 100 100 100 1 100 100 100 100 100 100 100 100 100 100 100 1 100 100 100 100 100 100 10 100 100 100 100 100 100 100 1 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 10...
output:
Case 1: 9 4 Case 2: 12 3 Case 3: 500000 5 Case 4: 49999 49999 Case 5: 700000 7 Case 6: 68382 10 Case 7: 112558 11 Case 8: 130701 18 Case 9: 63820 10 Case 10: 225950 7 Case 11: 198287 11 Case 12: 123217 19 Case 13: 91914 10 Case 14: 137984 11 Case 15: 85481 22 Case 16: 180261 12 Case 17: 26654 9 Case...
result:
ok 30 lines