Submission #257963

# Submission time Handle Problem Language Result Execution time Memory
257963 2020-08-05T06:30:57 Z 문홍윤(#5065) Toilets (JOI16_toilets) C++17
100 / 100
52 ms 7416 KB
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define svec(x) sort(x.begin(), x.end())
#define press(x) x.erase(unique(x.begin(), x.end()), x.end())
#define lb(x, v) lower_bound(x.begin(), x.end(), v)
#define ub(x, v) upper_bound(x.begin(), x.end(), v)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
const LL llinf=2000000000000000000;
const LL mod1=1000000007;
const LL mod2=998244353;
const int inf=2000000000;

int m;
LL n, len[100010], lsum[100010], cnt[100010], sum[100010], rpt[100010], ans;
string str[100010];

int main(){
    scanf("%lld %d", &n, &m);
    for(int i=1; i<=m; i++){
        cin>>str[i];
        scanf("%lld", &rpt[i]);
        len[i]=(LL)str[i].size();
        for(int j=0; j<str[i].size(); j++){
            if(str[i][j]=='F')cnt[i]++;
        }
        sum[i]=sum[i-1]+cnt[i]*rpt[i];
        lsum[i]=lsum[i-1]+len[i]*rpt[i];
    }
    if(sum[m]<n)return !printf("-1");
    LL num=sum[m]-n;
    for(int i=1; i<=m; i++){
        LL temp=sum[i-1];
        for(int j=0; j<str[i].size(); j++){
            LL nw=lsum[i-1]+j;
            if(str[i][j]=='F'){
                ans=max(ans, 2*(temp-num)-nw);
                temp++;
            }
        }
        temp=sum[i-1]+cnt[i]*(rpt[i]-1);
        for(int j=0; j<str[i].size(); j++){
            LL nw=lsum[i-1]+len[i]*(rpt[i]-1)+j;
            if(str[i][j]=='F'){
                ans=max(ans, 2*(temp-num)-nw);
                temp++;
            }
        }
    }
    printf("%lld", ans);
}

Compilation message

toilets.cpp: In function 'int main()':
toilets.cpp:32:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0; j<str[i].size(); j++){
                      ~^~~~~~~~~~~~~~
toilets.cpp:42:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0; j<str[i].size(); j++){
                      ~^~~~~~~~~~~~~~
toilets.cpp:50:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0; j<str[i].size(); j++){
                      ~^~~~~~~~~~~~~~
toilets.cpp:27:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld %d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~~~~
toilets.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &rpt[i]);
         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 2 ms 3456 KB Output is correct
