TODO: implement
This commit is contained in:
parent
aac3171e9e
commit
d7a8e0659e
167
snippet.c
167
snippet.c
|
@ -12,85 +12,24 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <vadefs.h>
|
#include <vadefs.h>
|
||||||
|
#define MAX_IONUM 100000
|
||||||
// Time Limit (normally 1s)
|
// Time Limit (normally 1s)
|
||||||
// 题目的时限(通常为1秒)
|
// 题目的时限(通常为1秒)
|
||||||
const unsigned int case_millseconds = 1000;
|
const unsigned int case_millseconds = 1000;
|
||||||
bool exception_happens = false;
|
|
||||||
unsigned int curr_testcase = 0, sum_mark = 0;
|
unsigned int curr_testcase = 0, sum_mark = 0;
|
||||||
size_t cur_output = 0;
|
size_t cur_output = 0;
|
||||||
#define MAX_IONUM 100000
|
|
||||||
char output_buffer[MAX_IONUM];
|
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN64)
|
#if defined(_WIN32) || defined(__CYGWIN__) || defined(_WIN64)
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
static LPTOP_LEVEL_EXCEPTION_FILTER prev = NULL;
|
HANDLE child_stdout_r = NULL;
|
||||||
const DWORD EXCEPTIONS[20] = {EXCEPTION_ACCESS_VIOLATION,
|
void create_process() {
|
||||||
EXCEPTION_ARRAY_BOUNDS_EXCEEDED,
|
PROCESS_INFORMATION piProcInfo;
|
||||||
EXCEPTION_DATATYPE_MISALIGNMENT,
|
STARTUPINFO siStartInfo;
|
||||||
EXCEPTION_FLT_DENORMAL_OPERAND,
|
BOOL bSuccess = FALSE;
|
||||||
EXCEPTION_FLT_DIVIDE_BY_ZERO,
|
ZeroMemory(&piProcInfo, sizeof(PROCESS_INFORMATION));
|
||||||
EXCEPTION_FLT_INEXACT_RESULT,
|
ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));
|
||||||
EXCEPTION_FLT_INVALID_OPERATION,
|
|
||||||
EXCEPTION_FLT_OVERFLOW,
|
|
||||||
EXCEPTION_FLT_STACK_CHECK,
|
|
||||||
EXCEPTION_FLT_UNDERFLOW,
|
|
||||||
EXCEPTION_GUARD_PAGE,
|
|
||||||
EXCEPTION_ILLEGAL_INSTRUCTION,
|
|
||||||
EXCEPTION_INT_DIVIDE_BY_ZERO,
|
|
||||||
EXCEPTION_INT_OVERFLOW,
|
|
||||||
EXCEPTION_INVALID_DISPOSITION,
|
|
||||||
EXCEPTION_INVALID_HANDLE,
|
|
||||||
EXCEPTION_IN_PAGE_ERROR,
|
|
||||||
EXCEPTION_NONCONTINUABLE_EXCEPTION,
|
|
||||||
EXCEPTION_PRIV_INSTRUCTION,
|
|
||||||
EXCEPTION_STACK_OVERFLOW};
|
|
||||||
// NOT WORKING
|
|
||||||
LONG WINAPI exception_filter(EXCEPTION_POINTERS *exception_pointers) {
|
|
||||||
EXCEPTION_RECORD *const exception_record =
|
|
||||||
exception_pointers->ExceptionRecord;
|
|
||||||
const DWORD code = exception_record->ExceptionCode;
|
|
||||||
unsigned int i;
|
|
||||||
for (i = 0; i < 20; i++) {
|
|
||||||
if (code == EXCEPTIONS[i]) {
|
|
||||||
printf("\x1b[31mCatching Exception at %p,This testcase will be marked as "
|
|
||||||
"Runtime Error\x1b[0m\n",
|
|
||||||
exception_record->ExceptionAddress);
|
|
||||||
exception_happens = true;
|
|
||||||
return EXCEPTION_EXECUTE_HANDLER;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return EXCEPTION_CONTINUE_SEARCH;
|
|
||||||
}
|
|
||||||
FILE *memopen(const char *buf, const char *mode) {
|
|
||||||
char temppath[MAX_PATH - 13];
|
|
||||||
if (0 == GetTempPath(sizeof(temppath), temppath)) {
|
|
||||||
printf("\x1b[31mERROR:While creating tempoary file,Can't get temp "
|
|
||||||
"path\x1b[0m\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
char filename[MAX_PATH + 1];
|
|
||||||
if (0 == GetTempFileName(temppath, "TMP", 0, filename)) {
|
|
||||||
printf("\x1b[31mERROR:While creating tempoary file,Can't get file "
|
|
||||||
"name\x1b[0m\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
FILE *f;
|
|
||||||
if ((f = fopen(filename, "w+")) == NULL) {
|
|
||||||
printf("\x1b[31mERROR:While creating tempoary file,The file '%s' was not "
|
|
||||||
"opened\x1b[0m\n",
|
|
||||||
filename);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
fputs(buf, f);
|
|
||||||
fclose(f);
|
|
||||||
FILE *f2;
|
|
||||||
if ((f2 = fopen(filename, mode)) != NULL)
|
|
||||||
return f2;
|
|
||||||
else
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
#define memopen fmemopen
|
#warning not finished
|
||||||
#endif
|
#endif
|
||||||
#if defined(__APPLE__) || defined(__MACH__) || defined(BSD)
|
#if defined(__APPLE__) || defined(__MACH__) || defined(BSD)
|
||||||
#error Unsupported OS
|
#error Unsupported OS
|
||||||
|
@ -118,73 +57,33 @@ unsigned int crc32f(unsigned char *message) {
|
||||||
}
|
}
|
||||||
return ~crc;
|
return ~crc;
|
||||||
}
|
}
|
||||||
|
int a_plus_b(int a, int b) { return a + b; }
|
||||||
|
/**
|
||||||
|
TESTCASE(1) {
|
||||||
|
|
||||||
void tprintf(const char *format, ...) {
|
|
||||||
char *buffer;
|
|
||||||
va_list args;
|
|
||||||
va_start(args, format);
|
|
||||||
vsprintf(buffer, format, args);
|
|
||||||
size_t len = strlen(buffer);
|
|
||||||
memcpy(output_buffer + cur_output, buffer, sizeof(char) * len);
|
|
||||||
va_end(args);
|
|
||||||
cur_output += len;
|
|
||||||
}
|
}
|
||||||
#define tscanf(format, ...) fscanf(in, format, __VA_ARGS__)
|
subprocess:
|
||||||
void solve(FILE *);
|
if result present in time limit * 2 : print crc and time
|
||||||
unsigned int run_testcase(const char *input, unsigned int crc32,
|
if not present & still running : TLE
|
||||||
unsigned int mark) {
|
if exit != 0 : RE
|
||||||
curr_testcase++;
|
*/
|
||||||
sum_mark += mark;
|
|
||||||
unsigned int ret = mark;
|
#define BEGIN_TESTCASE switch (atoi(argv[2])) {
|
||||||
printf("\x1b[34mJudging Testcase #%d\x1b[0m\n", curr_testcase);
|
#define TESTCASE(i, x) \
|
||||||
FILE *in_fp = memopen(input, "r+");
|
case i: { \
|
||||||
if (in_fp == NULL) {
|
x; \
|
||||||
printf("\x1b[31mFATAL ERROR: Cannot Create stdin file,aborting\x1b[0m\n");
|
break; \
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
#ifdef _WIN32
|
#define END_TESTCASE \
|
||||||
prev = SetUnhandledExceptionFilter(exception_filter);
|
default: \
|
||||||
#endif
|
break; \
|
||||||
struct timespec then, now;
|
}
|
||||||
clock_gettime(CLOCK_REALTIME, &then);
|
void test() {}
|
||||||
solve(in_fp);
|
int main(int argc, const char *argv[]) {
|
||||||
clock_gettime(CLOCK_REALTIME, &now);
|
if (argc == 3) {
|
||||||
#ifdef _WIN32
|
BEGIN_TESTCASE
|
||||||
SetUnhandledExceptionFilter(prev);
|
TESTCASE(1, printf("1"))
|
||||||
prev = NULL;
|
END_TESTCASE
|
||||||
#endif
|
|
||||||
fclose(in_fp);
|
|
||||||
if ((now.tv_sec - then.tv_sec) * 1000 +
|
|
||||||
(now.tv_nsec - then.tv_nsec) / 1000000 >=
|
|
||||||
case_millseconds) {
|
|
||||||
printf("\x1b[34mTime Limit Excceed on Testcase #%d\x1b[0m\n",
|
|
||||||
curr_testcase);
|
|
||||||
ret = 0;
|
|
||||||
} else if (crc32f((unsigned char *)trim(output_buffer)) != crc32) {
|
|
||||||
printf("\x1b[31mWrong Answer on Testcase #%d\x1b[0m\n", curr_testcase);
|
|
||||||
ret = 0;
|
|
||||||
} else if (exception_happens) {
|
|
||||||
printf("\x1b[95mRuntime Error on Testcase #%d\x1b[0m\n", curr_testcase);
|
|
||||||
ret = 0;
|
|
||||||
} else {
|
} else {
|
||||||
printf("\x1b[32mAccepted on Testcase #%d\x1b[0m\n", curr_testcase);
|
|
||||||
}
|
}
|
||||||
memset((void *)output_buffer, 0, MAX_IONUM);
|
|
||||||
cur_output = 0;
|
|
||||||
exception_happens = false;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 你的代码放到这里
|
|
||||||
void solve(FILE *in) { int a = 1 / 0; }
|
|
||||||
|
|
||||||
int main(void) {
|
|
||||||
unsigned int total_get = 0;
|
|
||||||
printf("\x1b[34mStart Judging...\x1b[0m\n");
|
|
||||||
total_get += run_testcase("1 2", 1842515611, 50);
|
|
||||||
total_get += run_testcase("114514 1919810", 3586865669, 50);
|
|
||||||
|
|
||||||
printf("\x1b[34mTotal testcase %d\nTotal mark %d/%d\x1b[0m", curr_testcase,
|
|
||||||
total_get, sum_mark);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue