QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#391525#3791. Interesting Calculatorucup-team1251100 ✓339ms15184kbC++202.1kb2024-04-16 17:00:332024-04-16 17:00:34

Judging History

你现在查看的是最新测评结果

  • [2024-04-16 17:00:34]
  • 评测
  • 测评结果:100
  • 用时:339ms
  • 内存:15184kb
  • [2024-04-16 17:00:33]
  • 提交

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