답안 #144947

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
144947 2019-08-18T08:55:53 Z SamAnd Raspad (COI17_raspad) C++17
26 / 100
6000 ms 2936 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 100005, M = 55;

int n, m;
char a[N][M];

vector<int> v[M];

int p[M];
int fi(int x)
{
    if (p[x] == 0)
        return 0;
    if (x == p[x])
        return x;
    return p[x] = fi(p[x]);
}
void kpc(int x, int y)
{
    x = fi(x);
    y = fi(y);
    p[x] = y;
}

long long ans;
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++i)
        scanf(" %s", a[i]);
    for (int i = 0; i < n; ++i)
    {
        long long yans = 0;
        int nb[M] = {};
        bool c[M] = {};
        for (int j = i; j < n; ++j)
        {
            for (int k = 1; k <= m; ++k)
                v[k].clear();
            for (int k = 1; k <= m; ++k)
            {
                if (j != i && a[j - 1][k - 1] == '1' && a[j][k - 1] == '1')
                {
                    v[nb[k]].push_back(k);
                }
            }
            for (int k = 1; k <= m; ++k)
            {
                if (c[k] && v[k].empty())
                    ++yans;
            }
            for (int k = 1; k <= m; ++k)
            {
                if (a[j][k - 1] == '1')
                    p[k] = k;
                else
                    p[k] = 0;
            }
            for (int k = 1; k <= m; ++k)
            {
                for (int vi = 0; vi < (int)v[k].size() - 1; ++vi)
                {
                    kpc(v[k][vi], v[k][vi + 1]);
                }
            }
            for (int k = 2; k <= m; ++k)
            {
                if (a[j][k - 1] == '1' && a[j][k - 2] == '1')
                    kpc(k, k - 1);
            }
            for (int k = 1; k <= m; ++k)
                nb[k] = fi(k);
            memset(c, false, sizeof c);
            for (int k = 1; k <= m; ++k)
                c[nb[k]] = true;
            for (int k = 1; k <= m; ++k)
            {
                if (c[k])
                    ++yans;
            }
            ans += yans;
            for (int k = 1; k <= m; ++k)
            {
                if (c[k])
                    --yans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Compilation message

raspad.cpp: In function 'int main()':
raspad.cpp:29: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:31:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf(" %s", a[i]);
         ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 15 ms 380 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 7 ms 376 KB Output is correct
5 Correct 11 ms 376 KB Output is correct
6 Correct 11 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 15 ms 380 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 7 ms 376 KB Output is correct
5 Correct 11 ms 376 KB Output is correct
6 Correct 11 ms 376 KB Output is correct
7 Correct 690 ms 408 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 1361 ms 424 KB Output is correct
10 Correct 325 ms 504 KB Output is correct
11 Correct 987 ms 472 KB Output is correct
12 Correct 308 ms 448 KB Output is correct
13 Correct 809 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6050 ms 2936 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 256 KB Output is correct
2 Correct 15 ms 380 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 7 ms 376 KB Output is correct
5 Correct 11 ms 376 KB Output is correct
6 Correct 11 ms 376 KB Output is correct
7 Correct 690 ms 408 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 1361 ms 424 KB Output is correct
10 Correct 325 ms 504 KB Output is correct
11 Correct 987 ms 472 KB Output is correct
12 Correct 308 ms 448 KB Output is correct
13 Correct 809 ms 376 KB Output is correct
14 Execution timed out 6050 ms 2936 KB Time limit exceeded
15 Halted 0 ms 0 KB -