Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <map>
- using namespace std;
- int max_v = 1;
- int v = 1;
- struct booster{
- int x;
- int y;
- char c;
- booster *l;
- booster *r;
- booster *u;
- booster *d;
- int OFF;
- booster(int x = 0, int y = 0, char c = 0){
- this->x = x;
- this->y = y;
- this->c = c;
- this->l = NULL;
- this->r = NULL;
- this->u = NULL;
- this->d = NULL;
- OFF = -1;
- }
- };
- bool comp_x(const booster &a,const booster &b){
- return (a.x < b.x || (a.x == b.x && a.y < b.y));
- }
- bool comp_y(const booster &a,const booster &b){
- return (a.y < b.y || (a.y == b.y && a.x < b.x));
- }
- int main(){
- int n;
- scanf("%d", &n);
- vector<booster> tab;
- vector<bool> vis(n);
- // # CZYTANIE #
- for(int i=0; i<n; i++){
- int a, b;
- char c;
- scanf("%d %d %c", &a, &b, &c);
- tab[i] = booster(a, b, c);
- }
- int s = tab.size();
- sort(tab.begin(), tab.end(), comp_x); // ustawia UP/DOWN po przekątnej od LU do RD
- if(tab[0].x == tab[1].x && tab[0].y < tab[1].y)
- tab[0].d = &tab[1];
- if(tab[s-1].x == tab[s-2].x && tab[s-1].y > tab[s-2].y)
- tab[s-1].u = &tab[s-2];
- for(int i = 1 ; i<s-1; i++){
- if(tab[i-1].x == tab[i].x) tab[i].u = &tab[i-1];
- if(tab[i+1].x == tab[i].x) tab[i].d = &tab[i+1];
- }
- sort(tab.begin(), tab.end(), comp_y); // ustawia LEFT/RIGHT tak samo
- if(tab[0].y == tab[1].y && tab[0].x < tab[1].x)
- tab[0].r = &tab[1];
- if(tab[s-1].y == tab[s-2].y && tab[s-1].x > tab[s-2].x)
- tab[s-1].l = &tab[s-2];
- for(int i = 1 ; i<tab.size()-1; i++){
- if(tab[i-1].y == tab[i].y) tab[i].l = &tab[i-1];
- if(tab[i+1].y == tab[i].y) tab[i].r = &tab[i+1];
- }
- for(int i=0; i<s; i++){
- v = 1;
- booster *next= &tab[i];
- next->OFF = i; //oznacza włączony
- while(next != NULL){
- next->OFF = i;
- if (next->c == '^'){
- booster *tmp = next->u;
- while(tmp->OFF == i)
- tmp = tmp->u;
- next = tmp;
- }
- else if(next->c == '<' ){
- booster *tmp = next->l;
- while(tmp->OFF == i)
- tmp = tmp->l;
- next = tmp;
- }
- else if(next->c == 'v'){
- booster *tmp = next->d;
- while(tmp->OFF == i)
- tmp = tmp->d;
- next = tmp;
- }
- else if(next->c == '>'){
- booster *tmp = next->r;
- while(tmp->OFF == i)
- tmp = tmp->r;
- next = tmp;
- }
- v++;
- }
- if(v > max_v) max_v = v;
- }
- printf("%d", max_v);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement