QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#64600#1806. Character GridNipunbaishnabAC ✓3ms3388kbC++144.2kb2022-11-25 01:23:122022-11-25 01:23:15

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-11-25 01:23:15]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3388kb
  • [2022-11-25 01:23:12]
  • 提交

answer

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#include <iostream>
#define   MP             make_pair
#define   PB             push_back
#define   nn             '\n'
#define   endl           '\n'
#define   IOS            ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define   UNIQUE(vec)    vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end()))) ;
#define   all(vec)       vec.begin(),vec.end()
#define   int            long long
#define   pii            pair<int,int>
#define   pdd            pair<double,double>

using namespace std ;

typedef long long LL ;

const int MOD=1e9+7,Base=998244353 ;
const int N=1e6+7 ;
const int oo=1LL*1000*1000*1000*1000*1000*1000+7LL ;
const double pie=acos(-1.0) ;
const double EPS=1e-9 ;

int test, n, a[N], b ;

char g[20][20] ;

set<string>e ;

set<string>dup ;

bool col(int c,int j,int mode=0)
{
    string s="", r ;
    s.push_back(g[j][c]) ;
    for(int i=j-1; i>=1; --i)
    {
        s.push_back(g[i][c]) ;
        r = s ;
        reverse(all(r)) ;
        if(mode==1)
            e.insert(r) ;
        else
            dup.insert(r) ;
        if(e.count(r) and mode==0)
            return false ;
    }
    return true ;
}

bool row(int r,int j,int mode=0)
{
    string s="", rw ;
    s.push_back(g[r][j]) ;
    for(int i=j-1; i>=1; --i)
    {
        s.push_back(g[r][i]) ;
        rw = s ;
        reverse(all(rw)) ;
        if(mode==1)
            e.insert(rw) ;
        if((e.count(rw) or dup.count(rw)) and mode==0)
            return false ;
        //cout<<rw<<" pass "<<endl ;
    }
    return true ;
}

void build(int n)
{
    g[1][1]='a' ;

    for(int c=2; c<=n; ++c)
    {
        if(c<=7)
        {
            for(int j=1; j<c; ++j)
            {
                for(char ch='z'; ch>='a'; --ch)
                {
                    g[j][c]=ch ;
                    dup.clear() ;
                    if(col(c,j))
                    {
                        if(row(j,c))
                        {
                            col(c,j,1) ;
                            row(j,c,1) ;
                            break ;
                        }
                    }
                }
            }

            for(int j=1; j<=c; ++j)
            {
                for(char ch='z'; ch>='a'; --ch)
                {
                    g[c][j]=ch ;
                    dup.clear() ;
                    if(col(j,c))
                    {
                        if(row(c,j))
                        {
                            row(c,j,1) ;
                            col(j,c,1) ;
                            break ;
                        }
                    }
                }
            }
        }
        else
        {
            for(int j=1; j<c; ++j)
            {
                for(char ch='a'; ch<='z'; ++ch)
                {
                    g[j][c]=ch ;
                    dup.clear() ;
                    if(col(c,j))
                    {
                        if(row(j,c))
                        {
                            col(c,j,1) ;
                            row(j,c,1) ;
                            break ;
                        }
                    }
                }
            }

            for(int j=1; j<=c; ++j)
            {
                for(char ch='a'; ch<='z'; ++ch)
                {
                    g[c][j]=ch ;
                    dup.clear() ;
                    if(col(j,c))
                    {
                        if(row(c,j))
                        {
                            row(c,j,1) ;
                            col(j,c,1) ;
                            break ;
                        }
                    }
                }
            }
        }
    }

    //cout<<e.size()<<endl ;
}

int32_t main()
{
    IOS

    build(13) ;

    cout<<13<<endl ;

    for(int i=1; i<=13; ++i)
    {
        for(int j=1; j<=13; ++j)
        {
            cout<<g[i][j] ;
        }
        cout<<endl ;
    }

    return 0 ;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 3388kb

input:



output:

13
azyvzvwafameo
yzxyrxxagkdkg
ywzuynwbbeffm
tyszqyjahandl
zpyozmycelcsf
txlykziaibocv
wvvhygzdckatd
cbccdaebfcpav
gdhidjcjbldre
cmbgednemaodp
qcrfegghfqbie
auasjijglenfr
wdxbphhnhqiik

result:

ok accepted