結果

問題 No.348 カゴメカゴメ
ユーザー motimoti
提出日時 2016-03-23 23:29:25
言語 Text
(cat 8.3)
結果
WA  
実行時間 -
コード長 4,555 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 6,948 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 21:13:50
合計ジャッジ時間 1,642 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

// 新テストケースverify用
// Rime使えばよかったことにさっき気がついた

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>
#include <boost/filesystem.hpp>
#include <boost/foreach.hpp>

using namespace std;

void main_(); signed main() {
  ios::sync_with_stdio(false);
  main_(); return 0;
}

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int command(string s) {
  return system(s.c_str());
}

string get_suffix(string s) {
  string ret;
  for(int i=(int)s.size()-1; i>=0; i--) {
    if(s[i] == '.') { break; }
    ret.push_back(s[i]);
  }
  reverse(all(ret));
  return ret;
}

int compile(string fname) {
  auto suffix = get_suffix(fname);
  if(suffix == "cpp" || suffix == "cxx") {
    return command("clang++ " + fname + " -std=c++1z -o __" + fname + "_exe");
  }
  else if(suffix == "java") {
    return command("javac " + fname);
  }
  else {
    cout << "undefined suffix: " << suffix << endl;
    return -1;
  }
  return 0;
}

int run_program(string fname, string redirect, int index) {
  auto suffix = get_suffix(fname);
  if(suffix == "cpp" || suffix == "cxx") {
    return command("./__" + fname + "_exe < " + redirect + " > __" + fname + "_out_" + to_string(index));
  }
  else if(suffix == "java") {
    return command("java " + fname.substr(0, fname.size() - 5) + " < " + redirect + " > __" + fname + "_out_" + to_string(index));
  }
  else {
    cout << "undefined suffix: " << suffix << endl;
    return -1;
  }
  return 0;
}

void main_() {

  vector<string> input_fnames;

  namespace fs = boost::filesystem;
  const fs::path path("new_input");
  BOOST_FOREACH(const fs::path& p,
    make_pair(fs::directory_iterator(path), fs::directory_iterator())) {
    if (!fs::is_directory(p)) {
      auto name = p.filename().string();
      if(name[0] == '.') { continue; }
      input_fnames.push_back(path.string() + "/" + name);
    }
  }

  string ac_code; cin >> ac_code;
  vector<string> codes;
  for(string s; cin >> s; codes.push_back(s));

  cout << "Compiling " << ac_code << "(AC code)" << endl;
  assert(0 == compile(ac_code));
  
  for(auto && f: codes) {
    cout << "Compiling " << f << endl;
    assert(0 == compile(f));
  }

  rep(in_idx, input_fnames.size()) {
    cout << "Runnning " << ac_code << "(AC code) with " << input_fnames[in_idx] << endl;
    run_program(ac_code, input_fnames[in_idx], in_idx);
  }

  rep(code_idx, codes.size()) {
    rep(in_idx, input_fnames.size()) {
      cout << "Runnning " << codes[code_idx] << " with " << input_fnames[in_idx] << endl;
      run_program(codes[code_idx], input_fnames[in_idx], in_idx);
    }
  }

  vector<int> pass_count(codes.size());
  map<int, double> input_success_rate;  // input_fnames'index -> rate

  rep(code_idx, codes.size()) {
    rep(in_idx, input_fnames.size()) {
      int s = 0 == command("diff __" + ac_code + "_out_" + to_string(in_idx) + " __" + codes[code_idx] + "_out_" + to_string(in_idx));
      pass_count[code_idx] += s;
      input_success_rate[in_idx] += (double)s / codes.size();
    }
  }

  rep(i, codes.size()) {
    cout << codes[i] << endl;
    cout << "Passed " << pass_count[i] << " / " << input_fnames.size() << endl << endl;
  }

  cout << "Input success rate" << endl;
  for(auto && e: input_success_rate) {
    cout << input_fnames[e.first] << ": " << setprecision(10) << e.second * 100.0 << "%" << endl;
  }

  #define TRY try {
  #define CATCH } catch(fs::filesystem_error& ex) { cout << ex.what() << endl; throw; }

  // remove files

  TRY fs::remove("__" + ac_code + "_exe"); CATCH
  rep(i, input_fnames.size()) {
    TRY fs::remove("__" + ac_code + "_out_" + to_string(i)); CATCH
  }

  rep(i, codes.size()) {
    TRY fs::remove("__" + codes[i] + "_exe"); CATCH
    rep(j, input_fnames.size()) {
      TRY fs::remove("__" + codes[i] + "_out_" + to_string(j)); CATCH
    }
  }

}
0