Submission #207546

# Submission time Handle Problem Language Result Execution time Memory
207546 2020-03-07T23:28:08 Z MetB OBELISK (NOI14_obelisk) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;

#define N 2000001

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll INF = 1e18, MOD = 1e9 + 7, MOD2 = 1e6 + 3;

int qdx[3] = {-1, 1, 0};

struct Pt {
	ll x, y;
} S, E;

int n, m;

vector <Pt> p[N];
vector <ll> d[N];

ll dist (Pt a, Pt b) {
	ll x = abs (a.x - b.x), y = abs (a.y - b.y);
    if(m == 1)
        return abs(x) + abs(y);
    int ans = (1<<30);
    for(int i = 0; i < 3; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            for(int g = 0; g < 2; g++)
            {
                for(int h = 0; h < 2; h++)
                {
                    int p = abs(x + dx[i] * (m + 1));
                    int q = abs(y + dx[j] * (m + 1));
                    int t1 = p / (m + 1) + (i < 2);
                    int t2 = q / (m + 1) + (j < 2);
                    int cur = t1 * 2 + t2 * 2 + g * 2 + h * 2;
                    p %= (m + 1);
                    q %= (m + 1);
                    if(p)
                    {
                        if(!t2)
                            cur += 2;
                        if(g)
                            cur += m + 1 - p;
                        else
                            cur += p;
                    }
                    if(q)
                    {
                        if(!t1)
                            cur += 2;
                        if(h)
                            cur += m + 1 - q;
                        else
                            cur += q;
                    }
                    ans = min(ans, cur);
                }
            }
        }
    }
    return ans;
} 

int main () {
	cin >> n >> m;

	cin >> S.x >> S.y >> E.x >> E.y;

	d[0].push_back (0);
	p[0].push_back (S);

	for (int i = 1; i < n; i++) {
		int h;
		cin >> h;
		d[i].resize (h);
		p[i].resize (h);

		for (int j = 0; j < h; j++) {
			cin >> p[i][j].x >> p[i][j].y;
			d[i][j] = INF;

			for (int k = 0; k < p[i-1].size (); k++) {
				d[i][j] = min (d[i][j], d[i-1][k] + dist (p[i-1][k], p[i][j]));
			}
		}
	}

	ll ans = INF;

	for (int i = 0; i < p[n-1].size (); i++) {
		ans = min (ans, d[n-1][i] + dist (p[n-1][i], E));
	}

	cout << (ans == INF ? -1 : ans);
}

Compilation message

obelisk.cpp: In function 'll dist(Pt, Pt)':
obelisk.cpp:39:37: error: 'dx' was not declared in this scope
                     int p = abs(x + dx[i] * (m + 1));
                                     ^~
obelisk.cpp:39:37: note: suggested alternative: 'x'
                     int p = abs(x + dx[i] * (m + 1));
                                     ^~
                                     x
obelisk.cpp: In function 'int main()':
obelisk.cpp:90:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int k = 0; k < p[i-1].size (); k++) {
                    ~~^~~~~~~~~~~~~~~~
obelisk.cpp:98:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < p[n-1].size (); i++) {
                  ~~^~~~~~~~~~~~~~~~