Cod sursa(job #3173886)

Utilizator Alexbora13Bora Ioan Alexandru Alexbora13 Data 23 noiembrie 2023 21:09:58
Problema Zota & Chidil Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.67 kb
#include <bits/stdc++.h>

using namespace  std;

ifstream fin("zc.in");
ofstream fout("zc.out");

vector <pair <int,int>> capc1;
vector <pair <int,int>> capc2;
int addx[14]={0,1,0,-1, 0,2,0,-2,0,1,-1, 1,-1};
int addy[14]={0,0,1, 0,-1,0,2, 0,-2,1,-1,-1, 1};

int n, m, x, y, dim, sol;
char c;

int main()
{
    ios::sync_with_stdio(false);
    fin.tie(NULL);
    fout.tie(NULL);
    fin >> n >> m;
    for(int i=1; i<=n; i++)
    {
        fin >> x >> y;
        for(int j=0; j<13; j++)
        {
            if(x+addx[j]!=0 || y+addy[j]!=0)
            {
                capc1.push_back(make_pair(x+addx[j],y+addy[j]));
                capc2.push_back(make_pair(y+addy[j],x+addx[j]));
            }
        }
    }
    sort(capc1.begin(),capc1.end());
    sort(capc2.begin(),capc2.end());
    capc1.resize(unique(capc1.begin(),capc1.end())-capc1.begin());
    capc2.resize(unique(capc2.begin(),capc2.end())-capc2.begin());
    /*
    for(pair<int,int> a:capc1)
        cout << a.first << ' ' << a.second << '\n';
    */
    x = 0;
    y = 0;
    for(int i=1; i<=m; i++)
    {
        fin >> c >> dim;
        if(c=='N')
        {
            int st = lower_bound(capc1.begin(),capc1.end(),make_pair(x,y+1))-capc1.begin();
            int dr = upper_bound(capc1.begin(),capc1.end(),make_pair(x,y+dim))-capc1.begin();
            if (st<=dr && capc1[st].first==x && y<=capc1[st].second && capc1[st].second<=y+dim)
                sol+=(dr-st);
            y+=dim;
        }
        if(c=='S')
        {
            int st = lower_bound(capc1.begin(),capc1.end(),make_pair(x,y-dim))-capc1.begin();
            int dr = upper_bound(capc1.begin(),capc1.end(),make_pair(x,y-1))-capc1.begin();
            if (st<=dr && capc1[st].first==x && y-dim<=capc1[st].second && capc1[st].first<=y)
                sol+=(dr-st);
            y-=dim;
        }
        if(c=='E')
        {
            int st=lower_bound(capc2.begin(),capc2.end(),make_pair(y,x+1))-capc2.begin();
            int dr=upper_bound(capc2.begin (),capc2.end (),make_pair(y,x+dim))-capc2.begin();
            if (st<=dr && capc2[st].first==y && x<=capc2[st].second && capc2[st].second<=x+dim)
                sol+=(dr-st);
            x+=dim;
        }
        if(c=='V')
        {
            int st=lower_bound(capc2.begin(),capc2.end(),make_pair(y,x-dim))-capc2.begin ();
            int dr=upper_bound(capc2.begin(),capc2.end(),make_pair(y,x-1))-capc2.begin ();
            if(st<=dr && capc2[st].first==y && x-dim<capc2[st].second&& capc2[st].second<=x)
                sol+=(dr-st);
            x-=dim;
        }
    }
    fout << sol;
    fin.close();
    fout.close();
    return 0;
}