Submission #68563

# Submission time Handle Problem Language Result Execution time Memory
68563 2018-08-17T11:01:11 Z BThero Soccer (JOI17_soccer) C++17
0 / 100
2 ms 520 KB
// Why I am so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int MAXN = (int)1e3 + 5;
const ll INF = (ll)1e16;

int px[MAXN], py[MAXN];

bool u[MAXN];

int a, b, c;

int n, m, k;

ll d[MAXN];

ll ans;

ll cost(int ax, int ay, int bx, int by) {
	int dx = abs(ax - bx), dy = abs(ay - by);
	ll ret = (dx + dy) * 1ll * c;
	ret = min(ret, dx * c + dy * 1ll * a + b);
	ret = min(ret, dy * c + dx * 1ll * a + b); 
	return ret;
}

void solve() {                   
	scanf("%d %d", &n, &m);
	scanf("%d %d %d", &a, &b, &c);
	scanf("%d", &k);

	for (int i = 1; i <= k; ++i) {
		scanf("%d %d", &px[i], &py[i]);
	}

	if (k == 2) {
		printf("%lld\n", cost(px[1], py[1], px[2], py[2]));
		return;
	}

    for (int i = 2; i <= k; ++i) {
    	d[i] = INF;
    }

    for (int i = 1; i <= k; ++i) {
    	int v = -1;

    	for (int j = 1; j <= k; ++j) {
    		if (u[j]) {
    			continue;
    		}

    		if (v == -1 || d[j] < d[v]) {
    			v = j;
    		}
    	}

    	if (d[v] == INF) {
    		break;
    	}

    	u[v] = 1;

    	for (int to = 1; to <= k; ++to) {
    		if (to == v) {
    			continue;
    		}

    		d[to] = min(d[to], d[v] + cost(px[v], py[v], px[to], py[to]));
    	}
    }    

   	printf("%lld\n", d[k]);
}

int main() {    
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Compilation message

soccer.cpp: In function 'void solve()':
soccer.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
soccer.cpp:41:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &a, &b, &c);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:42:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &k);
  ~~~~~^~~~~~~~~~
soccer.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &px[i], &py[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Incorrect 2 ms 440 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 520 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 360 KB Output is correct
3 Incorrect 2 ms 440 KB Output isn't correct
4 Halted 0 ms 0 KB -