3 Correct 3 ms 3456 KB Output is correct
4 Correct 2 ms 3456 KB Output is correct
5 Correct 3 ms 3456 KB Output is correct
6 Correct 3 ms 3456 KB Output is correct
7 Correct 3 ms 3456 KB Output is correct
8 Correct 3 ms 3456 KB Output is correct
9 Correct 3 ms 3456 KB Output is correct
10 Correct 2 ms 3456 KB Output is correct
11 Correct 3 ms 3456 KB Output is correct
12 Correct 3 ms 3584 KB Output is correct
13 Correct 2 ms 3456 KB Output is correct
14 Correct 3 ms 3456 KB Output is correct
15 Correct 2 ms 3456 KB Output is correct
16 Correct 2 ms 3456 KB Output is correct
17 Correct 3 ms 3456 KB Output is correct
18 Correct 3 ms 3456 KB Output is correct
19 Correct 3 ms 3456 KB Output is correct
20 Correct 3 ms 3456 KB Output is correct
21 Correct 3 ms 3456 KB Output is correct
22 Correct 2 ms 3456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 2 ms 3456 KB Output is correct
3 Correct 3 ms 3456 KB Output is correct
4 Correct 2 ms 3456 KB Output is correct
5 Correct 3 ms 3456 KB Output is correct
6 Correct 3 ms 3456 KB Output is correct
7 Correct 3 ms 3456 KB Output is correct
8 Correct 3 ms 3456 KB Output is correct
9 Correct 3 ms 3456 KB Output is correct
10 Correct 2 ms 3456 KB Output is correct
11 Correct 3 ms 3456 KB Output is correct
12 Correct 3 ms 3584 KB Output is correct
13 Correct 2 ms 3456 KB Output is correct
14 Correct 3 ms 3456 KB Output is correct
15 Correct 2 ms 3456 KB Output is correct
16 Correct 2 ms 3456 KB Output is correct
17 Correct 3 ms 3456 KB Output is correct
18 Correct 3 ms 3456 KB Output is correct
19 Correct 3 ms 3456 KB Output is correct
20 Correct 3 ms 3456 KB Output is correct
21 Correct 3 ms 3456 KB Output is correct
22 Correct 2 ms 3456 KB Output is correct
23 Correct 14 ms 3856 KB Output is correct
24 Correct 15 ms 3856 KB Output is correct
25 Correct 15 ms 3856 KB Output is correct
26 Correct 12 ms 3856 KB Output is correct
27 Correct 12 ms 3876 KB Output is correct
28 Correct 15 ms 3856 KB Output is correct
29 Correct 15 ms 3856 KB Output is correct
30 Correct 15 ms 3856 KB Output is correct
31 Correct 15 ms 3856 KB Output is correct
32 Correct 15 ms 3856 KB Output is correct
33 Correct 12 ms 3856 KB Output is correct
34 Correct 13 ms 3856 KB Output is correct
35 Correct 15 ms 3856 KB Output is correct
36 Correct 15 ms 3856 KB Output is correct
37 Correct 12 ms 3856 KB Output is correct
38 Correct 13 ms 3856 KB Output is correct
39 Correct 14 ms 3856 KB Output is correct
40 Correct 15 ms 3856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 2 ms 3456 KB Output is correct
3 Correct 3 ms 3456 KB Output is correct
4 Correct 2 ms 3456 KB Output is correct
5 Correct 3 ms 3456 KB Output is correct
6 Correct 3 ms 3456 KB Output is correct
7 Correct 3 ms 3456 KB Output is correct
8 Correct 3 ms 3456 KB Output is correct
9 Correct 3 ms 3456 KB Output is correct
10 Correct 2 ms 3456 KB Output is correct
11 Correct 3 ms 3456 KB Output is correct
12 Correct 3 ms 3584 KB Output is correct
13 Correct 2 ms 3456 KB Output is correct
14 Correct 3 ms 3456 KB Output is correct
15 Correct 2 ms 3456 KB Output is correct
16 Correct 2 ms 3456 KB Output is correct
17 Correct 3 ms 3456 KB Output is correct
18 Correct 3 ms 3456 KB Output is correct
19 Correct 3 ms 3456 KB Output is correct
20 Correct 3 ms 3456 KB Output is correct
21 Correct 3 ms 3456 KB Output is correct
22 Correct 2 ms 3456 KB Output is correct
23 Correct 14 ms 3856 KB Output is correct
24 Correct 15 ms 3856 KB Output is correct
25 Correct 15 ms 3856 KB Output is correct
26 Correct 12 ms 3856 KB Output is correct
27 Correct 12 ms 3876 KB Output is correct
28 Correct 15 ms 3856 KB Output is correct
29 Correct 15 ms 3856 KB Output is correct
30 Correct 15 ms 3856 KB Output is correct
31 Correct 15 ms 3856 KB Output is correct
32 Correct 15 ms 3856 KB Output is correct
33 Correct 12 ms 3856 KB Output is correct
34 Correct 13 ms 3856 KB Output is correct
35 Correct 15 ms 3856 KB Output is correct
36 Correct 15 ms 3856 KB Output is correct
37 Correct 12 ms 3856 KB Output is correct
38 Correct 13 ms 3856 KB Output is correct
39 Correct 14 ms 3856 KB Output is correct
40 Correct 15 ms 3856 KB Output is correct
41 Correct 52 ms 7416 KB Output is correct
42 Correct 51 ms 7288 KB Output is correct
43 Correct 3 ms 3456 KB Output is correct
44 Correct 2 ms 3456 KB Output is correct
45 Correct 2 ms 3456 KB Output is correct
46 Correct 22 ms 4224 KB Output is correct
47 Correct 15 ms 3840 KB Output is correct
48 Correct 16 ms 3712 KB Output is correct
49 Correct 14 ms 3840 KB Output is correct
50 Correct 14 ms 3840 KB Output is correct
51 Correct 20 ms 4352 KB Output is correct
52 Correct 51 ms 7416 KB Output is correct
53 Correct 49 ms 7396 KB Output is correct
54 Correct 45 ms 7288 KB Output is correct
55 Correct 13 ms 3840 KB Output is correct
56 Correct 14 ms 3840 KB Output is correct