SRM412: StringsAndTabs

(問題概要)
2つのTAB譜の変換

(解法)
やるだけ。制限が色々めんどい。
最近なら250〜300で出ても驚かないレベルの内容。

#include <algorithm>
#include <cstdio>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <set>
#include <iostream>
#include <sstream>

using namespace std;

class StringsAndTabs {
public:
  vector <string> transformTab(vector <string> tab, vector <int> stringsA, vector <int> stringsB, int d);
};

int num(char c){
  if(isdigit(c)) return c - '0';
  return c - 'A' + 10;
}

char toNum(int n){
  if(n < 10) return '0' + n;
  return 'A' + n - 10;
}

vector <string> StringsAndTabs::transformTab(vector <string> tab, vector <int> stringsA, vector <int> stringsB, int d){
  const int w = tab[0].size();
  const int h = tab.size();
  const int hh = stringsB.size();
  vector<vector<int> > val(w);
  vector<string> ans(hh, string(w, '-'));
  vector<pair<int, int> > idx(hh);
  REP(i,hh) idx[i] = make_pair(stringsB[i], i);
  sort(idx.rbegin(), idx.rend());

  REP(i,h) REP(j,w){
    if(tab[i][j] != '-'){
      val[j].push_back(stringsA[i] + num(tab[i][j]) + d);
    }
  }


  REP(j,w) sort(val[j].rbegin(), val[j].rend());

  REP(i,w) REP(j,val[i].size()){
    const int v = val[i][j];
    bool assign = false;
    REP(kk,hh){
      const int k = idx[kk].second;
      if(stringsB[k] <= v && v <= stringsB[k] + 35){
	if(ans[k][i] == '-'){
	  ans[k][i] = toNum(v - stringsB[k]);
	  assign = true;
	  break;
	}else{

	}
      }
    }
    if(!assign){
      REP(k,hh){
	ans[k][i] = 'x';
      }
    }
  }

  return ans;
}