萌新求助配置 Special Judge 题目
  • 板块灌水区
  • 楼主封禁用户
  • 当前回复3
  • 已保存回复3
  • 发布时间2021/5/21 13:13
  • 上次更新2023/11/4 23:00:27
查看原帖
萌新求助配置 Special Judge 题目
271784
封禁用户楼主2021/5/21 13:13

RT,有题配置需使用 Special Judge,官方给了一个 checker.cpp,如下,请问在洛谷配置该题目是否可据此改动使其达标,改动大吗?萌新不太会。

#include <cstdio>
#include <vector>

using namespace std;

#define BUFSIZE 4096
#define T_EOF 256
#define T_BAD 257
#define T_WS  258

struct parser {
  char buf[BUFSIZE];
  int pos;
  bool eof;
  FILE *f;

  bool ws(char x)
  { 
    return x == 0 || x == '\n' || x == '\r' || x == '\t' || x == ' ';
  }

  bool read()
  {
    if (eof)
      return false;
    while (buf[pos] == 0) {
      if (fgets(buf, BUFSIZE - 1, f) == NULL) {
        eof = true;
        return false;
      }
      bool all_ws = true;
      for (int i = 0; buf[i] != 0; ++i)
        if (!ws(buf[i])) {
          all_ws = false;
          break;
        }
      if (all_ws)
        buf[0] = 0;
      pos = 0;
    }
    return true;
  }

  int next()
  {
    if (!read())
      return T_EOF;
    char x = buf[pos++];
    if (ws(x))
      return T_WS;
    if (x<'0' || x>'9')
      return T_BAD;
    return (int) x;
  }

  void open(char *co)
  {
    f = fopen(co, "r");
    eof = false;
    pos = 0; 
    buf[0] = 0;
    read(); 
  }

  void close()
  {
    fclose(f);
    eof = true;
    pos = 0;
  }

  void back()
  {
    pos--;
  }

  bool read_ws()
  {
    int x;
    do { 
      x = next(); 
    } while (x == T_WS);
    if (x > 255)
      return false;
    back();
    return true;
  };

  int read_int(bool &ok)
  {
    if (!read_ws()) {
      ok = false;
      return 0;
    }
    //int znak = 1;
    int a = next();
    //if (a == '-') { znak =-1; a = next(); }
    if (a > 255) {
      ok = false;
      return 0;
    }
    int x = a - '0';
    int i = 0;
    while (++i < 10) {
      a = next();
      if (a == T_BAD) {
        ok = false;
	return x;
      }
      if (a > 255) {
        ok = true;
        //return znak < 0 ? -x : x;
        return x;
      }
      x *= 10;
      x += a - '0';
    }
    ok = false;
    return x;
  }
};

int n;

parser p;

typedef pair<int,int> block;

struct code {
  int e;
  int last_ch;
  int last_count;
  vector<block> res;

  code()
  {
    e = 0;
    last_ch = -1;
    last_count = 0;
  }

  void flush()
  {
    if (last_ch != -1)
      res.push_back(make_pair(last_ch, last_count));
  }

  void append(int a, int count)
  {
    if (a == last_ch)
      last_count += count;
    else {
      flush();
      last_ch = a;
      last_count = count;
    }
  }
  
  int read_ch(bool &ok)
  {
    int ch = p.read_int(ok);
    if (ch < 0 || ch >= n)
      ok = false;
    return ch;
  }
  
  vector<block> decode(bool &ok)
  {
    int m = p.read_int(ok);
    if (!ok)
      return vector<block>();
    int i = 0;
    while (i < m) {
      int a = read_ch(ok);
      if (!ok)
        return vector<block>();
      i++;
      if (a == e) {
        int b = read_ch(ok);
        if (!ok)
          return vector<block>();
	int k = read_ch(ok);
        if (!ok)
          return vector<block>();
        i += 2;
        if (b == e)
	  append(e, k + 1);
        else if (k == 0)
	  e = b;
        else
	  append(b, k + 3);
      } else
        append(a, 1);
    }
    flush();
    return res;
  }
};

int main(int argc, char *argv[])
{
  bool ok = true;
  p.open(argv[1]);
  n = p.read_int(ok);
  vector<block> input = code().decode(ok);
  p.close();
  if (!ok) {
    printf("Wrong input!?!?");
    return 1;
  }
  p.open(argv[2]);
  int len = p.read_int(ok);
  p.close();
  p.open(argv[2]);
  vector<block> seq = code().decode(ok);
  if (!ok) {
    printf("WRONG Output is corrupted");
    return 1;
  }
  p.close();
  if (input != seq) {
    printf("WRONG the output code does not encode the input sequence");
    return 1;
  }
  p.open(argv[3]);
  int min_len = p.read_int(ok);
  p.close();
  if (min_len < len) {
    printf("WRONG code is not the shortest");
    return 1;
  } else if (min_len > len) {
    printf("WRONG error in model solution!!!");
    return 2;
  }
  printf("OK");
  return 0;
}

2021/5/21 13:13
加载中...