Submission #255676

# Submission time Handle Problem Language Result Execution time Memory
255676 2020-08-01T14:12:22 Z sonvip9 Trobojnica (COCI19_trobojnica) C++14
20 / 110
19 ms 384 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ii pair <int,int>
#define pl pair <ll,ll>
#define fr(i,x,y) for (int i=x;i<=y;i++)
#define ft(i,x,y) for (int i=y;i>=x;i--)
#define N 100005
using namespace std ;
int n,color[12][12],first_color[12][12];
string s;
void inp()
{
   // freopen("task2.inp","r",stdin) ;
   // freopen("task2.out","w",stdout);
    cin>>n>>s;
}
bool hs(int u,int v)
{
    if (u>v) swap(u,v);
    if (u==1 and v==n) return true ;
    return false;
}
bool check()
{
    fr(i,1,n)
    {
        fr(j,i+1,n)
           fr(k,j+1,n)
            {
                if (color[i][j]!=0 and color[i][k]!=0 and color[k][j]!=0)
                    if (color[i][j]==color[i][k] or color[i][j]==color[j][k] or color[k][j]==color[i][k]) return false ;
            }
    }
    int dem = 0 ;
    fr(i,1,n)
    {
        fr(j,i+2,n)
        {
            if (hs(i,j)) continue ;
            if (color[i][j]!=0) dem++;
        }
    }
    if (dem!=n-3) return false ;
    return true ;
}
void duyet(int st,int ed)
{
    if (st>ed) swap(st,ed);
    if (ed-st==2)
    {
        if (check())
        {
            cout<<"DA"<<"\n";
            fr(i,1,n)
            {
                fr(j,i+2,n)
                {
                    if (color[i][j]!=0)
                    {
                        if (hs(i,j)) continue ;
                        cout<<i<<" "<<j<<" "<<color[i][j]<<"\n";
                    }
                }
            }
            exit(0);
        }
        return ;
    }
    fr(i,st+1,ed-1)
    {
        fr(now_color,1,3)
        {
            if (now_color!=color[st][ed])
            {
                if (color[st][i]==0) color[st][i] = color[i][st] = 6 - now_color - color[st][ed];
                if (color[ed][i]==0) color[ed][i] = color[i][ed] = now_color ;
                duyet(st,i);
                duyet(ed,i);
                color[i][st] = color[st][i] = first_color[st][i];
                color[i][ed] = color[ed][i] = first_color[ed][i];
            }
        }
    }
}
void sub1()
{
    fr(i,0,n-1)
    {
        if (i!=n-1)
        {
            color[i+1][i+2] = color[i+2][i+1] = s[i]-'0';
        }
        else color[1][n] = color[n][1] = s[i]-'0';
    }
    fr(i,1,n)
      fr(j,1,n)
         first_color[i][j] = color[i][j];
    duyet(n,1);
    cout<<"NE";
}
int main()
{
    inp();
    sub1();
}

# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 19 ms 256 KB Output is correct
5 Correct 7 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 12 ms 256 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 19 ms 256 KB Output is correct
5 Correct 7 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 12 ms 256 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 6 ms 256 KB Output is correct
12 Runtime error 1 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 19 ms 256 KB Output is correct
5 Correct 7 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 12 ms 256 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 6 ms 256 KB Output is correct
12 Runtime error 1 ms 384 KB Execution killed with signal 11 (could be triggered by violating memory limits)
13 Halted 0 ms 0 KB -