Submission #58981

#TimeUsernameProblemLanguageResultExecution timeMemory
58981andy627물통 (KOI17_bucket)C++17
34 / 100
6 ms796 KiB
#include <stdio.h> #include <queue> #include <map> #include <algorithm> #define pii pair<int,int> #define ff first #define ss second using namespace std; map<pii,int> mp; queue<pii> q; int main(){ int a,b,c,d; scanf("%d %d %d %d",&a,&b,&c,&d); if(a!=c && !c && b!=d && !d){printf("-1");return 0;} mp[{0,0}]=0; q.push({0,0}); while(!q.empty()){ int pa=q.front().ff; int pb=q.front().ss; q.pop(); int pd=mp[{pa,pb}]; if(pa==c && pb==d){printf("%d",pd);return 0;} if(a && mp.find({0,pb})==mp.end()) mp[{0,pb}]=pd+1,q.push({0,pb}); if(b && mp.find({pa,0})==mp.end()) mp[{pa,0}]=pd+1,q.push({pa,0}); if(pa!=a){ if(mp.find({a,pb})==mp.end()) mp[{a,pb}]=pd+1,q.push({a,pb}); if(pa+pb>a && mp.find({a,pa+pb-a})==mp.end()) mp[{a,pa+pb-a}]=pd+1,q.push({a,pa+pb-a}); if(pa+pb<=a && mp.find({pa+pb,0})==mp.end()) mp[{pa+pb,0}]=pd+1,q.push({pa+pb,0}); } if(pb!=b){ if(mp.find({pa,b})==mp.end()) mp[{pa,b}]=pd+1,q.push({pa,b}); if(pa+pb>b && mp.find({pa+pb-b,b})==mp.end()) mp[{pa+pb-b,b}]=pd+1,q.push({pa+pb-b,b}); if(pa+pb<=b && mp.find({0,pa+pb})==mp.end()) mp[{0,pa+pb}]=pd+1,q.push({0,pa+pb}); } } printf("-1"); return 0; }

Compilation message (stderr)

bucket.cpp: In function 'int main()':
bucket.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d %d",&a,&b,&c,&d);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...