Contest Duration: - (local time) (150 minutes) Back to Home

Submission #7860041

Source Code Expand

Copy
```#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)

int main(int argc, char** argv) {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
if (argc == 2 && atoi(argv[1]) == 123456789) {
freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
//freopen("d:\\code\\cpp\\contests\\stdout", "w", stdout);
}

string s;
cin >> s;
int k;
cin >> k;

vector<pii> v;
int cnt = 1;
const int n = s.size();
for(int i=1; i<n; i++){
if (s[i] == s[i-1]){
cnt++;
}
else{
v.push_back(make_pair(s[i-1], cnt));
cnt = 1;
}
}
v.push_back(make_pair(s.back(), cnt));

map<int, int> H;
if (s[0] != s.back()){
for(auto it : v)
H[it.second]+=k;
}
else{
if (v.size() == 1){
cout << ((ll)k) * s.size() / 2 << endl;
return 0;
}
H[v[0].second] += 1;
H[v.back().second] += 1;
H[v[0].second + v.back().second] += k-1;
for(int i=1; i+1<v.size(); i++)
H[v[i].second] += k;
}

ll sol = 0;
for(auto it : H)
sol += (ll)it.first / 2 * it.second;
cout << sol << endl;

if (argc == 2 && atoi(argv[1]) == 123456789)        cerr << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
return 0;
}```

#### Submission Info

Submission Time 2019-10-05 21:14:43+0900 A - Connection and Disconnection robertv C++14 (GCC 5.4.1) 300 1606 Byte AC 1 ms 256 KB

#### Compile Error

```./Main.cpp: In function ‘int main(int, char**)’:
./Main.cpp:13:62: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
^
```

#### Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
 AC × 3
 AC × 15
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 1 ms 256 KB
02.txt AC 1 ms 256 KB
03.txt AC 1 ms 256 KB
04.txt AC 1 ms 256 KB
05.txt AC 1 ms 256 KB
06.txt AC 1 ms 256 KB
07.txt AC 1 ms 256 KB
08.txt AC 1 ms 256 KB
09.txt AC 1 ms 256 KB
10.txt AC 1 ms 256 KB
11.txt AC 1 ms 256 KB
12.txt AC 1 ms 256 KB
s1.txt AC 1 ms 256 KB
s2.txt AC 1 ms 256 KB
s3.txt AC 1 ms 256 KB