CSES - Siperia opettaa 3.0 - Results
Submission details
Task:Robots
Sender:Laakeri
Submission time:2016-07-28 21:01:48 +0300
Language:C++
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'void func()':
input/code.cpp:76:6: error: reference to 'next' is ambiguous
   if(next[v][dv] != -1){
      ^
input/code.cpp:47:5: note: candidates are: int next [100010][4]
 int next[100010][4];
     ^
In file included from /usr/include/c++/4.8/bits/stl_algobase.h:66:0,
                 from /usr/include/c++/4.8/bits/char_traits.h:39,
                 from /usr/include/c++/4.8/ios:40,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from input/code.cpp:13:
/usr/include/c++/4.8/bits/stl_iterator_base_funcs.h:184:5: note:                 template<class _ForwardIterator> _ForwardIterator std::next(_ForwardIterator, typename std::iterator_traits<_Iter>::difference_type)
     next(_ForwardIterator __x, typename
     ^
input/code.cpp:77:12: error: reference to 'next' is ambiguous
    int u = next[v][dv];
            ^
input/code.cpp:47:5: note: candidates are: int next [100010][4]...

Code

#include <string.h>
#if ( _WIN32 || __WIN32__ || _WIN64 || __WIN64__ )
#define INT64 "%I64d"
#else
#define INT64 "%lld"
#endif

#if ( _WIN32 || __WIN32__ || _WIN64 || __WIN64__ )
#define UNS64 "%I64u"
#else
#define UNS64 "%llu"
#endif
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define snuke(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

typedef long long ll;
#define INF (1ll<<60)

string ds = "UDLR";
int dx[] = {0,0,-1,1}, dy[] = {1,-1,0,0};

int N;
int x[100010],y[100010],d[100010];

map <int, vector <pair <int, int> > > mx,my;
int next[100010][4];

ll dist[100010][4];
bool used[100010][4];
priority_queue <pair <ll, pair <int, int> > > q;

void add(int v, int dv, ll d){
	if(d < dist[v][dv]){
		dist[v][dv] = d;
		q.push(make_pair(-d, make_pair(v, dv)));
	}
}

void func(void){
	int i,j;
	
	REP(i,N) REP(j,4) dist[i][j] = INF;
	dist[0][d[0]] = 0;
	q.push(make_pair(0ll, make_pair(0, d[0])));
	
	while(!q.empty()){
		ll dis = -q.top().first;
		int v = q.top().second.first, dv = q.top().second.second;
		q.pop();
		
		if(used[v][dv]) continue;
		used[v][dv] = true;
		
		add(v, d[v], dis);
		if(next[v][dv] != -1){
			int u = next[v][dv];
			add(u, dv, dis + abs(x[u] - x[v]) + abs(y[u] - y[v]));
		}
	}
}

int main(void){
	int i,j;
	ll T;
	
	cin >> N >> T;
	REP(i,N){
		char ch;
		scanf(" %d %d %c ", &x[i], &y[i], &ch);
		REP(j,4) if(ds[j] == ch) d[i] = j;
	}
	
	REP(i,N) REP(j,4) next[i][j] = -1;
	
	REP(i,N){
		mx[x[i]].push_back(make_pair(y[i], i));
		my[y[i]].push_back(make_pair(x[i], i));
	}
	
	snuke(mx,itr){
		vector <pair <int, int> > v = (itr->second);
		sort(v.begin(),v.end());
		int sz = v.size();
		REP(i,sz-1){
			int p = v[i].second;
			int q = v[i+1].second;
			next[p][0] = q;
			next[q][1] = p;
		}
	}
	
	snuke(my,itr){
		vector <pair <int, int> > v = (itr->second);
		sort(v.begin(),v.end());
		int sz = v.size();
		REP(i,sz-1){
			int p = v[i].second;
			int q = v[i+1].second;
			next[p][3] = q;
			next[q][2] = p;
		}
	}
	
	func();
	
	REP(i,N){
		ll t = 0;
		if(dist[i][d[i]] < T) t = T - dist[i][d[i]];
		printf(INT64 " " INT64 "\n", x[i] + dx[d[i]] * t, y[i] + dy[d[i]] * t);
	}
	
	return 0;
}