全TLE求助

P1319 压缩技术

azure000 @ 2023-02-08 19:44:25

#include<bits/stdc++.h>
using namespace std;
int n,a=0,s=0,t=0,tot=0;
int main(){
    cin>>n;
    while(a=n*n){
        cin>>s;
        a+=s;
        if(t==0){
            for(int i=1;i<=s;++i){
                cout<<"0";
                tot++;
                if(tot%n==0)cout<<"\n"; 
            }
            t++;
        }
        else{
            for(int i=1;i<=s;++i){
                cout<<"1";
                tot++;
                if(tot%n==0)cout<<"\n";
            }
            t--; 
        }
    }
    return 0;
}

by tabelog_AFO @ 2023-02-10 21:20:58

#include <bits/stdc++.h>
using namespace std;
int main() {
    int a,n,t=0,i=0,b,s=0;
    cin>>n;
    while (s<n*n) {
        cin>>a;
        i++;
        for (b=a;b>=1;b--) {
            if (t==n) {
                cout<<endl;
                t=0;
            }
            if (i%2==1) cout<<0;
            else cout<<1;
            t++,s++;
            }
        }
    cout<<endl;
    return 0;
}

|