Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////Pre-Written Code/////////////////////////////
- #include <string.h>
- #include <stdio.h>
- #include <vector>
- #include <queue>
- #include <iostream>
- #include <algorithm>
- #include <stdlib.h>
- #include <math.h>
- #include <numeric>
- #include <map>
- #include <set>
- #include <sstream>
- #include <functional>
- using namespace std;
- #define all(c) c.begin(),c.end()
- #define rep_(i,n) for(i=n-1;i>=0;i--)
- #define rep(i,n) for(i=0;i<n;i++)
- #define forr(i,a,b) for(i=a;i<=b;i++)
- #define forr_(i,a,b) for(i=a;i>=b;i--)
- #define min(a,b) ( a>b? b : a )
- #define max(a,b) ( a>b? a : b )
- #define sz size()
- #define pb(a) push_back(a)
- #define mset(a,v) memset(a,v,sizeof(a))
- #define f first
- #define s second
- #define EPS 1e-11
- typedef vector<int> vi;
- typedef vector<vi> vvi;
- typedef map<int,int> mi;
- typedef vi::iterator it;
- typedef pair<int,int> pii;
- typedef vector<pii> vpii;
- typedef vector<string> vs;
- typedef pair<string,int> psi;
- typedef vector<psi> vpsi;
- typedef queue<int> qi;
- typedef queue<pii> qpii;
- typedef unsigned long long ubig;
- typedef long long big;
- typedef long double bigd;
- typedef stringstream ss;
- template<class T> string tos(T x){stringstream ss; ss<<x; return ss.str();}
- void rot(vvi v,vvi& tmp,int r1,int c1,int r2,int c2)
- {
- tmp.resize(c2-c1+1);
- int i,j;
- rep(i,tmp.sz)
- tmp[i].resize(r2-r1+1);
- forr(i,r1,r2)
- forr(j,c1,c2)
- tmp[j-c1][tmp[0].sz-(i-r1)-1]=v[i][j];
- }
- bool isPal(string s)
- {
- int i=0,j=s.sz-1;
- while(i<j)
- {
- if(islower(s[i]) && islower(s[j]) && s[i]!=s[j])
- return false;
- i++; j--;
- }
- return true;
- }
- ///////////////////////////////////Pre-Written Code/////////////////////////////
- int vis[10000],n,m;
- void solve(int box, int stp)
- {
- while(box!=0 && box!=n+1)
- {
- vis[box]=true;
- box+=stp;
- }
- }
- void imp()
- {
- cout<<"-1\n";
- exit(0);
- }
- int main()
- {
- mset(vis,0);
- int i,j;
- cin>>n>>m;
- string s,dir;
- char c;
- int box,stp;
- rep(i,m)
- {
- rep(j,3)cin>>dir;
- cin>>s>>box;
- if( dir=="left" )
- stp=1;
- else
- stp=-1;
- solve( box, stp );
- }
- int res=0;
- forr(i,1,n)if( !vis[i] )res++;
- if( !res ) imp();
- cout<<res<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement