大佬帮看一下,题目显示超过时间限制怎么回事

P1319 压缩技术

qew12312 @ 2023-01-05 22:24:31

#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int n,sum=0,sum1=0,y,u;
    cin>>n;
    int a[1000];
    for(int y=1;sum<n*n;y++)
    {
    cout<<a[y];
    sum+=a[y];}
    for(int t=1;t<=y;t++){
        for(u=1;u<=a[t];u++){sum1+=u;
            if(t%2!=0) cout<<"0";
            else cout<<"1";
            if(sum1%7==0) cout<<endl;
        }
    }
        return 0;
}

by _DeaDFish_ @ 2023-01-06 11:39:34

下次自己调试一下好不好示例都过不去

#include<iostream>
#include<cmath>
using namespace std;
int main(){
    int n,sum=0,sum1=0,o=0,j=0;
    cin>>n;
    int a;
    for(int y=1;sum<n*n;y++)
    {
        cin>>a;
        sum+=a;
        if(o%2!=0)
        {
            for(int i = 0;i<a;i++,j++)
            {
                if(j==n)
                {
                    j=0;
                    cout<<endl;
                }
                cout<<1;
            }
        }
        else
        {
            for(int i = 0;i<a;i++,j++)
            {
                if(j==n)
                 {
                    j=0;
                    cout<<endl;
                }
                cout<<0;
            }
        }
        o++;
    }
        return 0;
}

|