Submission #717978

# Submission time Handle Problem Language Result Execution time Memory
717978 2023-04-03T04:08:00 Z vinnipuh01 Soccer (JOI17_soccer) C++17
35 / 100
60 ms 18944 KB
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define int long long
#define sqrt sqrtl

using namespace std;

const long long oo = 1000000000000000000;

long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos;


/*
    ViHHiPuh

   (( `'-""``""-'` ))
     )-__-_.._-__-(
   / --- (o _ o) --- \
   \ .-* ( .0. ) *-. /
   _'-. ,_ '=' _, .-'_
  / `;#'#'# - #'#'#;` \
 \_)) -----'#'----- ((_/
      # --------- #
  '# ------- ------ #'
  /..-'# ------- #'-.\
  _\...-\'# -- #'/-.../_
  ((____)- '#' -(____))


    cout << fixed << setprecision(6) << x;

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    freopen ( "sum.in", "r", stdin )
*/

int h, w, a, b, c, n, x[ 100001 ], y[ 100001 ];
vector <pair<int, int> > v[ 100001 ];
set <pair<int, int> > st;
int d[ 100001 ];

int calc( int i, int j ) {
	int ans = abs( x[ i ] - x[ j ] ) + abs( y[ i ] - y[ j ] );
	ans = ans * c;
	ans = min( ans, abs( x[ i ] - x[ j] ) * c + a * abs( y[ i ] - y[ j ] ) + b );
	ans = min( ans, abs( y[ i ] - y[ j ] ) * c + a * abs( x[ i ] - x[ j ] ) + b );
	return ans;
}

main () {
	cin >> h >> w >> a >> b >> c >> n;
	for ( int i = 1;  i<= n; i ++ ) {
		cin >> x[ i ] >> y[ i ];
	}  
	if ( n == 2 ) {
		cout << calc( 1, 2 );
		return 0;
	}
	for ( int i = 1; i <= n; i ++ ) {
		for ( int j = i + 1; j <= n; j ++ ) {
			v[ i ].push_back( { j, calc( i, j ) } );
			v[ j ].push_back( { i, calc( i, j ) } );
		}
		d[ i ] = oo;
	}
	d[ 1 ] = 0;
	st.insert( { d[ 1 ], 1 } );
	while ( st.size() ) {
		int u = st.begin()->second;
		st.erase( st.begin() );
		for ( auto to : v[ u ] ) {
			if ( d[ to.first ] > d[ u ] + to.second ) {
				st.erase( { d[ to.first ], to.first } );
				d[ to.first ] = d[ u ] + to.second;
				st.insert( { d[ to.first ], to.first } );
			}
		}
	}
//	for ( int i = 1; i <= n; i ++ )
//		cout << i << " - " << d[ i ] << "\n";
	cout << d[ n ];
}

Compilation message

soccer.cpp:60:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   60 | main () {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 3 ms 2772 KB Output is correct
3 Correct 3 ms 2796 KB Output is correct
4 Correct 2 ms 2900 KB Output is correct
5 Correct 3 ms 3432 KB Output is correct
6 Correct 60 ms 18936 KB Output is correct
7 Correct 25 ms 18924 KB Output is correct
8 Correct 30 ms 18928 KB Output is correct
9 Correct 29 ms 18940 KB Output is correct
10 Correct 25 ms 18900 KB Output is correct
11 Correct 26 ms 18916 KB Output is correct
12 Correct 3 ms 3284 KB Output is correct
13 Correct 49 ms 18944 KB Output is correct
14 Correct 26 ms 18900 KB Output is correct
15 Correct 31 ms 18908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 3 ms 2772 KB Output is correct
8 Correct 3 ms 2796 KB Output is correct
9 Correct 2 ms 2900 KB Output is correct
10 Correct 3 ms 3432 KB Output is correct
11 Correct 60 ms 18936 KB Output is correct
12 Correct 25 ms 18924 KB Output is correct
13 Correct 30 ms 18928 KB Output is correct
14 Correct 29 ms 18940 KB Output is correct
15 Correct 25 ms 18900 KB Output is correct
16 Correct 26 ms 18916 KB Output is correct
17 Correct 3 ms 3284 KB Output is correct
18 Correct 49 ms 18944 KB Output is correct
19 Correct 26 ms 18900 KB Output is correct
20 Correct 31 ms 18908 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Incorrect 3 ms 2900 KB Output isn't correct
23 Halted 0 ms 0 KB -