/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 368.0 KiB
#2 Accepted 1ms 532.0 KiB
#3 Accepted 1ms 532.0 KiB
#4 Accepted 1ms 324.0 KiB
#5 Accepted 1ms 532.0 KiB
#6 Accepted 1ms 344.0 KiB
#7 Accepted 2ms 532.0 KiB
#8 Accepted 2ms 532.0 KiB
#9 Accepted 2ms 532.0 KiB
#10 Accepted 2ms 532.0 KiB
#11 Accepted 3ms 320.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
long long cnt=0;
bool ok=false;
int a,b,c;

int main()
{
    //ofstream file("output10.txt");
    long long a,b,c,X,n; cin>>X>>a>>b>>c>>n;
    int x=(n/a)+1, y=(n/b)+1, z=(n/c)+1;
    int cnt=1000000000;
    for(int i=0;i<=x;i++)
    {
        for(int j=0;j<=y;j++)
        {
            for(int k=0;k<=z;k++)
            {
                if(a*i+b*j+c*k+X == n) 
                {
                    ok=true;
                    cnt=min(cnt,i+j+k);
                }
            }
        }
    }

    if(ok) 
    {
        cout<<"YES"<<endl;
        //file<<"YES"<<endl;
        cout<<cnt<<endl;
    }
    else cout<<"NO"<<endl; //file<<"NO"<<endl;}
}

Information

Submit By
Type
Submission
Problem
P1028 Magical box and spell
Language
C++20 (G++ 13.2.0)
Submit At
2024-02-01 17:19:58
Judged At
2024-11-11 03:43:25
Judged By
Score
100
Total Time
3ms
Peak Memory
532.0 KiB