How to install plugins on Arena

You will need the next tutorial to create an account and understand how TopCoder’s SRM work.

http://topblogcoder.wordpress.com/tutorials/how-to-begin-in-topcoder/

Actually most of TopCoders use a combination of plugins to work easily with Arena. The list of plugins is in the next link:

http://community.topcoder.com/tc?module=Static&d1=applet&d2=plugins

Actually I am using the next configuration in my SRMs:

  • CodeProcessor.jar
  • FileEdit.jar
  • TZTester.jar

Sigue leyendo

TopCoder – Single Round March 537

Here is my Div1-250 solution.

#define FOR(i,a,b)  for(int i=(a),_##i=(b);i<_##i;++i)
#define F(i,a)      FOR(i,0,a)
#define ALL(x)      x.begin(),x.end()
#define PB          push_back
#define MP          make_pair
#define S           size()
typedef long long   LL;

bool oki(int A, int x, int y){
   F(i, 201){
      if(A - (x*i) >= 0)
      if((A - (x*i)) % y == 0) return true;
      if(A - (y*i) >= 0)
      if((A - (y*i)) % x == 0) return true;
   }
   return false;
}

class KingXNewCurrency {
public:
   int howMany(int A, int B, int X) {
      int t = 0;
      FOR(y, 1, 206)
         if(oki(A, X, y) && oki(B, X, y))
            t++;
      if(t == 205) return -1;
      return t;
   }
}

TopCoder SRM 498 – DIV 1 Level 2

The solution of the problem is as follows.

#define MP     make_pair
typedef long long   LL;

int xx[]={-1,-1,0,1,1,1,0,-1};
int yy[]={0,-1,-1,-1,0,1,1,1};

vector<int> res;

void bfs(vector<vector<int> >&v, int n, int m, int x, int y){
    queue<pair<int, pair<int,int> > > q;
    q.push(MP(1, MP(x, y)));
    while(!q.empty()){
        int val = q.front().first;
        x = q.front().second.first;
        y = q.front().second.second;
        q.pop();
        if(x < 0 || y < 0) continue;
        if(x >= n || y >= m) continue;
        if(v[x][y]) continue;
        v[x][y] = val;
        res[val]++;
        for(int k=0; k<8;k++)
            q.push(MP(val+1, MP(x+xx[k], y+yy[k])));
    }
}

void bfs1(vector<vector<int> >&v, int n, int m, int x, int y){
    vector<vector<pair<int,pair<int,int> > > > mark(202);
    vector<vector<bool> > vis(n, vector<bool>(m, 0));
    queue<pair<int, pair<int,int> > > q;
    q.push(MP(1, MP(x, y)));
    while(!q.empty()){
        int val = q.front().first;
        x = q.front().second.first;
        y = q.front().second.second;
        q.pop();
        if(x < 0 || y < 0) continue;
        if(x >= n || y >= m) continue;
        if(vis[x][y]) continue;
        vis[x][y] = true;
        mark[val].PB(MP(v[x][y], MP(x,y)));
        for(int k=0; k<8 ;k++)
            q.push(MP(val+1, MP(x+xx[k], y+yy[k])));
    }
    int it = 1;
    for(int i=1; i<202 ;i++){
        map<int,int> mapa;
        for(int j=0; j<mark[i].size();j++){
            int val = mark[i][j].first;
            x = mark[i][j].second.first;
            y = mark[i][j].second.second;
            if(mapa.find(val) == mapa.end()) mapa[val] = it++;
            v[x][y] = mapa[val];
        }
    }
}

LL fact(int x){
    LL r=1;
    for(LL i=2; i<=LL(x) ;i++)
        r = (r*i)%1000000009LL;
    return r;
}

class FoxStones{
    public:
    int getCount(int n, int m, vector<int> sx, vector<int> sy) {
        vector<vector<int> > v(n, vector<int>(m, 0));
        res = vector<int> (201, 0);
        bfs(v, n, m, sx[0]-1, sy[0]-1);
        for(int i=1; i            bfs1(v, n, m, sx[i]-1, sy[i]-1);
        vector<int> sol(40002, 0);
        for(int i=0;i<n;i++)
            for(int j=0;j<n;j++)
                sol[v[i][j]]++;
        LL r = 1LL;
        for(int i=0;i<sol.size();i++)
            if(sol[i])
                r = (r*fact(sol[i]))%1000000009LL;
        return r;
    }
};

TopCoder SRM 498 – DIV 1 Level 1

This problem is more simple but the implementation should be carefully.

Solution O(n):
1) get the first ascending sequence
2) get the first descending sequence
3) get the number with no difference
4) get the second ascending sequence
5) get the second ascending sequence

class FoxSequence{
    public:
    string isValid(vector<int> seq) {
        int n = seq.S;
        if(n < 5) return "NO";
//1) get the first ascending sequence
        int dif = seq[1]-seq[0], it = 1;
        if(dif<=0) return "NO";
        while(it<n-3 && seq[it]-seq[it-1] == dif) it++;
//2) get the first descending sequence
        dif = seq[it]-seq[it-1];
        if(dif>=0) return "NO";
        while(it<n-2 && seq[it]-seq[it-1] == dif) it++;
//3) get the number with no difference
        while(it<n-2 && seq[it] == seq[it-1]) it++;
//4) get the second ascending sequence
        dif = seq[it]-seq[it-1];
        if(dif<=0) return "NO";
        while(it<n-1 && seq[it]-seq[it-1] == dif) it++;
//5) get the second ascending sequence
        dif = seq[it]-seq[it-1];
        if(dif>=0) return "NO";
        while(it<n && seq[it]-seq[it-1] == dif) it++;
        if(it != n) return "NO";
        return "YES";
    }
};

TopCoder Single Round Match 484 – Div 2

Here ‘s my solution to the problem NumberMagicEasy SRM 484.

int theNumber(string a) {
    int t = 1;
    if(a[0] == 'N') t += (1<<3);
    if(a[1] == 'N') t += (1<<2);
    if(a[2] == 'N') t += (1<<1);
    if(a[3] == 'N') t += 1;
    return t;
}

Another very good solution to the problem was as follows.

int theNumber(string a){ 
    int ret = 16; 
    if(a[0]=='Y')ret-=8; 
    if(a[1]=='Y')ret-=4; 
    if(a[2]=='Y')ret-=2; 
    if(a[3]=='Y')ret-=1; 
    return ret; 
}