Submission #232315

# Submission time Handle Problem Language Result Execution time Memory
232315 2020-05-16T16:28:23 Z TempoTemp Raspad (COI17_raspad) C++14
100 / 100
1546 ms 10744 KB
// Pied!
#include<bits/stdc++.h>
using namespace std;
const int N = 100005, M = 53;
int n, m, P[M * 2];
char S[N][M];
int Find(int v)
{
    return P[v] < 0 ? v : (P[v] = Find(P[v]));
}
inline bool Merge(int v, int u)
{
    v = Find(v);
    u = Find(u);
    if (v == u)
        return 0;
    if (v > u)
        swap(v, u);
    P[u] = v;
    return 1;
}
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i ++)
        scanf("%s", &S[i][1]);
    long long tot = 0;
    vector < vector < int > > A, B;
    for (int i = 1; i <= n; i ++)
    {
        int Cnt = 0;
        vector < int > R(m + 1, 0);
        for (int j = 1; j <= m; j ++)
            if (S[i][j] == '1')
                R[j] = S[i][j - 1] == '1' ? R[j - 1] : ++ Cnt;
        tot += 1LL * i * (n - i + 1) * Cnt;
        R[0] = 1;
        B.push_back(R);
        for (auto st : A)
        {
            int Cn = 0;
            memset(P, -1, sizeof(P));
            for (int j = 1; j <= m; j ++)
                if (st[j] && R[j])
                    Cn += Merge(R[j], st[j] + Cnt);
            vector < int > T(m + 1, 0);
            for (int j = 1; j <= m; j ++)
                T[j] = Find(R[j]);
            T[0] = st[0];
            B.push_back(T);
            tot -= 1LL * Cn * st[0] * (n - i + 1);
        }
        for (int h = 0; h + 1 < (int)B.size(); h ++)
        {
            bool ff = 0;
            for (int j = 1; j <= m && !ff; j ++)
                ff |= B[h][j] != B[h + 1][j];
            if (ff) continue;
            B[h][0] += B[h + 1][0];
            B.erase(B.begin() + h + 1);
        }
        A.swap(B);
        B.clear();
    }
    return !printf("%lld\n", tot);
}

Compilation message

raspad.cpp: In function 'int main()':
raspad.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
raspad.cpp:26:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s", &S[i][1]);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 7 ms 512 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 10 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 8 ms 512 KB Output is correct
12 Correct 11 ms 384 KB Output is correct
13 Correct 8 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 3712 KB Output is correct
2 Correct 92 ms 7040 KB Output is correct
3 Correct 136 ms 7060 KB Output is correct
4 Correct 51 ms 6400 KB Output is correct
5 Correct 29 ms 2304 KB Output is correct
6 Correct 97 ms 7032 KB Output is correct
7 Correct 147 ms 7168 KB Output is correct
8 Correct 72 ms 5760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 7 ms 512 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 10 ms 384 KB Output is correct
10 Correct 6 ms 384 KB Output is correct
11 Correct 8 ms 512 KB Output is correct
12 Correct 11 ms 384 KB Output is correct
13 Correct 8 ms 512 KB Output is correct
14 Correct 34 ms 3712 KB Output is correct
15 Correct 92 ms 7040 KB Output is correct
16 Correct 136 ms 7060 KB Output is correct
17 Correct 51 ms 6400 KB Output is correct
18 Correct 29 ms 2304 KB Output is correct
19 Correct 97 ms 7032 KB Output is correct
20 Correct 147 ms 7168 KB Output is correct
21 Correct 72 ms 5760 KB Output is correct
22 Correct 191 ms 7680 KB Output is correct
23 Correct 679 ms 10616 KB Output is correct
24 Correct 645 ms 10744 KB Output is correct
25 Correct 214 ms 10520 KB Output is correct
26 Correct 178 ms 10616 KB Output is correct
27 Correct 256 ms 9464 KB Output is correct
28 Correct 524 ms 9592 KB Output is correct
29 Correct 306 ms 10552 KB Output is correct
30 Correct 115 ms 10620 KB Output is correct
31 Correct 1546 ms 10592 KB Output is correct
32 Correct 788 ms 10616 KB Output is correct
33 Correct 341 ms 9464 KB Output is correct
34 Correct 416 ms 9600 KB Output is correct