# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
392078 |
2021-04-20T12:24:39 Z |
tmbao |
Pinball (JOI14_pinball) |
C++14 |
|
0 ms |
0 KB |
#include<bits/stdc++.h>
using namespace std;
void solve(vector<tuple<int,int,int,int>> t,int w){
vector<unsigned long long> dpL;
vector<unsigned long long> dpR;
dpR.resize(w);
for(int i=0;i<w;i++){
dpR[i]=14159265358979323;
dpL.push_back(14159265358979323);
}
dpR[w-1]=0;
dpL[0]=0;
int a,b,c;
unsigned long long sc=14159265358979323;
unsigned long long d,e,f;
tie(a,b,c,d)=t.back();
while(a>0 & b+1<w & t.size()>0){
t.pop_back();
tie(a,b,c,d)=t.back();
}
unsigned long long luigi;
while(!t.empty()){
tie(a,b,c,d)=t.back();
t.pop_back();
luigi=7105079227968925;
for(int i=b;i>=a;i--){
luigi=min(luigi,dpR[i]);
sc=min(sc,dpL[i]+luigi+d);
}
e=dpL[c];
f=dpR[c];
for(int i=a;i<=b;i++){
e=min(e,dpL[i]+d);
f=min(f,dpR[i]+d);
}
dpL[c]=e;
dpR[c]=f;
}
if(sc>1234567890101112){
printf("-1");
}else{
printf("%llu",sc);
}
}
int main(){
//freopen("yeet.txt","r",stdin);
int a,b,c,d,N,t;
int h=0;
int l=314159;
scanf("%d%d",&N,&t);
vector<int> fapple_pencil;
unordered_set<int> mario;
unordered_map<int,int> cyclamic_acid;
vector<tuple<int,int,int,int>> grid;
for(int i=0;i<N;i++){
scanf("%d%d%d%d",&a,&b,&c,&d);
a--;b--;c--;
if(!mario.count(a)){
fapple_pencil.push_back(a);
mario.insert(a);
}
if(!mario.count(b)){
fapple_pencil.push_back(b);
mario.insert(b);
}
if(!mario.count(c)){
fapple_pencil.push_back(c);
mario.insert(c);
}
grid.push_back({a,b,c,d});
h=max(max(h,a),max(b,c));
l=min(min(l,a),min(b,c));cou
}
if(t>h+1 || l>0){
printf("-1");
return 0;
}
if(h>mario.size()){
sort(fapple_pencil.begin(),fapple_pencil.end());
vector<tuple<int,int,int,int>> electricity;
for(int i=1;i<fapple_pencil.size();i++){
cyclamic_acid[fapple_pencil[i]]=i;
}
cyclamic_acid[fapple_pencil[0]]=0;
while(!grid.empty()){
tie(a,b,c,d)=grid.back();
electricity.push_back({cyclamic_acid[a],cyclamic_acid[b],cyclamic_acid[c],d});
grid.pop_back();
}
solve(electricity,fapple_pencil.size());
fapple_pencil.clear();
}else{
fapple_pencil.clear();
reverse(grid.begin(),grid.end());
solve(grid,h+1);
}
return 0;
}
Compilation message
pinball.cpp: In function 'void solve(std::vector<std::tuple<int, int, int, int> >, int)':
pinball.cpp:17:12: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
17 | while(a>0 & b+1<w & t.size()>0){
| ~^~
pinball.cpp:17:33: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
17 | while(a>0 & b+1<w & t.size()>0){
| ~~~~~~~~^~
pinball.cpp: In function 'int main()':
pinball.cpp:75:34: error: 'cou' was not declared in this scope; did you mean 'cos'?
75 | l=min(min(l,a),min(b,c));cou
| ^~~
| cos
pinball.cpp:82:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::unordered_set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | if(h>mario.size()){
| ~^~~~~~~~~~~~~
pinball.cpp:85:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for(int i=1;i<fapple_pencil.size();i++){
| ~^~~~~~~~~~~~~~~~~~~~~
pinball.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
53 | scanf("%d%d",&N,&t);
| ~~~~~^~~~~~~~~~~~~~
pinball.cpp:59:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
59 | scanf("%d%d%d%d",&a,&b,&c,&d);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~