prithivMLmods/Coder-Stat huggingface dataset:
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  for (int i = 0; i <= s.length() - t.length(); ++i) {
    string y = s.substr(i, t.length());
    bool flag = false;
    for (int j = 0; j < t.length(); ++j) {
      if (y[j] != t[j] && y[j] != '?') {
        flag = true;
        break;
      }
    }
    if (flag)
      continue;
    if (1) {
      string ans = s.substr(0, i) + t + s.substr(i + t.length());
      for (auto x : ans) {
        if (x == '?')
          printf("%c", 'a');
        else
          printf("%c", x);
      }
      printf("\n");
      return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  for (int i = s.length() - t.length(); i >= 0; --i) {
    string y = s.substr(i, t.length());
    bool flag = false;
    for (int j = 0; j < t.length(); ++j) {
      if (y[j] != t[j] && y[j] != '?') {
        flag = true;
        break;
      }
    }
    if (flag)
      continue;
    if (1) {
      string ans = s.substr(0, i) + t + s.substr(i + t.length());
      for (auto x : ans) {
        if (x == '?')
          printf("%c", 'a');
        else
          printf("%c", x);
      }
      printf("\n");
      return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  string ss, t;
  cin >> ss >> t;
  int n = (int)ss.size() - (int)t.size() + 1, len = t.size();
  bool ok = false;
  int first;
  for (int i = n - 1; i > 0; i++) {
    string sss = ss.substr(i, len);
    for (int j = 0; j < len; j++) {
      if (sss[j] != t[j] && sss[j] != '?')
        break;
      if (j == len - 1)
        ok = true;
    }
    if (ok) {
      first = i;
      break;
    }
  }

  if (ok) {
    for (int i = 0; i < (int)ss.size(); i++) {
      if (i >= first && i <= first + len - 1)
        cout << t[i - first];
      else if (ss[i] == '?')
        cout << 'a';
      else
        cout << ss[i];
    }
  } else {
    cout << "UNRESTORABLE";
  }

  cout << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  string ss, t;
  cin >> ss >> t;
  int n = (int)ss.size() - (int)t.size() + 1, len = t.size();
  bool ok = false;
  int first;
  for (int i = n - 1; i >= 0; i--) {
    string sss = ss.substr(i, len);
    for (int j = 0; j < len; j++) {
      if (sss[j] != t[j] && sss[j] != '?')
        break;
      if (j == len - 1)
        ok = true;
    }
    if (ok) {
      first = i;
      break;
    }
  }

  if (ok) {
    for (int i = 0; i < (int)ss.size(); i++) {
      if (i >= first && i <= first + len - 1)
        cout << t[i - first];
      else if (ss[i] == '?')
        cout << 'a';
      else
        cout << ss[i];
    }
  } else {
    cout << "UNRESTORABLE";
  }

  cout << endl;

  return 0;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  int r = -1;
  for (int i = 0; i <= s.length() - t.length(); i++) {
    bool a = true;
    for (int j = 0; j < t.length(); j++) {
      if (s[i + j] == '?') {
        if (t[j] != 'a')
          a = false;
        continue;
      }
      if (s[i + j] != t[j])
        goto pnz;
    }
    r = i;
    if (a)
      break;
  pnz:;
  }
  if (r < 0) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  s.replace(r, t.length(), t);
  for (auto &c : s)
    if (c == '?')
      c = 'a';
  cout << s << endl;
  return 0;
}


Fixed submission:
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  int r = -1;
  for (int i = 0; i <= (int)s.length() - (int)t.length(); i++) {
    bool a = true;
    for (int j = 0; j < t.length(); j++) {
      if (s[i + j] == '?') {
        if (t[j] != 'a')
          a = false;
        continue;
      }
      if (s[i + j] != t[j])
        goto pnz;
    }
    r = i;
    if (a)
      break;
  pnz:;
  }
  if (r < 0) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  s.replace(r, t.length(), t);
  for (auto &c : s)
    if (c == '?')
      c = 'a';
  cout << s << endl;
  return 0;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  string s, t;
  cin >> s >> t;
  int range = t.size();
  int start = -1;
  bool allmatch = false;
  for (int i = 0; i <= s.size() - range; i++) {
    string pre = s.substr(i, range);
    bool match = true;
    if (pre == t) {
      allmatch = true;
      break;
    }
    for (int j = 0; j < range; j++) {
      if (s[i + j] != t[j] && s[i + j] != '?') {
        match = false;
      }
    }

    if (match) {
      start = i;
    }
  }

  if (allmatch) {
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '?') {
        s[i] = 'a';
      }
    }
    cout << s << endl;
  } else if (start == -1) {
    cout << "UNRESTORABLE" << endl;
  } else {
    for (int i = start; i < start + range; i++) {
      s[i] = t[i - start];
    }
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '?') {
        s[i] = 'a';
      }
    }
    cout << s << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main(void) {
  string s, t;
  cin >> s >> t;
  int range = t.size();
  int start = -1;
  bool allmatch = false;
  if (s.size() < t.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = 0; i <= s.size() - range; i++) {
    string pre = s.substr(i, range);
    bool match = true;
    if (pre == t) {
      allmatch = true;
      break;
    }
    for (int j = 0; j < range; j++) {
      if (s[i + j] != t[j] && s[i + j] != '?') {
        match = false;
      }
    }

    if (match) {
      start = i;
    }
  }

  if (allmatch) {
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '?') {
        s[i] = 'a';
      }
    }
    cout << s << endl;
  } else if (start == -1) {
    cout << "UNRESTORABLE" << endl;
  } else {
    for (int i = start; i < start + range; i++) {
      s[i] = t[i - start];
    }
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == '?') {
        s[i] = 'a';
      }
    }
    cout << s << endl;
  }
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {
  // input
  string S, T;
  cin >> S >> T;

  // S[i]から始めた文字列がTと一致するか調べる
  string str, ans = "~";
  bool findT;
  for (int i = 0; i <= S.size() - T.size(); i++) {
    // 文字列Tが存在するかチェック
    findT = true;
    for (int j = 0; j < T.size(); j++) {
      if (S[i + j] == T[j] || S[i + j] == '?')
        continue;
      else
        findT = false;
    }

    if (findT) {
      str = S.substr(0, i) + T + S.substr(i + T.size());
      for (int l = 0; l < str.size(); l++)
        if (str[l] == '?')
          str[l] = 'a';
      ans = min(ans, str);
    }
  }
  if (ans == "~")
    cout << "UNRESTORABLE" << endl;
  else
    cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {
  // input
  string S, T;
  cin >> S >> T;

  // S[i]から始めた文字列がTと一致するか調べる
  string str, ans = "~";
  bool findT;
  int Slen = S.length();
  int Tlen = T.length();
  for (int i = 0; i <= Slen - Tlen; i++) {
    // 文字列Tが存在するかチェック
    findT = true;
    for (int j = 0; j < T.size(); j++) {
      if (S[i + j] == T[j] || S[i + j] == '?')
        continue;
      else
        findT = false;
    }

    if (findT) {
      str = S.substr(0, i) + T + S.substr(i + T.size());
      for (int l = 0; l < str.size(); l++)
        if (str[l] == '?')
          str[l] = 'a';
      ans = min(ans, str);
    }
  }
  if (ans == "~")
    cout << "UNRESTORABLE" << endl;
  else
    cout << ans << endl;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a, b) for (int a = 0; a < b; a++)
#define Sort(a) sort(a.begin(), a.end())
int wari(int a, int b) {
  if (a % b == 0)
    return a / b;
  else
    return a / b + 1;
}
int keta(int a) {
  double b = a;
  b = log10(b);
  int c = b;
  return c + 1;
}
int souwa(int a) { return a * (a + 1) / 2; }
int lcm(int a, int b) {
  int d = a, e = b, f;
  if (a < b)
    swap(a, b);
  int c, m = 1;
  while (m) {
    c = a % b;
    if (c == 0) {
      f = b;
      m--;
    } else {
      a = b;
      b = c;
    }
  }
  return d * e / f;
}
int gcm(int a, int b) {
  int d = a, e = b, f;
  if (a < b)
    swap(a, b);
  int c, m = 1;
  while (m) {
    c = a % b;
    if (c == 0) {
      f = b;
      m--;
    } else {
      a = b;
      b = c;
    }
  }
  return f;
}
signed main() {
  string a, b, s;
  int c = 1;
  cin >> a >> b;
  vector<string> d;
  for (int i = 0; i < a.size() - b.size() + 1; i++) {
    s = a;
    for (int j = 0; j < b.size(); j++) {
      if (a[i + j] != '?' && a[i + j] != b[j])
        break;
      else {
        if (a[i + j] == '?')
          s[i + j] = b[j];
        else
          s[i + j] = a[i + j];
      }
      if (j == b.size() - 1) {
        for (int k = 0; k < s.size(); k++) {
          if (s[k] == '?')
            s[k] = 'a';
        }
        d.push_back(s);
      }
    }
  }
  Sort(d);
  cout << d.at(0) << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a, b) for (int a = 0; a < b; a++)
#define Sort(a) sort(a.begin(), a.end())
int wari(int a, int b) {
  if (a % b == 0)
    return a / b;
  else
    return a / b + 1;
}
int keta(int a) {
  double b = a;
  b = log10(b);
  int c = b;
  return c + 1;
}
int souwa(int a) { return a * (a + 1) / 2; }
int lcm(int a, int b) {
  int d = a, e = b, f;
  if (a < b)
    swap(a, b);
  int c, m = 1;
  while (m) {
    c = a % b;
    if (c == 0) {
      f = b;
      m--;
    } else {
      a = b;
      b = c;
    }
  }
  return d * e / f;
}
int gcm(int a, int b) {
  int d = a, e = b, f;
  if (a < b)
    swap(a, b);
  int c, m = 1;
  while (m) {
    c = a % b;
    if (c == 0) {
      f = b;
      m--;
    } else {
      a = b;
      b = c;
    }
  }
  return f;
}
signed main() {
  string a, b, s;
  int c = 1;
  cin >> a >> b;
  vector<string> d;
  for (int i = 0; i < a.size() - b.size() + 1; i++) {
    s = a;
    for (int j = 0; j < b.size(); j++) {
      if (a[i + j] != '?' && a[i + j] != b[j])
        break;
      else {
        if (a[i + j] == '?')
          s[i + j] = b[j];
        else
          s[i + j] = a[i + j];
      }
      if (j == b.size() - 1) {
        for (int k = 0; k < s.size(); k++) {
          if (s[k] == '?')
            s[k] = 'a';
        }
        d.push_back(s);
      }
    }
  }
  if (d.size() == 0)
    cout << "UNRESTORABLE" << endl;
  else {
    Sort(d);
    cout << d.at(0) << endl;
  }
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  string S, T;
  cin >> S >> T;

  bool found = false;

  for (int i = 0; i <= S.size() - T.size(); i++) {
    rep(j, T.size()) {
      if (S[i + j] != '?' && S[i + j] != T[j])
        break;
      else if (j == T.size() - 1) {
        rep(k, T.size()) { S[i + k] = T[k]; }
        rep(k, S.size()) {
          if (S[k] == '?')
            S[k] = 'a';
        }
        found = true;
      }
    }
  }

  if (found) {
    cout << S << endl;
  } else {
    cout << "UNRESTORABLE" << endl;
  }

  return 0;
}


Fixed submission:
#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  string S, T;
  cin >> S >> T;

  bool found = false;

  for (int i = S.size() - T.size(); i >= 0; i--) {
    rep(j, T.size()) {
      if (S[i + j] != '?' && S[i + j] != T[j])
        break;
      else if (j == T.size() - 1) {
        rep(k, T.size()) { S[i + k] = T[k]; }
        rep(k, S.size()) {
          if (S[k] == '?')
            S[k] = 'a';
        }
        found = true;
      }
    }
  }

  if (found) {
    cout << S << endl;
  } else {
    cout << "UNRESTORABLE" << endl;
  }

  return 0;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

string s, t;
vector<string> cand;

int main(void) {
  cin >> s >> t;

  if (s.size() - t.size() < 0) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  for (int i = 0; i <= s.size() - t.size(); i++) {
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] != '?' && t[j] != '?' && s[i + j] != t[j])
        goto NG;
    }
    cand.push_back(s);
    for (int j = 0; j < t.size(); j++)
      cand.back()[i + j] = t[j];
    for (int j = 0; j < s.size(); j++) {
      if (cand.back()[j] == '?')
        cand.back()[j] = 'a';
    }
  NG:;
  }
  if (cand.size() == 0) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  sort(cand.begin(), cand.end());
  cout << cand[0] << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

