結果
| 問題 | No.5002 stick xor | 
| コンテスト | |
| ユーザー |  ikd | 
| 提出日時 | 2018-05-28 21:34:29 | 
| 言語 | D (dmd 2.109.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 3 ms / 1,000 ms | 
| コード長 | 2,036 bytes | 
| コンパイル時間 | 2,749 ms | 
| 実行使用メモリ | 1,420 KB | 
| スコア | 15,203 | 
| 最終ジャッジ日時 | 2023-06-01 00:00:00 | 
| ジャッジサーバーID (参考情報) | judge6 / | 
| 純コード判定しない問題か言語 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 32 | 
ソースコード
class Problem{
  import std.stdio, std.string, std.conv, std.algorithm;  
  import std.math, std.array;
  const int L_MAX=25;
  const int n=60, k=500;
  int[] li;
  int[][] a;
  this(int[] li, int[][] a){
    this.li=li.dup;
    this.a=a.dup;
  }
  auto idx=new int[][](30);
  void init(){
    foreach(int i, l; li){
      idx[l]~=i;
    }
  }
  int take(int l){
    int ret=-1;
    for(int i=l; i<=L_MAX; i++){
      if(idx[i].length>0){
        ret=idx[i].back;
        idx[i].popBack;
        break;
      }
    }
    return ret;
  }
  
  struct Rect{
    int a, b, c, d;
  }
  auto ans=new Rect[](k);
  void solve(){
    foreach(i; 0..n){
      int len=1;
      foreach(j; 0..(L_MAX))if(a[i][j]==1){
        int m=take(len);
        if(m<0) goto hell;
        ans[m]=Rect(i, j, i, j+li[m]-1);
        foreach(l; j..(j+li[m])) a[i][l]^=1;
        len++;
      }
    }
    hell:;
  }
  void output(){
    int un_used=0;
    foreach(int i, l; li){
      auto r=ans[i];
      if(r.d-r.b>0){
        writeln(r.a+1, " ", r.b+1, " ", r.c+1, " ", r.d+1);
      }else{
        un_used++;
        writeln(n-1, " ", 1, " ", n-1, " ", l);
      }
    }
    // writeln(un_used);
  }
  void count(){
    int[int] cnt;
    foreach(i; 0..25){
      int c=0;
      foreach(j; 0..25){
        if(a[i][j]==1) c++;
        else{
          if(c in cnt) cnt[c]++;
          else cnt[c]=1;
          c=0;
        } 
      }
    }
    foreach(key; cnt.keys.sort){
      writeln(key, " ", cnt[key]);
    }
  }
  void show(){
  }
}
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  int n, k; rd(n, k);
  auto li=readln.split.to!(int[]);
  auto a=new int[][](n, n);
  foreach(i; 0..n){
    auto line=readln.chomp.to!(char[]);
    foreach(j; 0..n) a[i][j]=line[j]-'0';
  }
  auto problem=new Problem(li, a);
  problem.init;
  problem.solve;
  problem.output;
}
void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}
            
            
            
        