#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <cstdlib>
#include <chrono>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <cassert>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
struct TestData;
void solve(TestData& t);
void io_solve(TestData& t, FILE* input, FILE* output);
void test();
#if _WIN32
# define DO_TESTS 1
# if DO_TESTS
# define DO_LOGS 1
# else
# define DO_LOGS 0
# endif
#else
# define DO_LOGS 0
# define DO_TESTS 0
#endif
#if DO_LOGS
auto time_start = std::chrono::high_resolution_clock::now();
# define DEB(...) do { \
auto duration_from_start = std::chrono::high_resolution_clock::now() - time_start; \
auto micros = std::chrono::duration_cast<std::chrono::microseconds>(duration_from_start).count(); \
fprintf(stderr, "# %lld.%06lld ", micros/1000000, micros%1000000); \
fprintf(stderr, __VA_ARGS__); \
fputc('\n', stderr); \
} while (0)
#else
# define DEB(...) do {} while (0);
#endif
struct TestData {
int x, d, h, m;
int64_t result;
TestData() {}
};
int main() {
#if DO_TESTS
test();
#else
FILE* input = stdin;
FILE* output = stdout;
#if _WIN32
const char *file = nullptr;
//file = "in/r3d-x_1_tak.txt";
if (file != nullptr) input = fopen(file, "r");
if (input == NULL) {
input = stdin;
} else {
# if 0
std::string out_file = file;
out_file += "_out.log";
output = fopen(out_file.c_str(), "w");
# endif
}
#endif
TestData t;
io_solve(t, input, output);
#endif
return 0;
}
void solve(TestData& t);
#if DO_TESTS
void test_files() {
std::vector<std::string> files = {
"in/zmi0.in",
"in/zmi1.in",
};
for (int i = 0; i < files.size(); ++i) {
DEB("test %d %s", i, files[i].c_str());
FILE* file = fopen(files[i].c_str(), "r");
if (file == nullptr) {
DEB("can not open %s", files[i].c_str());
return;
}
//FILE* outfile = fopen("out.out", "w");
FILE* outfile = stdout;
TestData t;
io_solve(t, file, outfile);
fclose(file);
if (outfile != stdout) fclose(outfile);
std::string check_out = files[i];
check_out[check_out.size()-2] = 'o';
check_out[check_out.size()-1] = 'u';
check_out += 't';
FILE* expect_file = fopen(check_out.c_str(), "r");
if (expect_file == nullptr) {
DEB("test %d. can not open %s\n", i, check_out.c_str());
} else {
DEB("test %d. Expects", i);
char buf[8*1024];
for (int lines = 0; lines < 3; ++lines) {
fgets(buf, sizeof(buf) -1, expect_file);
buf[sizeof(buf) -1] = 0;
char* end = strchr(buf, '\n');
if (end != nullptr) *end = '\0';
DEB("%s", buf);
}
fclose(expect_file);
}
}
DEB("test_files done %d", (int) files.size());
}
void test() {
test_files();
/*
std::vector<TestData> tests;
for(int i = 0; i < tests.size(); ++i)
{
auto& t = tests[i];
DEB("test %d %d", i, t.m);
solve(t);
if (t.expected != t.result) {
DEB("test %d: t.expected %d != %d t.result", i, t.expected, t.result);
continue;
}
DEB("test %d done %d", i, t.result);
}*/
}
#endif
void io_solve(TestData& t, FILE *input, FILE *output) {
//DEB("io_solve");
fscanf(input, "%d %d %d %d\n", &t.x, &t.d, &t.h, &t.m);
solve(t);
fprintf(output, "%lld\n", t.result);
}
void solve(TestData& t) {
//day 1 23
//double day round
DEB("%d %d %d", t.d, t.h, t.m);
//time shit is at d 29 h 2
int64_t minute_break = ((29)*24 + 2)*60;
int64_t minute_start = ((t.d)*24 + t.h)*60 + t.m;
//day end for x1 is 24 hour 23 minute 59
int64_t day_end = t.x + 23;
//on round 5 wwe have one more day
if (t.x >= 5) day_end += 1;
int64_t minute_end = ((day_end)*24 + 23)*60 + 59;
DEB("%lld %d %d", day_end, 23, 59);
//shift one hour
if (minute_start >= minute_break) minute_start -= 60;
if (minute_end >= minute_break) minute_end -= 60;
t.result = minute_end - minute_start + 1;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | #include <stdint.h> #include <stdio.h> #include <string.h> #include <vector> #include <cstdlib> #include <chrono> #include <map> #include <unordered_set> #include <unordered_map> #include <cassert> #include <queue> #include <algorithm> #include <string> #include <cmath> struct TestData; void solve(TestData& t); void io_solve(TestData& t, FILE* input, FILE* output); void test(); #if _WIN32 # define DO_TESTS 1 # if DO_TESTS # define DO_LOGS 1 # else # define DO_LOGS 0 # endif #else # define DO_LOGS 0 # define DO_TESTS 0 #endif #if DO_LOGS auto time_start = std::chrono::high_resolution_clock::now(); # define DEB(...) do { \ auto duration_from_start = std::chrono::high_resolution_clock::now() - time_start; \ auto micros = std::chrono::duration_cast<std::chrono::microseconds>(duration_from_start).count(); \ fprintf(stderr, "# %lld.%06lld ", micros/1000000, micros%1000000); \ fprintf(stderr, __VA_ARGS__); \ fputc('\n', stderr); \ } while (0) #else # define DEB(...) do {} while (0); #endif struct TestData { int x, d, h, m; int64_t result; TestData() {} }; int main() { #if DO_TESTS test(); #else FILE* input = stdin; FILE* output = stdout; #if _WIN32 const char *file = nullptr; //file = "in/r3d-x_1_tak.txt"; if (file != nullptr) input = fopen(file, "r"); if (input == NULL) { input = stdin; } else { # if 0 std::string out_file = file; out_file += "_out.log"; output = fopen(out_file.c_str(), "w"); # endif } #endif TestData t; io_solve(t, input, output); #endif return 0; } void solve(TestData& t); #if DO_TESTS void test_files() { std::vector<std::string> files = { "in/zmi0.in", "in/zmi1.in", }; for (int i = 0; i < files.size(); ++i) { DEB("test %d %s", i, files[i].c_str()); FILE* file = fopen(files[i].c_str(), "r"); if (file == nullptr) { DEB("can not open %s", files[i].c_str()); return; } //FILE* outfile = fopen("out.out", "w"); FILE* outfile = stdout; TestData t; io_solve(t, file, outfile); fclose(file); if (outfile != stdout) fclose(outfile); std::string check_out = files[i]; check_out[check_out.size()-2] = 'o'; check_out[check_out.size()-1] = 'u'; check_out += 't'; FILE* expect_file = fopen(check_out.c_str(), "r"); if (expect_file == nullptr) { DEB("test %d. can not open %s\n", i, check_out.c_str()); } else { DEB("test %d. Expects", i); char buf[8*1024]; for (int lines = 0; lines < 3; ++lines) { fgets(buf, sizeof(buf) -1, expect_file); buf[sizeof(buf) -1] = 0; char* end = strchr(buf, '\n'); if (end != nullptr) *end = '\0'; DEB("%s", buf); } fclose(expect_file); } } DEB("test_files done %d", (int) files.size()); } void test() { test_files(); /* std::vector<TestData> tests; for(int i = 0; i < tests.size(); ++i) { auto& t = tests[i]; DEB("test %d %d", i, t.m); solve(t); if (t.expected != t.result) { DEB("test %d: t.expected %d != %d t.result", i, t.expected, t.result); continue; } DEB("test %d done %d", i, t.result); }*/ } #endif void io_solve(TestData& t, FILE *input, FILE *output) { //DEB("io_solve"); fscanf(input, "%d %d %d %d\n", &t.x, &t.d, &t.h, &t.m); solve(t); fprintf(output, "%lld\n", t.result); } void solve(TestData& t) { //day 1 23 //double day round DEB("%d %d %d", t.d, t.h, t.m); //time shit is at d 29 h 2 int64_t minute_break = ((29)*24 + 2)*60; int64_t minute_start = ((t.d)*24 + t.h)*60 + t.m; //day end for x1 is 24 hour 23 minute 59 int64_t day_end = t.x + 23; //on round 5 wwe have one more day if (t.x >= 5) day_end += 1; int64_t minute_end = ((day_end)*24 + 23)*60 + 59; DEB("%lld %d %d", day_end, 23, 59); //shift one hour if (minute_start >= minute_break) minute_start -= 60; if (minute_end >= minute_break) minute_end -= 60; t.result = minute_end - minute_start + 1; } |
English