string s, t;
vector<string> cand;

int main(void) {
  cin >> s >> t;

  if (s.size() < t.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  for (int i = 0; i <= s.size() - t.size(); i++) {
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] != '?' && t[j] != '?' && s[i + j] != t[j])
        goto NG;
    }
    cand.push_back(s);
    for (int j = 0; j < t.size(); j++)
      cand.back()[i + j] = t[j];
    for (int j = 0; j < s.size(); j++) {
      if (cand.back()[j] == '?')
        cand.back()[j] = 'a';
    }
  NG:;
  }
  if (cand.size() == 0) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  sort(cand.begin(), cand.end());
  cout << cand[0] << endl;
  return 0;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
  string s, t, tmp;
  cin >> s >> t;
  vector<string> kouho;
  bool isfit;
  for (int i = 0; i <= s.size() - t.size(); i++) {
    isfit = true;
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] != t[j] && s[i + j] != '?') {
        isfit = false;
        break;
      }
    }
    if (isfit) {
      tmp = s;
      tmp.replace(i, t.size(), t);
      kouho.push_back(tmp);
    }
  }
  if (kouho.size() == 0) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = 0; i < kouho.size(); i++) {
    while (kouho[i].find('?') != -1) {
      tmp = kouho[i];
      tmp.replace(tmp.find('?'), 1, "a");
      kouho[i] = tmp;
    }
  }
  sort(kouho.begin(), kouho.end());
  cout << kouho[0] << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
  string s, t, tmp;
  cin >> s >> t;
  vector<string> kouho;
  bool isfit;
  if (s.size() < t.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = 0; i <= s.size() - t.size(); i++) {
    isfit = true;
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] != t[j] && s[i + j] != '?') {
        isfit = false;
        break;
      }
    }
    if (isfit) {
      tmp = s;
      tmp.replace(i, t.size(), t);
      kouho.push_back(tmp);
    }
  }
  if (kouho.size() == 0) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = 0; i < kouho.size(); i++) {
    while (kouho[i].find('?') != -1) {
      tmp = kouho[i];
      tmp.replace(tmp.find('?'), 1, "a");
      kouho[i] = tmp;
    }
  }
  sort(kouho.begin(), kouho.end());
  cout << kouho[0] << endl;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
