TLE,求调 QAQ
查看原帖
TLE,求调 QAQ
1384613
lluuonone_sr楼主2024/11/19 22:05

这个代码超时是为什么呀?

第一个,第二个和第九个,第十个测试点超时了。。。T_T

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e5+5;

ll n;

void pg (ll x)
{
	if (x < 2)
	{
		printf ("-1");
		return;
	}
	
	if (x == 2) {printf ("1");return;}
	if (x == 5) {printf ("2");return;}
	if (x == 4) {printf ("4");return;}
	if (x == 6) {printf ("6");return;}
	if (x == 3) {printf ("7");return;}
	if (x == 7) {printf ("8");return;}

    if (x % 7 == 0)
    {
        for (ll i = 1; i <= x/7; i++)
        {
            printf ("8");
        }printf ("\n");
        return ;
    }

    if (x % 7 == 1)
    {
        printf ("10");
        for (ll i = 1; i <= (x-8)/7; i++)
        {
            printf ("8");
        }printf ("\n");
        return ;
    }if (x % 7 == 2)
    {
        printf ("18");
        for (ll i = 1; i < i <= (x-9)/7; i++)
        {
            printf ("8");
        }printf ("\n");
        return ;
    }if (x % 7 == 3)
    {
        if (x == 10) {printf ("22"); return ;}
        if (x == 17) {printf ("20"); return ;}
        cout << 200;
        for (ll i = 1; i <= (x-17)/7; i++)
        {
            printf ("8");
        }printf ("\n");
        return ;
    }if (x % 7 == 4)
    {
        printf ("20");
        for (ll i = 1; i <= (x-11)/7; i++)
        {
            printf ("8");
        }printf ("\n");
        return ;
    }if (x % 7 == 5)
    {
        printf ("28");
        for (ll i = 1; i <= (x-12)/7; i++)
        {
            printf ("8");
        }printf ("\n");
        return ;
    }if (x % 7 == 6)
    {
        printf ("68");
        for (ll i = 1; i <= (x-13)/7; i++)
        {
            printf ("8");
        }printf ("\n");
        return ;
    }
}

int main()
{
	cin >> n;
	
	ll a;
	while (n--)
    {
        scanf ("%lld", &a);
		pg (a);
    }
    
	return 0;
}

2024/11/19 22:05
加载中...