評分結果(參考) : AC (40ms, 1.3MB)
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<vector<char>> v(n, vector<char>(n, '0'));
for(int i=0; i<n; i++){
for(int j=i; j<n; j++){
if(m <= 0) break;
if(i == j){
v[i][j] = '1';
m--;
}
else{
if(m >= 2)
{
v[i][j] = '1';
v[j][i] = '1';
m -= 2;
}
}
}
}
for(auto& a : v){
for(char c : a){
cout << c << " ";
}
cout << "\n";
}
return 0;
}