string s, t;
int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> s >> t;
  string mmin;
  for (int i = 0; i < s.size(); i++)
    mmin += "}";
  for (int i = 0; i <= s.size() - t.size(); i++) {
    string tmp = s.substr(i, t.size());
    string tt = s;
    for (int j = 0; j < tmp.size(); j++)
      if (tmp[j] == '?')
        tmp[j] = t[j];
    if (tmp == t) {
      tt.replace(i, t.size(), t);
      for (int j = 0; j < tt.size(); j++)
        if (tt[j] == '?')
          tt[j] = 'a';
      mmin = min(mmin, tt);
    }
  }
  if (mmin[0] != '}')
    cout << mmin << endl;
  else
    cout << "UNRESTORABLE" << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
string s, t;
int main() {
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> s >> t;
  string mmin;
  if (t.size() > s.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for (int i = 0; i < s.size(); i++)
    mmin += "}";
  for (int i = 0; i <= s.size() - t.size(); i++) {
    string tmp = s.substr(i, t.size());
    string tt = s;
    for (int j = 0; j < tmp.size(); j++)
      if (tmp[j] == '?')
        tmp[j] = t[j];
    if (tmp == t) {
      tt.replace(i, t.size(), t);
      for (int j = 0; j < tt.size(); j++)
        if (tt[j] == '?')
          tt[j] = 'a';
      mmin = min(mmin, tt);
    }
  }
  if (mmin[0] != '}')
    cout << mmin << endl;
  else
    cout << "UNRESTORABLE" << endl;
  return 0;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

string S, T;

int main() {

  cin >> S;
  cin >> T;

  int i, j;

  int ans = 0;
  int idx = 0;

  for (i = 0; i <= S.size() - T.size(); i++) {
    string sub_str = S.substr(i, T.size());
    int flag = 0;
    for (j = 0; j < T.size(); j++) {
      if (sub_str[j] == '?' || T[j] == sub_str[j])
        ;
      else {
        flag = 1;
      }
    }
    if (flag == 0) {
      ans = 1;
      idx = i;
    }
  }

  if (ans == 0) {
    printf("UNRESTORABLE\n");
  } else {
    string S_ans = S;
    for (i = idx; i < idx + T.size(); i++) {
      S_ans[i] = T[i - idx];
    }
    for (i = 0; i < S_ans.size(); i++) {
      if (S_ans[i] == '?') {
        S_ans[i] = 'a';
      }
    }
    cout << S_ans << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

string S, T;

int main() {

  cin >> S;
  cin >> T;

  int i, j;

  int ans = 0;
  int idx = 0;

  if (S.size() < T.size()) {
    printf("UNRESTORABLE\n");
    return 0;
  }

  for (i = 0; i <= S.size() - T.size(); i++) {
    string sub_str = S.substr(i, T.size());
    int flag = 0;
    for (j = 0; j < T.size(); j++) {
      if (sub_str[j] == '?' || T[j] == sub_str[j])
        ;
      else {
        flag = 1;
      }
    }
    if (flag == 0) {
      ans = 1;
      idx = i;
    }
  }

  if (ans == 0) {
    printf("UNRESTORABLE\n");
  } else {
    string S_ans = S;
    for (i = idx; i < idx + T.size(); i++) {
      S_ans[i] = T[i - idx];
    }
    for (i = 0; i < S_ans.size(); i++) {
      if (S_ans[i] == '?') {
        S_ans[i] = 'a';
      }
    }
    cout << S_ans << endl;
  }

  return 0;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  string ans = "{";
  for (int i = 0; i <= s.size() - t.size(); i++) {
    string tmp(s.size(), '?');
    for (int j = 0; j < i; j++)
      tmp[j] = (s[j] == '?') ? 'a' : s[j];

    bool flag = true;
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] == '?' || s[i + j] == t[j])
        tmp[i + j] = t[j];
      else {
        flag = false;
        break;
      }
    }
    if (!flag)
      continue;
    for (int j = i + t.size(); j < s.size(); j++) {
      tmp[j] = (s[j] == '?') ? 'a' : s[j];
    }

    if (ans > tmp)
      ans = tmp;
  }
  cout << ((ans == "{") ? "UNRESTORABLE" : ans) << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  string s, t;
  cin >> s >> t;
  string ans = "{";
  if (s.size() < t.size()) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }

  for (int i = 0; i <= s.size() - t.size(); i++) {
    string tmp(s.size(), '?');
    for (int j = 0; j < i; j++)
      tmp[j] = (s[j] == '?') ? 'a' : s[j];

    bool flag = true;
    for (int j = 0; j < t.size(); j++) {
      if (s[i + j] == '?' || s[i + j] == t[j])
        tmp[i + j] = t[j];
      else {
        flag = false;
        break;
      }
    }
    if (!flag)
      continue;
    for (int j = i + t.size(); j < s.size(); j++) {
      tmp[j] = (s[j] == '?') ? 'a' : s[j];
    }

    if (ans > tmp)
      ans = tmp;
  }
  cout << ((ans == "{") ? "UNRESTORABLE" : ans) << endl;
  return 0;
}
Problem p03565 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S, T;
  cin >> S >> T;

  reverse(all(S));
  reverse(all(T));
  int k = T.size();
  bool elf = false;

  //?について調べる
  for (int i = 0; i < S.size() - k - 1; ++i) {
    bool res = true;
    string s = S.substr(i, k);
    for (int j = 0; j < k; ++j) {
      if (s[j] == '?')
        continue;
      if (s[j] != T[j])
        res = false;
    }
    if (res) {
      for (int j = 0; j < k; ++j) {
        S[i + j] = T[j];
      }
      elf = true;
      break;
    }
  }

  if (!elf) {
    puts("UNRESTORABLE");
    return 0;
  }

  rep(i, S.size()) {
    if (S[i] == '?')
      S[i] = 'a';
  }

  reverse(all(S));

  dunk(S);

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S, T;
  cin >> S >> T;

  if (S.size() < T.size()) {
    puts("UNRESTORABLE");
    return 0;
  }
  // こっち
  /*if (S.size() == T.size() && count(all(S), '?') != S.size()) {
          puts("UNRESTORABLE");
          return 0;
  }*/

  reverse(all(S));
  reverse(all(T));
  int k = T.size();
  bool elf = false;

  //?について調べる
  for (int i = 0; i < S.size() - k - 1; ++i) {
    bool res = true;
    string s = S.substr(i, k);
    for (int j = 0; j < k; ++j) {
      if (s[j] == '?')
        continue;
      if (s[j] != T[j])
        res = false;
    }
    if (res) {
      for (int j = 0; j < k; ++j) {
        S[i + j] = T[j];
      }
      elf = true;
      break;
    }
  }

  if (!elf) {
    puts("UNRESTORABLE");
    return 0;
  }

  rep(i, S.size()) {
    if (S[i] == '?')
      S[i] = 'a';
  }

  reverse(all(S));

  dunk(S);

  return 0;
}
Problem p03566 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)
#define pq priority_queue
#define P pair<int, int>
#define P2 pair<int, P>
#define P3 pair<int, P2>
typedef long long ll;
typedef long double ld;
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7,
          around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
const ll LINF = 1e18;
const ld PI = abs(acos(-1));
int n, t[110], v[110];
double dp[20010][310];

int main() {
  cin >> n;
  REP(i, 0, n) cin >> t[i];
  REP(i, 0, n) t[i + 1] += t[i];
  REP(i, 0, n) cin >> v[i];

  int c = 0, s[1010];
  REP(i, 0, t[n]) {
    if (t[c] == i)
      c++;
    s[i] = v[c];
  }

  REP(i, 0, t[n]) REP(j, 0, 310) dp[i][j] = -(double)INF;
  dp[0][0] = 0;
  REP(i, 0, t[n]) {
    REP(j, 0, 310) {
      if (dp[i][j] == -(double)INF)
        continue;
      REP(k, -1, 2) {
        if (j + k > s[i + 1] or j + k < 0)
          continue;
        if (k == 1 and j == s[i])
          continue;
        dp[i + 1][j + k] = max(dp[i + 1][j + k], dp[i][j] + j + k * 0.5);
      }
      if (s[i] > j and s[i + 1] >= j)
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + 0.25 + j);
    }
  }

  cout << fixed << setprecision(9);
  cout << dp[t[n]][0] << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)
#define pq priority_queue
#define P pair<int, int>
#define P2 pair<int, P>
#define P3 pair<int, P2>
typedef long long ll;
typedef long double ld;
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7,
          around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
const ll LINF = 1e18;
const ld PI = abs(acos(-1));
int n, t[110], v[110];
double dp[20010][310];

int main() {
  cin >> n;
  REP(i, 0, n) cin >> t[i];
  REP(i, 0, n) t[i + 1] += t[i];
  REP(i, 0, n) cin >> v[i];

  int c = 0, s[20010];
  REP(i, 0, t[n]) {
    if (t[c] == i)
      c++;
    s[i] = v[c];
  }

  REP(i, 0, t[n]) REP(j, 0, 310) dp[i][j] = -(double)INF;
  dp[0][0] = 0;
  REP(i, 0, t[n]) {
    REP(j, 0, 310) {
      if (dp[i][j] == -(double)INF)
        continue;
      REP(k, -1, 2) {
        if (j + k > s[i + 1] or j + k < 0)
          continue;
        if (k == 1 and j == s[i])
          continue;
        dp[i + 1][j + k] = max(dp[i + 1][j + k], dp[i][j] + j + k * 0.5);
      }
      if (s[i] > j and s[i + 1] >= j)
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + 0.25 + j);
    }
  }

  cout << fixed << setprecision(9);
  cout << dp[t[n]][0] << endl;
  return 0;
}
Problem p03566 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

