QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#325555#4833. Tetra-puzzletuanlinh123Compile Error//C++204.9kb2024-02-11 16:50:062024-02-11 16:50:07

Judging History

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

  • [2024-02-11 16:50:07]
  • 评测
  • [2024-02-11 16:50:06]
  • 提交

answer

#include<bits/stdc++.h>
#define ll int
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
using namespace std;
inline ll IDX(ll i, ll j) {return i*5+j;}
inline bool BIT(ll mask, ll i, ll j) {return (mask&1<<IDX(i, j))!=0;}

struct piece
{
    ll val=0, h=0, w=0;
    piece(){}
    piece(char s)
    {
        vector <vector <bool>> a(5, vector <bool> (5, 0));
        if (s=='I') a[0][0]=a[1][0]=a[2][0]=a[3][0]=1, h=4, w=1;
        if (s=='L') a[0][0]=a[1][0]=a[2][0]=a[2][1]=1, h=3, w=2;
        if (s=='O') a[0][0]=a[0][1]=a[1][0]=a[1][1]=1, h=w=2;
        if (s=='T') a[0][0]=a[0][1]=a[0][2]=a[1][1]=1, h=2, w=3;
        if (s=='Z') a[0][0]=a[0][1]=a[1][1]=a[1][2]=1, h=2, w=3;
        for (ll i=0; i<5; i++)
            for (ll j=0; j<5; j++)
                if (a[i][j]) val|=1<<IDX(i, j);
    }

    inline void fdiag()
    {
        ll res=0;
        for (ll i=0; i<5; i++)
            for (ll j=0; j<5; j++)
                if (BIT(val, i, j))
                    res|=1<<IDX(j, i);
        val=res, swap(h, w);
    }
    inline void fhori()
    {
        ll res=0;
        for (ll i=0; i<5; i++)
            for (ll j=0; j<5; j++)
                if (BIT(val, i, j))
                    res|=1<<IDX(4-i, j);
        val=res;
    }
    inline void rotate()
    {
        fdiag();
        fhori();
    }
    inline void fix()
    {
        while (1)
        {
            bool ok=1;
            for (ll i=0; i<5; i++)
                if (BIT(val, 0, i))
                    {ok=0; break;}
            if (!ok) break;
            val>>=5;
        }
        while (1)
        {
            bool ok=1;
            for (ll i=0; i<5; i++)
                if (BIT(val, i, 0))
                    {ok=0; break;}
            if (!ok) break;
            val>>=1;
        }
    }

    void print()
    {
        cout << h << " " << w << "\n";
        for (ll i=0; i<5; i++)
            for (ll j=0; j<5; j++)
                cout << BIT(val, i, j) << " \n"[j==4];
    }
};

const ll all=(1<<25)-1;
vector <piece> I, L, O, T, Z;
vector <ll> t[26];
ll hori[5], veri[5];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    for (ll i=0; i<5; i++)
        for (ll j=0; j<5; j++)
        {
            hori[i]|=1<<IDX(i, j);
            veri[j]|=1<<IDX(i, j);
        }
    auto init=[&](vector <piece> &a, char s)
    {
        a.resize(8), a[0]=piece(s);
        for (ll i=1; i<8; i++)
        {
            if (i<4) a[i]=a[i-1], a[i].rotate();
            else a[i]=a[i-4], a[i].fhori();
            a[i].fix();
        }
        map <ll, bool> Map;
        for (ll i=0; i<8; i++) for (ll j=0; j<=5-a[i].h; j++) for (ll k=0; k<=5-a[i].w; k++)
        {
            ll val=a[i].val<<IDX(j, k);
            if (!Map[val]) Map[val]=1, t[s-'A'].pb(val);
        }
    }; init(I, 'I'), init(L, 'L'), init(O, 'O'), init(T, 'T'), init(Z, 'Z');
    string type; cin >> type;
    if (type=="prepare")
    {
        ll n, cr=0; cin >> n;
        for (ll i=0; i<n; i++)
        {
            string s; cin >> s;
            pll best[2]; best[0]=best[1]={100, 0};
            for (ll j=0; j<2; j++)
            {
                ll c=s[j]-'A';
                for (ll move:t[c]) if (!(cr&move))
                {
                    ll ne=cr|move, re=0;
                    for (ll k=0; k<5; k++)
                    {
                        if ((ne|hori[k])==ne) 
                            re|=hori[k];
                        if ((ne|veri[k])==ne) 
                            re|=veri[k];
                    }
                    best[j]=min(best[j], {__builtin_popcount(ne^re), ne^re});
                }
            }
            if (best[0].fi<best[1].fi)
                cout << s[0], cr=best[0].se;
            else cout << s[1], cr=best[1].se;
        }
    }
    else
    {
        ll n, cr=0; cin >> n;
        for (ll i=0; i<n; i++)
        {
            char c; cin >> c; c-='A';
            pair<ll, pll> best; best.fi=100;
            for (ll move:t[c]) if (!(cr&move))
            {
                ll ne=cr|move, re=0;
                for (ll k=0; k<5; k++)
                {
                    if ((ne|hori[k])==ne) 
                        re|=hori[k];
                    if ((ne|veri[k])==ne) 
                        re|=veri[k];
                }
                best=min(best, {__builtin_popcount(ne^re), {ne^re, move}});
            }
            if (best.fi==100) return;
            ll move=best.se.se, ne=best.se.fi;
            for (ll i=0; i<5; i++) for (ll j=0; j<5; j++)
            {
                if (BIT(cr, i, j)) cout << '#';
                else if (BIT(move, i, j)) cout << '*';
                else cout << '.'; if (j==4) cout << endl;
            }
            cr=ne;
        }
    }
}

详细

answer.code: In function ‘int main()’:
answer.code:163:31: error: return-statement with no value, in function returning ‘int’ [-fpermissive]
  163 |             if (best.fi==100) return;
      |                               ^~~~~~