-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathday7.cpp
64 lines (60 loc) · 1.03 KB
/
day7.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
#include <bits/stdc++.h>
#define endl '\n'
#define eat cin
#define moo cout
#define int long long
using namespace std;
string S;
int ans = 0;
map<string, int> sz;
vector<string> cur;
void solve(){
if(S[0] == '$'){
S = S.substr(2);
if(S[0] == 'c'){
S = S.substr(3);
if(S == ".."){
cur.pop_back();
}else{
cur.push_back(S);
}
}
}else{
if(S[0] != 'd'){
int n = 0;
for(int i = 0; i < S.length(); i++){
if(!isdigit(S[i]))break;
n = n * 10;
n += (S[i] - '0');
//n = min(n, 100001LL);
}
string cz;
for(int i = 0; i < cur.size(); i++){
cz += cur[i];
sz[cz] += n;
}
}
}
}
int32_t main(){
eat.tie(0) -> sync_with_stdio(0);
cur.push_back("/");
while(getline(cin, S)){
if(S.size() == 0) break;
solve();
}
int rem = sz["/"] - 40000000;
int mn = 1e15;
for(pair<string, int> i : sz){
if(i.second <= 100000){
ans += i.second;
}
if(i.second < mn && i.second >= rem){
mn = i.second;
}
}
moo << ans << endl;
moo << mn << endl;
// solve();
//moo << sum << endl;
}