typedef vector<int> vi;
typedef pair<int, int> pii;

int main(void) {
  int i, j;
  int n;
  cin >> n;
  vi t(n), v(n);
  rep(i, n) cin >> t[i], t[i] *= 2;
  rep(i, n) cin >> v[i];
  rep(i, n - 1) t[i + 1] += t[i];

  int max_t = t[n - 1];
  vector<double> v1(max_t + 1, 0.0), v2(max_t + 1, 0.0);
  int cnt = 0;
  rep(i, max_t + 1) {
    if (i == t[cnt])
      cnt++;
    v1[i + 1] = min((double)v[cnt], v1[i] + 0.5);
  }
  for (; i > 0; i--) {
    if (i == t[cnt - 1])
      cnt--;
    v2[i - 1] = min((double)v[cnt], v2[i] + 0.5);
  }

  double ans = 0;
  rep(i, max_t + 1) ans += min(v1[i], v2[i]);
  cout << shosu(5) << ans / 2 << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i, n) for (i = 0; i < n; i++)
#define loop(i, a, n) for (i = a; i < n; i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

typedef vector<int> vi;
typedef pair<int, int> pii;

int main(void) {
  int i, j;
  int n;
  cin >> n;
  vi t(n), v(n);
  rep(i, n) cin >> t[i], t[i] *= 2;
  rep(i, n) cin >> v[i];
  rep(i, n - 1) t[i + 1] += t[i];

  int max_t = t[n - 1];
  vector<double> v1(max_t + 1, 0.0), v2(max_t + 1, 0.0);
  int cnt = 0;
  rep(i, max_t) {
    if (i == t[cnt])
      cnt++;
    v1[i + 1] = min((double)v[cnt], v1[i] + 0.5);
  }
  for (; i > 0; i--) {
    if (i == t[cnt - 1])
      cnt--;
    v2[i - 1] = min((double)v[cnt], v2[i] + 0.5);
  }

  double ans = 0;
  rep(i, max_t + 1) ans += min(v1[i], v2[i]);
  cout << shosu(5) << ans / 2 << endl;
}
Problem p03566 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <string>
#include <vector>

#include <inttypes.h>
using namespace std;

