Problem p00256 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int dy[] = {-1, 0, 1, 0}, dx[] = {0, 1, 0, -1};
// adjust problem by problem
const double EPS = 1e-8;
const double PI = acos(-1.0);
#ifdef __GNUC__
int popcount(int n) { return __builtin_popcount(n); }
int popcount(ll n) { return __builtin_popcountll(n); }
#endif
#ifndef __GNUC__
template <class T> int popcount(T n) {
  int cnt = 0;
  while (n) {
    if (n % 2)
      cnt++;
    n /= 2;
  }
  return cnt;
}
#endif
template <class T> int SIZE(T a) { return a.size(); }
template <class T> string IntToString(T num) {
  string res;
  stringstream ss;
  ss << num;
  return ss.str();
}
template <class T> T StringToInt(string str) {
  T res = 0;
  for (int i = 0; i < SIZE(str); i++)
    res = (res * 10 + str[i] - '0');
  return res;
}
template <class T> T gcd(T a, T b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> void PrintSeq(T &a, int sz) {
  for (int i = 0; i < sz; i++) {
    cout << a[i];
    if (sz == i + 1)
      cout << endl;
    else
      cout << ' ';
  }
}
bool EQ(double a, double b) { return abs(a - b) < EPS; }
void fastStream() {
  cin.tie(0);
  std::ios_base::sync_with_stdio(0);
}
vector<string> split(string str, char del) {
  vector<string> res;
  for (int i = 0, s = 0; i < SIZE(str); i++) {
    if (str[i] == del) {
      if (i - s != 0)
        res.push_back(str.substr(s, i - s));
      s = i + 1;
    } else if (i == SIZE(str) - 1) {
      res.push_back(str.substr(s));
    }
  }
  return res;
}

ll sumd[10000011];

const int md[2][12] = {{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
                       {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};

bool isLeap(int y) { return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0); }

int main() {

  // テァツエツッテァツゥツ硬ay
  for (int y = 2013; y <= 10000010; y++) {
    if (isLeap(y))
      sumd[y] = sumd[y - 1] + 366;
    else
      sumd[y] = sumd[y - 1] + 365;
  }

  string str;
  while (getline(cin, str) && str != "#") {
    int dot = 0;
    for (int i = 0; i < (int)str.size(); i++) {
      if (str[i] == '.')
        dot++;
    }
    // s to m
    if (dot == 2) {
      vector<string> v = split(str, '.');
      vector<int> vv;
      for (int i = 0; i < (int)v.size(); i++)
        vv.push_back(StringToInt<int>(v[i]));
      ll pday = 0;
      // 2012,12.21テ」ツ?凝」ツつ嘉・ツ按敕」ツつ?」ツ?ヲテ、ツスツ陛ヲツ猟・テァツオツ古ゥツ?偲」ツ?療」ツ?淌」ツ?凝」ツつ津ィツィツ暗ァツョツ療」ツ??
      // テ」ツ?敕」ツ?ョテ・ツ?、テ」ツつ津ァツ板ィテ」ツ??」ツ?ヲテ」ツδ榲」ツδ、テヲツ堋ヲテ」ツ?ォテ・ツ、ツ嘉ヲツ渉?
      if (vv[0] == 2012 && vv[1] == 12)
        pday += vv[2] - 21;
      else {
        pday += 10;
        pday += sumd[vv[0] - 1];
        int c = isLeap(vv[0]);
        for (int i = 0; i < 12; i++) {
          if (vv[1] == i + 1) {
            pday += vv[2];
            break;
          } else {
            pday += md[c][i];
          }
        }
      }
      pday %= (ll)13 * 20 * 20 * 18 * 20;
      // cout<<pday<<endl;
      // pdayテ」ツつ津・ツ、ツ嘉ヲツ渉?
      vector<int> res;
      res.push_back(pday / (20 * 18 * 20 * 20));
      pday %= (20 * 18 * 20 * 20);
      res.push_back(pday / (20 * 18 * 20));
      pday %= 20 * 18 * 20;
      res.push_back(pday / (20 * 18));
      pday %= 20 * 18;
      res.push_back(pday / 20);
      pday %= 20;
      res.push_back(pday);
      for (int i = 0; i < (int)res.size(); i++) {
        cout << res[i];
        if (i == (int)res.size() - 1)
          cout << endl;
        else
          cout << ".";
      }
    }
    // m to s
    else {
      vector<string> v = split(str, '.');
      vector<int> vv;
      for (int i = 0; i < (int)v.size(); i++)
        vv.push_back(StringToInt<int>(v[i]));
      ll sum = 0;
      sum = sum + vv[0];
      sum = sum * 20 + vv[1];
      sum = sum * 20 + vv[2];
      sum = sum * 18 + vv[3];
      sum = sum * 20 + vv[4];
      // 2012,12,21テ」ツ?凝」ツつ嘉」ツ?ョテァツオツ古ゥツ?仕ayテ」ツつ痴umテ」ツ?ィテ」ツ?凖」ツつ?
      if (sum <= 10)
        cout << 2012 << "." << 12 << "." << 21 + sum << endl;
      else {
        sum -= 10;
        // テ」ツ?禿」ツ?禿」ツ?凝」ツつ嘉ァツエツッテァツゥツ酵earテ」ツつ津、ツスツソテ」ツ?」テ」ツ?ヲテ、ツコツ古・ツ按?ヲツ篠「テァツエツ「テ」ツ?ァテ」ツ??、ツスツ陛・ツケツエテ」ツ?セテ」ツ?ァテゥツ?イテ」ツつ?」ツつ凝」ツ?凝ィツェツソテ」ツ?ケテ」ツつ?
        int ub = 10000010;
        int lb = 2012;
        while (ub - lb > 1) {
          int mid = (ub + lb) / 2;
          if (sumd[mid] >= sum)
            ub = mid;
          else
            lb = mid;
        }
        // ubテ・ツケツエテ」ツ?古」ツ??ィツカツ?」ツ?暗」ツつ凝ヲツ慊?・ツ按敕」ツ?ョテ・ツケツエテ」ツ?ェテ」ツ?ョテ」ツ?ァ
        // ub-1テ・ツケツエテ」ツ?セテ」ツ?ァテ・ツケツエテ」ツつ津ゥツ?イテ」ツつ?」ツ?ヲテ」ツ?甘」ツ??
        sum -= sumd[ub - 1];
        int resy = ub;
        int c = isLeap(resy);
        int resm, resd;
        for (int i = 0; i < 12; i++) {
          if (sum <= md[c][i]) {
            resm = i + 1;
            resd = sum;
            break;
          } else
            sum -= md[c][i];
        }
        cout << resy << "." << resm << "." << resd << endl;
      }
    }
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int dy[] = {-1, 0, 1, 0}, dx[] = {0, 1, 0, -1};
// adjust problem by problem
const double EPS = 1e-8;
const double PI = acos(-1.0);
#ifdef __GNUC__
int popcount(int n) { return __builtin_popcount(n); }
int popcount(ll n) { return __builtin_popcountll(n); }
#endif
#ifndef __GNUC__
template <class T> int popcount(T n) {
  int cnt = 0;
  while (n) {
    if (n % 2)
      cnt++;
    n /= 2;
  }
  return cnt;
}
#endif
template <class T> int SIZE(T a) { return a.size(); }
template <class T> string IntToString(T num) {
  string res;
  stringstream ss;
  ss << num;
  return ss.str();
}
template <class T> T StringToInt(string str) {
  T res = 0;
  for (int i = 0; i < SIZE(str); i++)
    res = (res * 10 + str[i] - '0');
  return res;
}
template <class T> T gcd(T a, T b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> void PrintSeq(T &a, int sz) {
  for (int i = 0; i < sz; i++) {
    cout << a[i];
    if (sz == i + 1)
      cout << endl;
    else
      cout << ' ';
  }
}
bool EQ(double a, double b) { return abs(a - b) < EPS; }
void fastStream() {
  cin.tie(0);
  std::ios_base::sync_with_stdio(0);
}
vector<string> split(string str, char del) {
  vector<string> res;
  for (int i = 0, s = 0; i < SIZE(str); i++) {
    if (str[i] == del) {
      if (i - s != 0)
        res.push_back(str.substr(s, i - s));
      s = i + 1;
    } else if (i == SIZE(str) - 1) {
      res.push_back(str.substr(s));
    }
  }
  return res;
}

unsigned int sumd[10000011];

const int md[2][12] = {{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
                       {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};

bool isLeap(int y) { return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0); }

int main() {

  // テァツエツッテァツゥツ硬ay
  for (int y = 2013; y <= 10000010; y++) {
    if (isLeap(y))
      sumd[y] = sumd[y - 1] + 366;
    else
      sumd[y] = sumd[y - 1] + 365;
  }

  string str;
  while (getline(cin, str) && str != "#") {
    int dot = 0;
    for (int i = 0; i < (int)str.size(); i++) {
      if (str[i] == '.')
        dot++;
    }
    // s to m
    if (dot == 2) {
      vector<string> v = split(str, '.');
      vector<int> vv;
      for (int i = 0; i < (int)v.size(); i++)
        vv.push_back(StringToInt<int>(v[i]));
      ll pday = 0;
      // 2012,12.21テ」ツ?凝」ツつ嘉・ツ按敕」ツつ?」ツ?ヲテ、ツスツ陛ヲツ猟・テァツオツ古ゥツ?偲」ツ?療」ツ?淌」ツ?凝」ツつ津ィツィツ暗ァツョツ療」ツ??
      // テ」ツ?敕」ツ?ョテ・ツ?、テ」ツつ津ァツ板ィテ」ツ??」ツ?ヲテ」ツδ榲」ツδ、テヲツ堋ヲテ」ツ?ォテ・ツ、ツ嘉ヲツ渉?
      if (vv[0] == 2012 && vv[1] == 12)
        pday += vv[2] - 21;
      else {
        pday += 10;
        pday += sumd[vv[0] - 1];
        int c = isLeap(vv[0]);
        for (int i = 0; i < 12; i++) {
          if (vv[1] == i + 1) {
            pday += vv[2];
            break;
          } else {
            pday += md[c][i];
          }
        }
      }
      pday %= (ll)13 * 20 * 20 * 18 * 20;
      // cout<<pday<<endl;
      // pdayテ」ツつ津・ツ、ツ嘉ヲツ渉?
      vector<int> res;
      res.push_back(pday / (20 * 18 * 20 * 20));
      pday %= (20 * 18 * 20 * 20);
      res.push_back(pday / (20 * 18 * 20));
      pday %= 20 * 18 * 20;
      res.push_back(pday / (20 * 18));
      pday %= 20 * 18;
      res.push_back(pday / 20);
      pday %= 20;
      res.push_back(pday);
      for (int i = 0; i < (int)res.size(); i++) {
        cout << res[i];
        if (i == (int)res.size() - 1)
          cout << endl;
        else
          cout << ".";
      }
    }
    // m to s
    else {
      vector<string> v = split(str, '.');
      vector<int> vv;
      for (int i = 0; i < (int)v.size(); i++)
        vv.push_back(StringToInt<int>(v[i]));
      ll sum = 0;
      sum = sum + vv[0];
      sum = sum * 20 + vv[1];
      sum = sum * 20 + vv[2];
      sum = sum * 18 + vv[3];
      sum = sum * 20 + vv[4];
      // 2012,12,21テ」ツ?凝」ツつ嘉」ツ?ョテァツオツ古ゥツ?仕ayテ」ツつ痴umテ」ツ?ィテ」ツ?凖」ツつ?
      if (sum <= 10)
        cout << 2012 << "." << 12 << "." << 21 + sum << endl;
      else {
        sum -= 10;
        // テ」ツ?禿」ツ?禿」ツ?凝」ツつ嘉ァツエツッテァツゥツ酵earテ」ツつ津、ツスツソテ」ツ?」テ」ツ?ヲテ、ツコツ古・ツ按?ヲツ篠「テァツエツ「テ」ツ?ァテ」ツ??、ツスツ陛・ツケツエテ」ツ?セテ」ツ?ァテゥツ?イテ」ツつ?」ツつ凝」ツ?凝ィツェツソテ」ツ?ケテ」ツつ?
        int ub = 10000010;
        int lb = 2012;
        while (ub - lb > 1) {
          int mid = (ub + lb) / 2;
          if (sumd[mid] >= sum)
            ub = mid;
          else
            lb = mid;
        }
        // ubテ・ツケツエテ」ツ?古」ツ??ィツカツ?」ツ?暗」ツつ凝ヲツ慊?・ツ按敕」ツ?ョテ・ツケツエテ」ツ?ェテ」ツ?ョテ」ツ?ァ
        // ub-1テ・ツケツエテ」ツ?セテ」ツ?ァテ・ツケツエテ」ツつ津ゥツ?イテ」ツつ?」ツ?ヲテ」ツ?甘」ツ??
        sum -= sumd[ub - 1];
        int resy = ub;
        int c = isLeap(resy);
        int resm, resd;
        for (int i = 0; i < 12; i++) {
          if (sum <= md[c][i]) {
            resm = i + 1;
            resd = sum;
            break;
          } else
            sum -= md[c][i];
        }
        cout << resy << "." << resm << "." << resd << endl;
      }
    }
  }

  return 0;
}