-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.cpp
81 lines (76 loc) · 1.52 KB
/
sample.cpp
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
#define _CRT_SECURE_NO_WARNINGS
#include <ios>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <chrono>
#include <cstdlib>
#include <future>
#include <numeric>
#include <functional>
#include <iterator>
using namespace std;
struct Input
{
friend istream& operator >> (istream& lhs, Input& rhs)
{
return lhs;
}
};
struct Output
{
friend ostream& operator << (ostream& lhs, const Output& rhs)
{
static int case_number = 0;
return lhs << "Case #" << ++case_number << ": " << endl;
}
};
Output solve(Input input)
{
return{};
}
int main(int argc, char* argv[])
{
auto start = chrono::system_clock::now();
ios_base::sync_with_stdio(false);
ifstream fin(argv[1]);
ofstream fout(argv[2]);
int t;
fin >> t;
int ready = 0;
vector<future<Output>> tasks;
mutex cout_mutex;
for (int i = 0; i < t; ++i)
{
Input input;
fin >> input;
tasks.push_back(async([&ready, &t, &cout_mutex](Input input)
{
auto ans = solve(input);
cout_mutex.lock();
system("cls");
cout << ++ready << "/" << t << endl;
cout_mutex.unlock();
return ans;
}, input));
}
for (auto& task : tasks)
{
fout << task.get();
}
auto finish = chrono::system_clock::now();
auto elapsed = chrono::duration_cast<chrono::duration<float, std::ratio<1, 1>>>(finish - start);
cout << "Done!" << endl;
cout << "Time elapsed: " << elapsed.count() << " s" << endl;
string s;
getline(cin, s);
return 0;
}