int main() {
  int32_t N;
  scanf("%d", &N);

  int32_t t[101];
  int32_t T = 0;
  for (int32_t i = 0; i < N; i++) {
    scanf("%d", &t[i]);
    T += t[i];
  }

  int32_t v[101];
  for (int32_t i = 0; i < N; i++) {
    scanf("%d", &v[i]);
  }

  double max_v[20001];
  int32_t max_v_index = 0;
  for (int32_t i = 0; i < N; i++) {
    for (int32_t j = 0; j < 2 * t[i]; j++) {
      if (i > 0 && j == 0)
        max_v[max_v_index++] = min(v[i - 1], v[i]);
      else
        max_v[max_v_index++] = v[i];
    }
  }

  max_v[0] = 0;
  max_v[2 * T] = 0;

  for (int32_t i = 1; i < 2 * T + 1; i++)
    max_v[i] = min(max_v[i], max_v[i - 1] + 0.5);
  for (int32_t i = 2 * T - 1; i >= 0; i--)
    max_v[i] = min(max_v[i], max_v[i + 1] + 0.5);

  double res = 0;
  for (int32_t i = 0; i < 2 * T; i++) {
    res += min(max_v[i], max_v[i + 1]) * 0.5;
    if (max_v[i] != max_v[i + 1])
      res += 0.5 * 0.5 / 2;
  }

  printf("%.17f\n", res);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <string>
#include <vector>

#include <inttypes.h>
using namespace std;

int main() {
  int32_t N;
  scanf("%d", &N);

  int32_t t[101];
  int32_t T = 0;
  for (int32_t i = 0; i < N; i++) {
    scanf("%d", &t[i]);
    T += t[i];
  }

  int32_t v[101];
  for (int32_t i = 0; i < N; i++) {
    scanf("%d", &v[i]);
  }

  double max_v[40001];
  int32_t max_v_index = 0;
  for (int32_t i = 0; i < N; i++) {
    for (int32_t j = 0; j < 2 * t[i]; j++) {
      if (i > 0 && j == 0)
        max_v[max_v_index++] = min(v[i - 1], v[i]);
      else
        max_v[max_v_index++] = v[i];
    }
  }

  max_v[0] = 0;
  max_v[2 * T] = 0;

  for (int32_t i = 1; i < 2 * T + 1; i++)
    max_v[i] = min(max_v[i], max_v[i - 1] + 0.5);
  for (int32_t i = 2 * T - 1; i >= 0; i--)
    max_v[i] = min(max_v[i], max_v[i + 1] + 0.5);

  double res = 0;
  for (int32_t i = 0; i < 2 * T; i++) {
    res += min(max_v[i], max_v[i + 1]) * 0.5;
    if (max_v[i] != max_v[i + 1])
      res += 0.5 * 0.5 / 2;
  }

  printf("%.17f\n", res);

  return 0;
}
Problem p03566 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  int t[101];
  int v[102];
  for (int i = 0; i < n; i++) {
    scanf("%d", &t[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &v[i]);
  }
  v[n] = 0;
  float g[20001];
  g[0] = 0;
  int tt = 0;
  for (int i = 0; i < n; i++) {
    int u = tt + t[i] * 2;
    for (; tt < u; tt++) {
      if (g[tt] + 0.5 <= v[i]) {
        g[tt + 1] = g[tt] + 0.5;
      } else
        g[tt + 1] = g[tt];
    }
    if (g[tt] > v[i + 1]) {
      int p = tt;
      g[p] = v[i + 1];
      while (true) {
        if (g[p - 1] != g[p] + 0.5) {
          g[p - 1] = g[p] + 0.5;
          p--;
        } else
          break;
      }
    }
  }

  float ans = 0;
  for (int i = 0; i < tt; i++) {
    ans += (g[i] + g[i + 1]);
  }

  printf("%.8f\n", ans / 4);

  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;
  int t[101];
  int v[102];
  for (int i = 0; i < n; i++) {
    scanf("%d", &t[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &v[i]);
  }
  v[n] = 0;
  float g[60001];
  g[0] = 0;
  int tt = 0;
  for (int i = 0; i < n; i++) {
    int u = tt + t[i] * 2;
    for (; tt < u; tt++) {
      if (g[tt] + 0.5 <= v[i]) {
        g[tt + 1] = g[tt] + 0.5;
      } else
        g[tt + 1] = g[tt];
    }
    if (g[tt] > v[i + 1]) {
      int p = tt;
      g[p] = v[i + 1];
      while (true) {
        if (g[p - 1] != g[p] + 0.5) {
          g[p - 1] = g[p] + 0.5;
          p--;
        } else
          break;
      }
    }
  }

  float ans = 0;
  for (int i = 0; i < tt; i++) {
    ans += (g[i] + g[i + 1]);
  }

  printf("%.8f\n", ans / 4);

  return 0;
}
Problem p03566 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int64_t INF = (1LL << 62);

int main() {
  int N, t = 0;
  double v;
  cin >> N;
  vector<double> T(N), maxv(40000, INF);
  maxv[0] = 0;
  for (int i = 0; i < N; i++)
    cin >> T.at(i);
  for (int i = 0; i < N; i++) {
    cin >> v;
    for (int j = 0; j <= T.at(i) * 2; j++) {
      maxv.at(t + j) = min(v, maxv.at(t + j));
    }
    t += T.at(i) * 2;
  }
  maxv[t] = 0;
  for (int i = 1; i <= t; i++)
    maxv[i] = min(maxv[i], maxv[i - 1] + 0.5);
  for (int i = t - 1; i >= 0; i--)
    maxv[i] = min(maxv[i], maxv[i + 1] + 0.5);
  double ans = 0;
  for (int i = 1; i <= t; i++)
    ans += ((maxv[i - 1] + maxv[i]) * 0.5) / 2.0;
  cout << fixed << setprecision(15) << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int64_t INF = (1LL << 62);

int main() {
  int N, t = 0;
  double v;
  cin >> N;
  vector<double> T(N), maxv(40010, INF);
  maxv[0] = 0;
  for (int i = 0; i < N; i++)
    cin >> T.at(i);
  for (int i = 0; i < N; i++) {
    cin >> v;
    for (int j = 0; j <= T.at(i) * 2; j++) {
      maxv.at(t + j) = min(v, maxv.at(t + j));
    }
    t += T.at(i) * 2;
  }
  maxv[t] = 0;
  for (int i = 1; i <= t; i++)
    maxv[i] = min(maxv[i], maxv[i - 1] + 0.5);
  for (int i = t - 1; i >= 0; i--)
    maxv[i] = min(maxv[i], maxv[i + 1] + 0.5);
  double ans = 0;
  for (int i = 1; i <= t; i++)
    ans += ((maxv[i - 1] + maxv[i]) * 0.5) / 2.0;
  cout << fixed << setprecision(15) << ans << endl;
}
Problem p03566 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
long long int mod = 1e9 + 7;
template <class T> void inputV(vector<T> &x, int n) {
  for (int i = 0; i < n; i++)
    cin >> x[i];
}

int main() {
  int n;
  cin >> n;
  vector<int> t(n + 1, 0);
  vector<int> v(n);
  for (int i = 1; i <= n; i++) {
    cin >> t[i];
    t[i] += t[i - 1];
  }
  for (int i = 0; i < n; i++)
    cin >> v[i];
  vector<double> mv(404, 0.0);
  for (int i = 1; i <= n; i++) {
    for (int j = t[i - 1] * 2 + 1; j <= t[i] * 2; j++) {
      mv[j] = min(mv[j - 1] + 0.5, v[i - 1] * 1.0);
    }
  }

  mv[t[n] * 2] = 0.0;
  for (int i = n; i >= 1; i--) {
    for (int j = t[i] * 2; j >= t[i - 1] * 2 + 1; j--) {
      mv[j - 1] = min({mv[j] + 0.5, mv[j - 1], v[i - 1] * 1.0});
    }
  }
  double ans = 0.0;
  for (int i = 0; i <= t[n] * 2; i++) {
    ans += (mv[i] + mv[i + 1]) / 4;
  }
  printf("%.4lf\n", ans);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
long long int mod = 1e9 + 7;
template <class T> void inputV(vector<T> &x, int n) {
  for (int i = 0; i < n; i++)
    cin >> x[i];
}

int main() {
  int n;
  cin >> n;
  vector<int> t(n + 1, 0);
  vector<int> v(n);
  for (int i = 1; i <= n; i++) {
    cin >> t[i];
    t[i] += t[i - 1];
  }
  for (int i = 0; i < n; i++)
    cin >> v[i];
  vector<double> mv(40010, 0.0);
  for (int i = 1; i <= n; i++) {
    for (int j = t[i - 1] * 2 + 1; j <= t[i] * 2; j++) {
      mv[j] = min(mv[j - 1] + 0.5, v[i - 1] * 1.0);
    }
  }

  mv[t[n] * 2] = 0.0;
  for (int i = n; i >= 1; i--) {
    for (int j = t[i] * 2; j >= t[i - 1] * 2 + 1; j--) {
      mv[j - 1] = min({mv[j] + 0.5, mv[j - 1], v[i - 1] * 1.0});
    }
  }
  double ans = 0.0;
  for (int i = 0; i <= t[n] * 2; i++) {
    ans += (mv[i] + mv[i + 1]) / 4;
  }
  printf("%.4lf\n", ans);

  return 0;
}
Problem p03566 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iomanip>
#include <iostream>
using namespace std;

int main() {
  int n, T[100];
  cin >> n;
  double V[100];
  for (int i = 0; i < n; i++)
    cin >> T[i];
  for (int i = 0; i < n; i++)
    cin >> V[i];

  int t = 0;
  double vl[10005], vr[10005];
  vl[0] = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 2 * T[i]; j++) {
      vl[t + 1] = min(vl[t] + 0.5, V[i]);
      t++;
    }

  vr[t] = 0;
  for (int i = n - 1; i >= 0; i--)
    for (int j = 0; j < 2 * T[i]; j++) {
      vr[t - 1] = min(vr[t] + 0.5, V[i]);
      t--;
    }

  double ans = 0;
  t = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 2 * T[i]; j++) {
      ans += (min(vl[t], vr[t]) + min(vl[t + 1], vr[t + 1])) / 4;
      t++;
    }
  cout << fixed << setprecision(14) << ans << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
using namespace std;

int main() {
  int n, T[100];
  cin >> n;
  double V[100];
  for (int i = 0; i < n; i++)
    cin >> T[i];
  for (int i = 0; i < n; i++)
    cin >> V[i];

  int t = 0;
  double vl[40005], vr[40005];
  vl[0] = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 2 * T[i]; j++) {
      vl[t + 1] = min(vl[t] + 0.5, V[i]);
      t++;
    }

  vr[t] = 0;
  for (int i = n - 1; i >= 0; i--)
    for (int j = 0; j < 2 * T[i]; j++) {
      vr[t - 1] = min(vr[t] + 0.5, V[i]);
      t--;
    }

  double ans = 0;
  t = 0;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 2 * T[i]; j++) {
      ans += (min(vl[t], vr[t]) + min(vl[t + 1], vr[t + 1])) / 4;
      t++;
    }
  cout << fixed << setprecision(14) << ans << endl;

  return 0;
}
Problem p03566 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> pll;
const ll mod = 1e9 + 7;
// const ll mod=998244353;
const ll inf = 1LL << 61;

int main() {
  ll n;
  cin >> n;
  vec t(n), v(n);
  for (ll i = 0; i < n; i++)
    cin >> t[i], t[i] *= 2;
  for (ll i = 0; i < n; i++)
    cin >> v[i], v[i] *= 2;
  for (ll i = 0; i < n - 1; i++)
    t[i + 1] += t[i];
  ll ct = 0;
  ll cv = 0;
  vec lim(2e4 + 10);
  for (ll i = 0; i < n; i++) {
    if (i)
      ct--, cv--;
    while (ct <= t[i]) {
      lim[ct] = min(cv, v[i]);
      cv = lim[ct] + 1;
      ct++;
    }
  }
  cv = 0;
  ct--;
  double ans = 0;
  while (ct) {
    cv = min(lim[ct], cv);
    ans += cv;
    ct--;
    cv++;
  }
  ans *= 1 / 4.0;
  cout << fixed << setprecision(10) << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> pll;
const ll mod = 1e9 + 7;
// const ll mod=998244353;
const ll inf = 1LL << 61;

int main() {
  ll n;
  cin >> n;
  vec t(n), v(n);
  for (ll i = 0; i < n; i++)
    cin >> t[i], t[i] *= 2;
  for (ll i = 0; i < n; i++)
    cin >> v[i], v[i] *= 2;
  for (ll i = 0; i < n - 1; i++)
    t[i + 1] += t[i];
  ll ct = 0;
  ll cv = 0;
  vec lim(8e4 + 10);
  for (ll i = 0; i < n; i++) {
    if (i)
      ct--, cv--;
    while (ct <= t[i]) {
      lim[ct] = min(cv, v[i]);
      cv = lim[ct] + 1;
      ct++;
    }
  }
  cv = 0;
  ct--;
  double ans = 0;
  while (ct) {
    cv = min(lim[ct], cv);
    ans += cv;
    ct--;
    cv++;
  }
  ans *= 1 / 4.0;
  cout << fixed << setprecision(10) << ans << endl;
}
Problem p03566 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static const int MAX = 100;
int g[MAX * 4 + 2];

int n, t[MAX + 2], v[MAX + 2], ans;
int main(void) {
  cin >> n;
  t[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> t[i];
    t[i] *= 2;        // x->2*x座標にする
    t[i] += t[i - 1]; // 2*x座標と対応させる
  }
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    v[i] *= 2; // y座標も2倍。傾きが1のまま。
  }
  for (int i = 0; i <= t[n]; i++) {
    g[i] = min(i, t[n] - i); // t[0],t[n]の制限
    for (int j = 0; j < n; ++j) {
      if (i <= t[j]) { // i->t[j]->t[j+1]
        g[i] = min(g[i], v[j] + t[j] - i);
      } else if (t[j + 1] <= i) { // t[j]->t[j+1]->i
        g[i] = min(g[i], v[j] + i - t[j + 1]);
      } else { // t[j]->j->t[j+1]
        g[i] = min(g[i], v[j]);
      }
    }
  }
  for (int i = 0; i < t[n]; ++i) {
    ans += g[i] + g[i + 1]; // 台形の面積
  }
  printf("%.5lf\n", ((double)(ans) / 8));
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static const int MAX = 100;
int g[MAX * 400 + 2];

int n, t[MAX + 2], v[MAX + 2], ans;
int main(void) {
  cin >> n;
  t[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> t[i];
    t[i] *= 2;        // x->2*x座標にする
    t[i] += t[i - 1]; // 2*x座標と対応させる
  }
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    v[i] *= 2; // y座標も2倍。傾きが1のまま。
  }
  for (int i = 0; i <= t[n]; i++) {
    g[i] = min(i, t[n] - i); // t[0],t[n]の制限
    for (int j = 0; j < n; ++j) {
      if (i <= t[j]) { // i->t[j]->t[j+1]
        g[i] = min(g[i], v[j] + t[j] - i);
      } else if (t[j + 1] <= i) { // t[j]->t[j+1]->i
        g[i] = min(g[i], v[j] + i - t[j + 1]);
      } else { // t[j]->j->t[j+1]
        g[i] = min(g[i], v[j]);
      }
    }
  }
  for (int i = 0; i < t[n]; ++i) {
    ans += g[i] + g[i + 1]; // 台形の面積
  }
  printf("%.5lf\n", ((double)(ans) / 8));
  return 0;
}
Problem p03566 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> t(n + 2);
  vector<double> v(n + 2), va;
  for (int i = 1; i <= n; i++)
    cin >> t[i];
  for (int i = 1; i <= n; i++)
    cin >> v[i];
  for (int i = 1; i <= n; i++)
    t[i] += t[i - 1];
  for (int i = 0; i <= n; i++)
    t[i] *= 2;
  for (int i = 0; i <= t[n]; i++) {
    double s = i / 2.;
    for (int j = 1; j <= n; j++) {
      if (t[j - 1] <= i && i <= t[j])
        s = min(s, v[j]);
      else if (i < t[j - 1])
        s = min(s, v[j] + abs(t[j - 1] - i) / 2.);
      else if (t[j] < i)
        s = min(s, v[j] + abs(t[j] - i) / 2.);
    }
    s = min(s, abs(t[n] - i) / 2.);
    va.push_back(s);
  }

  double ans = 0;
  for (int i = 0; i < (int)va.size() - 1; i++) {
    ans += 0.5 * (va[i + 1] + va[i]) / 2.;
  }
  cout << fixed << setprecision(100000000) << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

typedef long long ll;

int main() {
  int n;
  cin >> n;
  vector<int> t(n + 2);
  vector<double> v(n + 2), va;
  for (int i = 1; i <= n; i++)
    cin >> t[i];
  for (int i = 1; i <= n; i++)
    cin >> v[i];
  for (int i = 1; i <= n; i++)
    t[i] += t[i - 1];
  for (int i = 0; i <= n; i++)
    t[i] *= 2;
  for (int i = 0; i <= t[n]; i++) {
    double s = i / 2.;
    for (int j = 1; j <= n; j++) {
      if (t[j - 1] <= i && i <= t[j])
        s = min(s, v[j]);
      else if (i < t[j - 1])
        s = min(s, v[j] + abs(t[j - 1] - i) / 2.);
      else if (t[j] < i)
        s = min(s, v[j] + abs(t[j] - i) / 2.);
    }
    s = min(s, abs(t[n] - i) / 2.);
    va.push_back(s);
  }

  double ans = 0;
  for (int i = 0; i < (int)va.size() - 1; i++) {
    ans += 0.5 * (va[i + 1] + va[i]) / 2.;
  }
  cout << fixed << setprecision(1000000) << ans << endl;
  return 0;
}
Problem p03566 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n; i >= 0; i--)
#define REP(i, s, t) for (int i = s; i <= t; i++)
#define RREP(i, s, t) for (int i = s; i >= t; i--)
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int t[110], v[110];
  rep(i, N) cin >> t[i];
  int sum = 0;
  rep(i, N) sum += t[i];
  rep(i, N) cin >> v[i];
  int s[20010];
  rep(i, 20010) { s[i] = INF; }
  s[0] = 0;
  int T = 0;
  rep(i, N) {
    for (int j = T; j < T + t[i] * 2; j += 2) {
      s[j + 1] = min({s[j + 1], v[i] * 2, s[j] + 1});
      s[j + 2] = min({s[j + 2], v[i] * 2, s[j] + 2});
    }
    T += t[i] * 2;
  }
  // rep(i, sum * 2 + 1) cout << fixed << setprecision(1) << i/2.0 << " " <<
  // s[i]/2.0 << endl; cout << endl;
  T = sum * 2;
  s[sum * 2] = 0;
  RREP(i, N - 1, 0) {
    for (int j = T; j > T - t[i] * 2; j -= 2) {
      s[j - 1] = min({s[j - 1], v[i] * 2, s[j] + 1});
      s[j - 2] = min({s[j - 2], v[i] * 2, s[j] + 2});
    }
    T -= t[i] * 2;
  }
  int ans = 0;
  // rep(i, sum * 2 + 1) cout << fixed << setprecision(1) << i/2.0 << " " <<
  // s[i]/2.0 << endl; cout << endl;
  rep(i, sum * 2 + 1) ans += s[i];
  cout << fixed << setprecision(12) << ans / 4.0 << endl;

  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n; i >= 0; i--)
#define REP(i, s, t) for (int i = s; i <= t; i++)
#define RREP(i, s, t) for (int i = s; i >= t; i--)
#define dump(x) cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int t[110], v[110];
  rep(i, N) cin >> t[i];
  int sum = 0;
  rep(i, N) sum += t[i];
  rep(i, N) cin >> v[i];
  int s[40010];
  rep(i, 40010) { s[i] = INF; }
  s[0] = 0;
  int T = 0;
  rep(i, N) {
    for (int j = T; j < T + t[i] * 2; j += 2) {
      s[j + 1] = min({s[j + 1], v[i] * 2, s[j] + 1});
      s[j + 2] = min({s[j + 2], v[i] * 2, s[j] + 2});
    }
    T += t[i] * 2;
  }
  // rep(i, sum * 2 + 1) cout << fixed << setprecision(1) << i/2.0 << " " <<
  // s[i]/2.0 << endl; cout << endl;
  T = sum * 2;
  s[sum * 2] = 0;
  RREP(i, N - 1, 0) {
    for (int j = T; j > T - t[i] * 2; j -= 2) {
      s[j - 1] = min({s[j - 1], v[i] * 2, s[j] + 1});
      s[j - 2] = min({s[j - 2], v[i] * 2, s[j] + 2});
    }
    T -= t[i] * 2;
  }
  int ans = 0;
  // rep(i, sum * 2 + 1) cout << fixed << setprecision(1) << i/2.0 << " " <<
  // s[i]/2.0 << endl; cout << endl;
  rep(i, sum * 2 + 1) ans += s[i];
  cout << fixed << setprecision(12) << ans / 4.0 << endl;

  return 0;
}