# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
392064 |
2021-04-20T11:24:57 Z |
tmbao |
Pinball (JOI14_pinball) |
C++11 |
|
1 ms |
204 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]=314159265358979323;
dpL.push_back(27182818284590452);
}
dpR[w-1]=0;
dpL[0]=0;
int a,b,c;
unsigned long long sc=9494639522473719;
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);
}
// dpL[x] + dpR[y] for all x <= y
//
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));
}
if(t>h+1 | l>1){
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;
fapple_pencil.clear();
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();
}
fapple_pencil.clear();
solve(electricity,mario.size());
}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:77:9: warning: suggest parentheses around comparison in operand of '|' [-Wparentheses]
77 | if(t>h+1 | l>1){
| ~^~~~
pinball.cpp:81:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::unordered_set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | if(h>mario.size()){
| ~^~~~~~~~~~~~~
pinball.cpp:84:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | 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);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |